-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EC2_instance: add support for controlling metadata options (#414)
EC2_instance: add support for controlling metadata options SUMMARY Adding support for controlling the metadata options, 'Metadata Accessible' and 'Metadata Version' in amazon.aws.ec2_instance. Fixes #399 ISSUE TYPE Feature Pull Request COMPONENT NAME amazon.aws.ec2_instance Reviewed-by: Jill R <None> Reviewed-by: Abhijeet Kasurde <None> Reviewed-by: Mark Chappell <None> Reviewed-by: None <None>
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/414-ec2_instance-support-controlling-metadata-options.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- ec2_instance - add support for controlling metadata options (https://github.com/ansible-collections/amazon.aws/pull/414). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/metadata_options.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
- block: | ||
- name: "create t3.nano instance with metadata_options" | ||
ec2_instance: | ||
state: present | ||
name: "{{ resource_prefix }}-test-t3nano-enabled-required" | ||
image_id: "{{ ec2_ami_image }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}" | ||
instance_type: t3.nano | ||
metadata_options: | ||
http_endpoint: enabled | ||
http_tokens: required | ||
wait: false | ||
register: instance_creation | ||
|
||
- name: "instance with metadata_options created with the right options" | ||
assert: | ||
that: | ||
- instance_creation is success | ||
- instance_creation is changed | ||
- "'{{ instance_creation.spec.MetadataOptions.HttpEndpoint }}' == 'enabled'" | ||
- "'{{ instance_creation.spec.MetadataOptions.HttpTokens }}' == 'required'" | ||
|
||
- name: "modify metadata_options on existing instance" | ||
ec2_instance: | ||
state: present | ||
name: "{{ resource_prefix }}-test-t3nano-enabled-required" | ||
image_id: "{{ ec2_ami_image }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}" | ||
instance_type: t3.nano | ||
metadata_options: | ||
http_endpoint: enabled | ||
http_tokens: optional | ||
wait: false | ||
register: metadata_options_update | ||
ignore_errors: yes | ||
|
||
- name: "fact presented ec2 instance" | ||
ec2_instance_info: | ||
filters: | ||
"tag:Name": "{{ resource_prefix }}-test-t3nano-enabled-required" | ||
register: presented_instance_fact | ||
|
||
- name: "modify metadata_options has no effect on existing instance" | ||
assert: | ||
that: | ||
- metadata_options_update is success | ||
- metadata_options_update is not changed | ||
- "{{ presented_instance_fact.instances | length }} > 0" | ||
- "'{{ presented_instance_fact.instances.0.state.name }}' in ['running','pending']" | ||
- "'{{ presented_instance_fact.instances.0.metadata_options.http_endpoint }}' == 'enabled'" | ||
- "'{{ presented_instance_fact.instances.0.metadata_options.http_tokens }}' == 'required'" | ||
|
||
always: | ||
- name: "Terminate metadata_options instances" | ||
ec2_instance: | ||
state: absent | ||
filters: | ||
"tag:TestId": "{{ ec2_instance_tag_TestId }}" | ||
wait: yes | ||
ignore_errors: yes |