Skip to content

Commit

Permalink
add metadata options to ec2 template (#322)
Browse files Browse the repository at this point in the history
* add metadata options to ec2 template
  • Loading branch information
danquack authored and tremble committed Mar 14, 2021
1 parent bed7be8 commit 568f746
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_launch_template - added ``metadata_options`` parameter to support changing the IMDS configuration for instances (https://github.com/ansible-collections/community.aws/pull/322).
34 changes: 34 additions & 0 deletions plugins/modules/ec2_launch_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,32 @@
U(http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html#instancedata-add-user-data)
documentation on user-data.
type: str
metadata_options:
description:
- Configure EC2 Metadata options.
- For more information see the IMDS documentation
U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html).
type: dict
version_added: 1.5.0
suboptions:
http_endpoint:
type: str
description: >
This parameter enables or disables the HTTP metadata endpoint on your instances.
choices: [enabled, disabled]
default: 'enabled'
http_put_response_hop_limit:
type: int
description: >
The desired HTTP PUT response hop limit for instance metadata requests.
The larger the number, the further instance metadata requests can travel.
default: 1
http_tokens:
type: str
description: >
The state of token usage for your instance metadata requests.
choices: [optional, required]
default: 'optional'
'''

EXAMPLES = '''
Expand Down Expand Up @@ -636,6 +662,14 @@ def main():
enabled=dict(type='bool')
),
),
metadata_options=dict(
type='dict',
options=dict(
http_endpoint=dict(choices=['enabled', 'disabled'], default='enabled'),
http_put_response_hop_limit=dict(type='int', default=1),
http_tokens=dict(choices=['optional', 'required'], default='optional')
)
),
network_interfaces=dict(
type='list',
elements='dict',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- block:
- name: metadata_options
ec2_launch_template:
name: "{{ resource_prefix }}-test-metadata"
metadata_options:
http_put_response_hop_limit: 1
http_tokens: required
state: present
register: metadata_options_launch_template
- name: instance with metadata_options created with the right options
assert:
that:
- metadata_options_launch_template is changed
- "metadata_options_launch_template.latest_template.launch_template_data.metadata_options.http_put_response_hop_limit == 1"
- "metadata_options_launch_template.latest_template.launch_template_data.metadata_options.http_tokens == 'required'"
always:
- name: delete the template
ec2_launch_template:
name: "{{ resource_prefix }}-test-metadata"
state: absent
register: del_lt
retries: 10
until: del_lt is not failed
ignore_errors: true
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- include_tasks: cpu_options.yml
- include_tasks: iam_instance_role.yml
- include_tasks: versions.yml
- include_tasks: instance-metadata.yml

always:

Expand Down

0 comments on commit 568f746

Please sign in to comment.