Skip to content

Commit

Permalink
ec2_instance - fetch status of instance before attempting to set addi…
Browse files Browse the repository at this point in the history
…tional parameters (ansible-collections#533)
  • Loading branch information
tremble authored and danielcotton committed Nov 23, 2021
1 parent a62ac29 commit eb5b2eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/532-ec2_instance-wait-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_instance - wait for new instances to return a status before attempting to set additional parameters (https://github.com/ansible-collections/community.aws/pull/533).
12 changes: 12 additions & 0 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,18 @@ def ensure_present(existing_matches, changed, ec2, state):
instance_ids = [i['InstanceId'] for i in instances]

for ins in instances:
# Wait for instances to exist (don't check state)
try:
AWSRetry.jittered_backoff(
catch_extra_error_codes=['InvalidInstanceID.NotFound'],
)(
ec2.describe_instance_status
)(
InstanceIds=[ins['InstanceId']],
IncludeAllInstances=True,
)
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
module.fail_json_aws(e, msg="Failed to fetch status of new EC2 instance")
changes = diff_instance_and_params(ins, module.params, ec2, skip=['UserData', 'EbsOptimized'])
for c in changes:
try:
Expand Down

0 comments on commit eb5b2eb

Please sign in to comment.