Skip to content

Commit

Permalink
modified based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mandar242 committed Sep 11, 2024
1 parent c98e8e1 commit 152f90e
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions plugins/modules/ec2_eip.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,10 @@
description: Whether to update the reverse DNS record of ec2 Elastic IP Address (eip)
required: false
type: bool
allocation_id:
description: The allocation ID of ec2 EIP.
required: false
type: str
domain_name:
description: The domain name to modify for the IP address.
required: false
type: str
dry_run:
description:
- Checks whether you have the required permissions for the action, without actually making the request, and provides an error response.
- If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.
required: false
type: bool
extends_documentation_fragment:
- amazon.aws.common.modules
- amazon.aws.region.modules
Expand Down Expand Up @@ -223,7 +213,7 @@
- name: Modify reverse DNS record of EIP
amazon.aws.ec2_eip:
update_reverse_dns_record: true
allocation_id: eipalloc-00a61ec1234567890
public_ip: 11.22.33.44
domain_name: example.com
"""

Expand Down Expand Up @@ -531,15 +521,12 @@ def ensure_present(
return result


def update_reverse_dns_record_of_eip(client, module: AnsibleAWSModule):
def update_reverse_dns_record_of_eip(client, module: AnsibleAWSModule, allocation_id, domain_name):
changed = False
allocation_id = module.params.get("allocation_id")
domain_name = module.params.get("domain_name")
dry_run = module.params.get("dry_run")

try:
update_reverse_dns_record_result = client.modify_address_attribute(
AllocationId=allocation_id, DomainName=domain_name, DryRun=dry_run
AllocationId=allocation_id, DomainName=domain_name
)
changed = True
except AnsibleEC2Error as e:
Expand All @@ -556,10 +543,8 @@ def update_reverse_dns_record_of_eip(client, module: AnsibleAWSModule):

def main():
argument_spec = dict(
allocation_id=dict(required=False, type="str"),
device_id=dict(required=False),
domain_name=dict(required=False, type="str"),
dry_run=dict(required=False, type="bool"),
public_ip=dict(required=False, aliases=["ip"]),
state=dict(required=False, default="present", choices=["present", "absent"]),
in_vpc=dict(required=False, type="bool", default=False),
Expand All @@ -583,7 +568,7 @@ def main():
"tag_value": ["tag_name"],
},
required_if=[
("update_reverse_dns_record", True, ("allocation_id", "domain_name")),
("update_reverse_dns_record", True, ("public_ip", "domain_name")),
],
)

Expand All @@ -596,7 +581,9 @@ def main():
is_instance = check_is_instance(module)

if module.params.get("update_reverse_dns_record") is True:
result = update_reverse_dns_record_of_eip(ec2, module)
allocation_id = ec2.describe_addresses(PublicIps=[public_ip])["Addresses"][0]["AllocationId"]
domain_name = module.params.get("domain_name")
result = update_reverse_dns_record_of_eip(ec2, module, allocation_id, domain_name)
else:
try:
# Find existing address
Expand Down

0 comments on commit 152f90e

Please sign in to comment.