diff --git a/test_data/az_data.yml b/test_data/az_data.yml index ca92467..39f7c12 100644 --- a/test_data/az_data.yml +++ b/test_data/az_data.yml @@ -907,3 +907,19 @@ vms: vm_id: eb3229e8-26a9-4a46-94ac-f8261b11bc6b extensions_time_budget: PT1H30M time_created: '2023-09-08T05:48:05.560671Z' +nat_gateways: + - id: /subscriptions/26b9eb0b-2d3b-49e8-b07f-ce08716a1fc6/resourceGroups/ManagedByParacloud/providers/Microsoft.Network/natGateways/natgw2 + name: natgw2 + type: Microsoft.Network/natGateways + location: eastus + tags: {} + sku: + name: Standard + etag: W/"062b3468-b080-4ec5-b7f0-b519f5bda734" + idle_timeout_in_minutes: 4 + public_ip_addresses: + - id: /subscriptions/26b9eb0b-2d3b-49e8-b07f-ce08716a1fc6/resourceGroups/ManagedByParacloud/providers/Microsoft.Network/publicIPAddresses/priv-publicIpAddress + subnets: + - id: /subscriptions/26b9eb0b-2d3b-49e8-b07f-ce08716a1fc6/resourceGroups/ManagedByParacloud/providers/Microsoft.Network/virtualNetworks/main/subnets/priv + resource_guid: 90953e6b-5cea-4af0-82f2-15611e2a617d + provisioning_state: Succeeded diff --git a/transible/plugins/az_ansible/azure_ansible.py b/transible/plugins/az_ansible/azure_ansible.py index 9474e84..a36826f 100644 --- a/transible/plugins/az_ansible/azure_ansible.py +++ b/transible/plugins/az_ansible/azure_ansible.py @@ -12,7 +12,6 @@ from transible.utils import read_yaml, optimize - class AzureAnsible: """Main class to generate Ansible playbooks from Amazon @@ -79,6 +78,7 @@ def retrieve_cloud_data(self, data_type): const.FILE_LBS: ('networks', self.az_calc.create_load_balancers), const.FILE_SERVERS: ('compute', self.az_calc.create_servers), const.FILE_AVAIL_SETS: ('compute', self.az_calc.create_availability_sets), + const.FILE_NAT_GWS: ('networks', self.az_calc.create_nat_gateways), } for file_name, (path, func) in cloud_funcs.items(): @@ -358,6 +358,31 @@ def create_network_interfaces(self, force_optimize=conf.VARS_OPT_NETINTS, netints.append(optimized) return netints + def create_nat_gateways(self, force_optimize=conf.VARS_OPT_NAT_GWS, + vars_file=True): + ngws = [] + pre_optimized = [] + for ng in self.data['nat_gateways']: + n = {'state': '{{ state }}'} + n['resource_group'] = self.resource_group_name + n['name'] = ng['name'] + n['public_ip_addresses'] = [i['id'].split("/publicIPAddresses/")[1] for i in ng['public_ip_addresses']] + n['idle_timeout_in_minutes'] = ng['idle_timeout_in_minutes'] + n['sku'] = ng['sku']['name'] + ngw = {'azure.azcollection.azure_rm_natgateway': n} + if force_optimize: + pre_optimized.append(ngw) + else: + ngws.append(ngw) + if force_optimize: + optimized = optimize( + pre_optimized, + use_vars=vars_file, + var_name="nat_gateways") + if optimized: + ngws.append(optimized) + return ngws + def create_app_secgroups(self, force_optimize=conf.VARS_OPT_APPSECGROUPS, vars_file=True): appscgps = [] @@ -642,6 +667,8 @@ def get_info(self): self.resource_group_name), const.FILE_LBS), "subnets": (conf.DUMP_NETWORKS, self.network_client.virtual_networks.list( self.resource_group_name), const.FILE_SUBNETS), + "nat_gateways": (conf.DUMP_NETWORKS, self.network_client.nat_gateways.list( + self.resource_group_name), const.FILE_NAT_GWS), "availability_sets": (conf.DUMP_SERVERS, self.compute_client.availability_sets.list( self.resource_group_name), const.FILE_KEYPAIRS), "vms": (conf.DUMP_SERVERS, self.compute_client.virtual_machines.list( diff --git a/transible/plugins/az_ansible/config.py b/transible/plugins/az_ansible/config.py index 3c657bc..16e6048 100644 --- a/transible/plugins/az_ansible/config.py +++ b/transible/plugins/az_ansible/config.py @@ -34,3 +34,4 @@ VARS_OPT_NETINTS = False VARS_OPT_RESOURCEGRPS = True VARS_OPT_AVAILSETS = False +VARS_OPT_NAT_GWS = False diff --git a/transible/plugins/az_ansible/const.py b/transible/plugins/az_ansible/const.py index e76618a..35750cc 100644 --- a/transible/plugins/az_ansible/const.py +++ b/transible/plugins/az_ansible/const.py @@ -28,6 +28,7 @@ - import_tasks: networks/subnets.yml - import_tasks: networks/security_groups.yml - import_tasks: networks/eips.yml + - import_tasks: networks/nat_gateways.yml - import_tasks: networks/load_balancers.yml - import_tasks: networks/application_security_groups.yml - import_tasks: networks/network_interfaces.yml @@ -59,6 +60,7 @@ - import_tasks: networks/network_interfaces.yml - import_tasks: networks/security_groups.yml - import_tasks: networks/application_security_groups.yml + - import_tasks: networks/nat_gateways.yml - import_tasks: networks/load_balancers.yml - import_tasks: networks/eips.yml - import_tasks: networks/subnets.yml