# Buggy code
def get_or_create_public_ip_address(self, ip_config):
    name = ip_config.get("public_ip_address_name")
    pip = self.get_public_ip_address(name)
    if not pip:
        params = self.network_models.PublicIPAddress(
            location=self.location,
            public_ip_allocation_method=ip_config.get("public_ip_allocation_method"),
        )
        try:
            poller = self.network_client.public_ip_addresses.create_or_update(
                self.resource_group, name, params
            )
            pip = self.get_poller_result(poller)
        except CloudError as exc:
            self.fail("Error creating {0} - {1}".format(name, str(exc)))
    return pip


# Traceback (msrest.exceptions.ValidationError)
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py", line 595, in <module>
main()
File "/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py", line 591, in main
AzureRMNetworkInterface()
File "/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py", line 408, in __init__
required_if=required_if)
File "/tmp/ansible_TpE0Hc/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 332, in __init__
File "/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py", line 516, in exec_module
) for ip_config in self.ip_configurations
File "/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py", line 546, in get_or_create_public_ip_address
poller = self.network_client.public_ip_addresses.create_or_update(self.resource_group, name, params)
File "/home/paolomargara/ansible/local/lib/python2.7/site-packages/azure/mgmt/network/v2017_06_01/operations/public_ip_addresses_operations.py", line 212, in create_or_update
'publicIpAddressName': self._serialize.url("public_ip_address_name", public_ip_address_name, 'str'),
File "/home/paolomargara/ansible/local/lib/python2.7/site-packages/msrest/serialization.py", line 488, in url
data = self.validate(data, name, required=True, **kwargs)
File "/home/paolomargara/ansible/local/lib/python2.7/site-packages/msrest/serialization.py", line 558, in validate
raise ValidationError("required", name, True)
msrest.exceptions.ValidationError: Parameter 'public_ip_address_name' can not be None.

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py\", line 595, in <module>\n    main()\n  File \"/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py\", line 591, in main\n    AzureRMNetworkInterface()\n  File \"/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py\", line 408, in __init__\n    required_if=required_if)\n  File \"/tmp/ansible_TpE0Hc/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 332, in __init__\n  File \"/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py\", line 516, in exec_module\n    ) for ip_config in self.ip_configurations\n  File \"/tmp/ansible_TpE0Hc/ansible_module_azure_rm_networkinterface.py\", line 546, in get_or_create_public_ip_address\n    poller = self.network_client.public_ip_addresses.create_or_update(self.resource_group, name, params)\n  File \"/home/paolomargara/ansible/local/lib/python2.7/site-packages/azure/mgmt/network/v2017_06_01/operations/public_ip_addresses_operations.py\", line 212, in create_or_update\n    'publicIpAddressName': self._serialize.url(\"public_ip_address_name\", public_ip_address_name, 'str'),\n  File \"/home/paolomargara/ansible/local/lib/python2.7/site-packages/msrest/serialization.py\", line 488, in url\n    data = self.validate(data, name, required=True, **kwargs)\n  File \"/home/paolomargara/ansible/local/lib/python2.7/site-packages/msrest/serialization.py\", line 558, in validate\n    raise ValidationError(\"required\", name, True)\nmsrest.exceptions.ValidationError: Parameter 'public_ip_address_name' can not be None.\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}

# Fixed code
def get_or_create_public_ip_address(self, ip_config):
    name = ip_config.get("public_ip_address_name")

    if not (self.public_ip and name):
        return None

    pip = self.get_public_ip_address(name)
    if not pip:
        params = self.network_models.PublicIPAddress(
            location=self.location,
            public_ip_allocation_method=ip_config.get("public_ip_allocation_method"),
        )
        try:
            poller = self.network_client.public_ip_addresses.create_or_update(
                self.resource_group, name, params
            )
            pip = self.get_poller_result(poller)
        except CloudError as exc:
            self.fail("Error creating {0} - {1}".format(name, str(exc)))
    return pip