Add test for creating launch templates with TagSpecifications option
This commit is contained in:
parent
743e5be4d3
commit
a1aa087718
@ -94,17 +94,25 @@ class LaunchTemplates(BaseResponse):
|
||||
def create_launch_template(self):
|
||||
name = self._get_param('LaunchTemplateName')
|
||||
version_description = self._get_param('VersionDescription')
|
||||
tag_spec = self._get_param('TagSpecifications')
|
||||
tag_spec = self._parse_tag_specification("TagSpecification")
|
||||
|
||||
raw_template_data = self._get_dict_param('LaunchTemplateData.')
|
||||
parsed_template_data = parse_object(raw_template_data)
|
||||
|
||||
|
||||
if self.is_not_dryrun('CreateLaunchTemplate'):
|
||||
if tag_spec:
|
||||
if 'TagSpecifications' not in parsed_template_data:
|
||||
parsed_template_data['TagSpecifications'] = []
|
||||
parsed_template_data['TagSpecifications'].extend(tag_spec)
|
||||
converted_tag_spec = []
|
||||
for resource_type, tags in six.iteritems(tag_spec):
|
||||
converted_tag_spec.append({
|
||||
"ResourceType": resource_type,
|
||||
"Tags": [{"Key": key, "Value": value} for key, value in six.iteritems(tags)],
|
||||
})
|
||||
|
||||
parsed_template_data['TagSpecifications'].extend(converted_tag_spec)
|
||||
|
||||
if self.is_not_dryrun('CreateLaunchTemplate'):
|
||||
template = self.ec2_backend.create_launch_template(name, version_description, parsed_template_data)
|
||||
version = template.default_version()
|
||||
|
||||
|
@ -356,3 +356,32 @@ def test_describe_launch_templates_with_filters():
|
||||
resp["LaunchTemplates"].should.have.length_of(1)
|
||||
resp["LaunchTemplates"][0]["LaunchTemplateName"].should.equal("no-tags")
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_create_launch_template_with_tag_spec():
|
||||
cli = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
cli.create_launch_template(
|
||||
LaunchTemplateName="test-template",
|
||||
LaunchTemplateData={"ImageId":"ami-abc123"},
|
||||
TagSpecifications=[{
|
||||
"ResourceType": "instance",
|
||||
"Tags": [
|
||||
{"Key": "key", "Value": "value"}
|
||||
]
|
||||
}],
|
||||
)
|
||||
|
||||
resp = cli.describe_launch_template_versions(
|
||||
LaunchTemplateName="test-template",
|
||||
Versions=["1"])
|
||||
version = resp["LaunchTemplateVersions"][0]
|
||||
|
||||
version["LaunchTemplateData"].should.have.key("TagSpecifications")
|
||||
version["LaunchTemplateData"]["TagSpecifications"].should.have.length_of(1)
|
||||
version["LaunchTemplateData"]["TagSpecifications"][0].should.equal({
|
||||
"ResourceType": "instance",
|
||||
"Tags": [
|
||||
{"Key": "key", "Value": "value"}
|
||||
]
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user