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 (#533)
  • Loading branch information
tremble authored Apr 9, 2021
1 parent 8fbfead commit 1b6dcca
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 1b6dcca

Please sign in to comment.