340
340
- A set of key-value pairs to be applied to resources when this Launch Template is used.
341
341
- "Tag key constraints: Tag keys are case-sensitive and accept a maximum of 127 Unicode characters. May not begin with I(aws:)"
342
342
- "Tag value constraints: Tag values are case-sensitive and accept a maximum of 255 Unicode characters."
343
+ - This field is deprecated and will be removed in a release after 2026-12-01, use O(tag_specifications) instead.
343
344
aliases: ['resource_tags']
345
+ tag_specifications:
346
+ description:
347
+ - The tags to apply to the resources when this Launch template is used.
348
+ type: list
349
+ elements: dict
350
+ version_added: 8.1.0
351
+ suboptions:
352
+ resource_type:
353
+ description:
354
+ - The type of resource to tag.
355
+ - If the instance does not include the resource type that you specify, the instance launch fails.
356
+ type: str
357
+ default: instance
358
+ choices:
359
+ - instance
360
+ - volume
361
+ - network-interface
362
+ - spot-instances-request
363
+ tags:
364
+ description:
365
+ - A set of key-value pairs to be applied to the resource type.
366
+ - "Tag key constraints: Tag keys are case-sensitive and accept a maximum of 127 Unicode characters. May not begin with I(aws:)"
367
+ - "Tag value constraints: Tag values are case-sensitive and accept a maximum of 255 Unicode characters."
368
+ type: dict
344
369
user_data:
345
370
description: >
346
371
The Base64-encoded user data to make available to the instance. For more information, see the Linux
394
419
- If the O(template_tags) parameter is not set then tags will not be modified.
395
420
type: dict
396
421
required: false
422
+ version_added: 8.1.0
397
423
purge_template_tags:
398
424
description:
399
425
- If O(purge_template_tags=true) and O(template_tags) is set, existing tags will be purged
407
433
type: bool
408
434
default: true
409
435
required: false
436
+ version_added: 8.1.0
410
437
extends_documentation_fragment:
411
438
- amazon.aws.common.modules
412
439
- amazon.aws.region.modules
450
477
- 1
451
478
default_version: 2
452
479
state: absent
480
+
481
+ - name: Create an ec2 launch template with specific tags
482
+ community.aws.ec2_launch_template:
483
+ name: "my_template"
484
+ image_id: "ami-04b762b4289fba92b"
485
+ instance_type: t2.micro
486
+ disable_api_termination: true
487
+ template_tags:
488
+ Some: tag
489
+ Another: tag
490
+
491
+ - name: Create an ec2 launch template with different tag for volume and instance
492
+ community.aws.ec2_launch_template:
493
+ name: "my_template"
494
+ image_id: "ami-04b762b4289fba92b"
495
+ instance_type: t2.micro
496
+ block_device_mappings:
497
+ - device_name: /dev/sdb
498
+ ebs:
499
+ volume_size: 20
500
+ delete_on_termination: true
501
+ volume_type: standard
502
+ tag_specifications:
503
+ - resource_type: instance
504
+ tags:
505
+ OsType: Linux
506
+ - resource_type: volume
507
+ tags:
508
+ foo: bar
453
509
"""
454
510
455
511
RETURN = r"""
@@ -759,9 +815,16 @@ def find_existing(client, module: AnsibleAWSModule) -> Tuple[Optional[Dict[str,
759
815
def params_to_launch_data (
760
816
template_params : Dict [str , Any ], iam_instance_profile_arn : Optional [str ] = None
761
817
) -> Dict [str , Any ]:
818
+ if template_params .get ("tag_specifications" ):
819
+ template_params ["tag_specifications" ] = [
820
+ {"resource_type" : ts ["resource_type" ], "tags" : ansible_dict_to_boto3_tag_list (ts ["tags" ])}
821
+ for ts in template_params ["tag_specifications" ]
822
+ ]
762
823
if template_params .get ("tags" ):
824
+ if "tag_specifications" not in template_params :
825
+ template_params ["tag_specifications" ] = []
763
826
tag_list = ansible_dict_to_boto3_tag_list (template_params .get ("tags" ))
764
- template_params ["tag_specifications" ] = [
827
+ template_params ["tag_specifications" ] + = [
765
828
{"resource_type" : r_type , "tags" : tag_list } for r_type in ("instance" , "volume" , "network-interface" )
766
829
]
767
830
del template_params ["tags" ]
@@ -1162,6 +1225,18 @@ def main():
1162
1225
security_groups = dict (type = "list" , elements = "str" ),
1163
1226
tags = dict (type = "dict" , aliases = ["resource_tags" ]),
1164
1227
user_data = dict (),
1228
+ tag_specifications = dict (
1229
+ type = "list" ,
1230
+ elements = "dict" ,
1231
+ options = dict (
1232
+ resource_type = dict (
1233
+ type = "str" ,
1234
+ default = "instance" ,
1235
+ choices = ["instance" , "volume" , "network-interface" , "spot-instances-request" ],
1236
+ ),
1237
+ tags = dict (type = "dict" ),
1238
+ ),
1239
+ ),
1165
1240
)
1166
1241
1167
1242
argument_spec = dict (
@@ -1187,6 +1262,13 @@ def main():
1187
1262
supports_check_mode = True ,
1188
1263
)
1189
1264
1265
+ if module .params .get ("tags" ):
1266
+ module .deprecate (
1267
+ "The tags parameter has been deprecated, please use tag_specifications instead." ,
1268
+ date = "2026-12-01" ,
1269
+ collection_name = "community.aws" ,
1270
+ )
1271
+
1190
1272
state = module .params .get ("state" )
1191
1273
client = module .client ("ec2" )
1192
1274
launch_template , launch_template_versions = find_existing (client , module )
0 commit comments