fix(cloudformation): missing Parameters key in get_template_summary() response (#4466)
This commit is contained in:
parent
ce91a8d615
commit
12bd6af540
@ -1186,14 +1186,38 @@ LIST_STACK_SET_OPERATION_RESULTS_RESPONSE_TEMPLATE = (
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_GetTemplateSummary.html
|
||||||
|
# TODO:implement fields: ResourceIdentifierSummaries, Capabilities, CapabilitiesReason
|
||||||
GET_TEMPLATE_SUMMARY_TEMPLATE = """<GetTemplateSummaryResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">
|
GET_TEMPLATE_SUMMARY_TEMPLATE = """<GetTemplateSummaryResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">
|
||||||
<GetTemplateSummaryResult>
|
<GetTemplateSummaryResult>
|
||||||
<Description>{{ template_summary.Description }}</Description>
|
<Description>{{ template_summary.Description }}</Description>
|
||||||
{% for resource in template_summary.resourceTypes %}
|
{% for resource in template_summary.resourceTypes %}
|
||||||
<ResourceTypes>
|
<ResourceTypes>
|
||||||
<ResourceType>{{ resource }}</ResourceType>
|
<member>{{ resource }}</member>
|
||||||
</ResourceTypes>
|
</ResourceTypes>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<Parameters>
|
||||||
|
{% for k,p in template_summary.get('Parameters',{}).items() %}
|
||||||
|
<member>
|
||||||
|
<ParameterKey>{{ k }}</ParameterKey> ,
|
||||||
|
<Description>{{ p.get('Description', '') }}</Description>,
|
||||||
|
{% if p.Default %}
|
||||||
|
<DefaultValue>{{ p.Default }}</DefaultValue>
|
||||||
|
{% endif %}
|
||||||
|
<NoEcho>{{ p.get('NoEcho', False) }}</NoEcho>
|
||||||
|
<ParameterType>{{ p.get('Type', 'String') }}</ParameterType>
|
||||||
|
<ParameterConstraints>
|
||||||
|
{% if p.AllowedValues %}
|
||||||
|
<AllowedValues>
|
||||||
|
{% for v in p.AllowedValues %}
|
||||||
|
<member>{{ v }}</member>
|
||||||
|
{% endfor %}
|
||||||
|
</AllowedValues>
|
||||||
|
{% endif %}
|
||||||
|
</ParameterConstraints>
|
||||||
|
</member>
|
||||||
|
{% endfor %}
|
||||||
|
</Parameters>
|
||||||
<Version>{{ template_summary.AWSTemplateFormatVersion }}</Version>
|
<Version>{{ template_summary.AWSTemplateFormatVersion }}</Version>
|
||||||
</GetTemplateSummaryResult>
|
</GetTemplateSummaryResult>
|
||||||
<ResponseMetadata>
|
<ResponseMetadata>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import boto
|
import boto
|
||||||
from unittest import SkipTest
|
from unittest import SkipTest
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable, Mapping
|
||||||
from sure import assertion
|
from sure import assertion
|
||||||
|
|
||||||
|
|
||||||
@ -45,3 +45,16 @@ def containing_item_with_attributes(context, **kwargs):
|
|||||||
else:
|
else:
|
||||||
assert contains, f"{context.obj} does not contain matching item {kwargs}"
|
assert contains, f"{context.obj} does not contain matching item {kwargs}"
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@assertion
|
||||||
|
def match_dict(context, dict_value):
|
||||||
|
assert isinstance(dict_value, Mapping), f"Invalid match target value: {dict_value}"
|
||||||
|
assert isinstance(
|
||||||
|
context.obj, Mapping
|
||||||
|
), f"Expected dict like object, but got: {context.obj}"
|
||||||
|
|
||||||
|
for k, v in dict_value.items():
|
||||||
|
assert k in context.obj, f"No such key '{k}' in {context.obj}"
|
||||||
|
context.obj[k].should.equal(v)
|
||||||
|
return True
|
||||||
|
@ -55,6 +55,28 @@ dummy_template3 = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dummy_template_with_parameters = {
|
||||||
|
"AWSTemplateFormatVersion": "2010-09-09",
|
||||||
|
"Description": "A simple CloudFormation template",
|
||||||
|
"Resources": {
|
||||||
|
"Bucket": {
|
||||||
|
"Type": "AWS::S3::Bucket",
|
||||||
|
"Properties": {"BucketName": {"Ref": "Name"}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Parameters": {
|
||||||
|
"Name": {"Type": "String", "Default": "SomeValue"},
|
||||||
|
"Another": {
|
||||||
|
"Type": "String",
|
||||||
|
"Default": "A",
|
||||||
|
"AllowedValues": ["A", "B"],
|
||||||
|
"Description": "Chose A or B",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
dummy_template_yaml = """---
|
dummy_template_yaml = """---
|
||||||
AWSTemplateFormatVersion: 2010-09-09
|
AWSTemplateFormatVersion: 2010-09-09
|
||||||
Description: Stack1 with yaml template
|
Description: Stack1 with yaml template
|
||||||
@ -70,6 +92,7 @@ Resources:
|
|||||||
Value: Test tag
|
Value: Test tag
|
||||||
- Key: Name
|
- Key: Name
|
||||||
Value: Name tag for tests
|
Value: Name tag for tests
|
||||||
|
Parameters:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
dummy_template_yaml_with_short_form_func = """---
|
dummy_template_yaml_with_short_form_func = """---
|
||||||
@ -867,6 +890,7 @@ def test_get_template_summary():
|
|||||||
result["ResourceTypes"].should.equal(["AWS::EC2::VPC"])
|
result["ResourceTypes"].should.equal(["AWS::EC2::VPC"])
|
||||||
result["Version"].should.equal("2010-09-09")
|
result["Version"].should.equal("2010-09-09")
|
||||||
result["Description"].should.equal("Stack 3")
|
result["Description"].should.equal("Stack 3")
|
||||||
|
result["Parameters"].should.equal([])
|
||||||
|
|
||||||
# existing stack
|
# existing stack
|
||||||
conn.create_stack(StackName="test_stack", TemplateBody=json.dumps(dummy_template3))
|
conn.create_stack(StackName="test_stack", TemplateBody=json.dumps(dummy_template3))
|
||||||
@ -874,6 +898,7 @@ def test_get_template_summary():
|
|||||||
result["ResourceTypes"].should.equal(["AWS::EC2::VPC"])
|
result["ResourceTypes"].should.equal(["AWS::EC2::VPC"])
|
||||||
result["Version"].should.equal("2010-09-09")
|
result["Version"].should.equal("2010-09-09")
|
||||||
result["Description"].should.equal("Stack 3")
|
result["Description"].should.equal("Stack 3")
|
||||||
|
result["Parameters"].should.equal([])
|
||||||
|
|
||||||
# json template from s3
|
# json template from s3
|
||||||
s3_conn.create_bucket(Bucket="foobar")
|
s3_conn.create_bucket(Bucket="foobar")
|
||||||
@ -896,7 +921,7 @@ def test_get_template_summary():
|
|||||||
|
|
||||||
|
|
||||||
@mock_cloudformation
|
@mock_cloudformation
|
||||||
def test_get_template_summary_for_stack_createed_by_changeset_execution():
|
def test_get_template_summary_for_stack_created_by_changeset_execution():
|
||||||
conn = boto3.client("cloudformation", region_name="us-east-1")
|
conn = boto3.client("cloudformation", region_name="us-east-1")
|
||||||
conn.create_change_set(
|
conn.create_change_set(
|
||||||
StackName="stack_from_changeset",
|
StackName="stack_from_changeset",
|
||||||
@ -916,6 +941,49 @@ def test_get_template_summary_for_stack_createed_by_changeset_execution():
|
|||||||
result["Description"].should.equal("Stack 3")
|
result["Description"].should.equal("Stack 3")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_s3
|
||||||
|
@mock_cloudformation
|
||||||
|
def test_get_template_summary_for_template_containing_parameters():
|
||||||
|
conn = boto3.client("cloudformation", region_name="us-east-1")
|
||||||
|
conn.create_stack(
|
||||||
|
StackName="test_stack", TemplateBody=json.dumps(dummy_template_with_parameters)
|
||||||
|
)
|
||||||
|
result = conn.get_template_summary(StackName="test_stack")
|
||||||
|
result.should.match_dict(
|
||||||
|
{
|
||||||
|
"Parameters": [
|
||||||
|
{
|
||||||
|
"ParameterKey": "Name",
|
||||||
|
"DefaultValue": "SomeValue",
|
||||||
|
"ParameterType": "String",
|
||||||
|
"NoEcho": False,
|
||||||
|
"Description": "",
|
||||||
|
"ParameterConstraints": {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ParameterKey": "Another",
|
||||||
|
"DefaultValue": "A",
|
||||||
|
"ParameterType": "String",
|
||||||
|
"NoEcho": False,
|
||||||
|
"Description": "Chose A or B",
|
||||||
|
"ParameterConstraints": {"AllowedValues": ["A", "B"]},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"Description": "A simple CloudFormation template",
|
||||||
|
"ResourceTypes": ["AWS::S3::Bucket"],
|
||||||
|
"Version": "2010-09-09",
|
||||||
|
# TODO: get_template_summary should support ResourceIdentifierSummaries
|
||||||
|
# "ResourceIdentifierSummaries": [
|
||||||
|
# {
|
||||||
|
# "ResourceType": "AWS::S3::Bucket",
|
||||||
|
# "LogicalResourceIds": ["Bucket"],
|
||||||
|
# "ResourceIdentifiers": ["BucketName"],
|
||||||
|
# }
|
||||||
|
# ],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_cloudformation
|
@mock_cloudformation
|
||||||
def test_boto3_create_stack_with_ref_yaml():
|
def test_boto3_create_stack_with_ref_yaml():
|
||||||
cf_conn = boto3.client("cloudformation", region_name="us-east-1")
|
cf_conn = boto3.client("cloudformation", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user