Skip to content

Commit 74f24fe

Browse files
authored
feat: adding support for SSM Parameters (string) as Type (#2469)
* feat: adding support for SSM Parameters as Type * added new entry on parameters.json > Types > enum * added one input to test all correct types pass * added one input and output to test that it will fail if a Parameter is not included in the enum from parameters.json * updated test_validator_root to include these new cases * fix: changed after 'make black'
1 parent 6011ada commit 74f24fe

File tree

5 files changed

+220
-1
lines changed

5 files changed

+220
-1
lines changed

samtranslator/validator/sam_schema/definitions/parameter.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"List<AWS::EC2::Volume::Id>",
6060
"List<AWS::EC2::VPC::Id>",
6161
"List<AWS::Route53::HostedZone::Id>",
62-
"List<String>"
62+
"List<String>",
63+
"AWS::SSM::Parameter::Value<String>"
6364
],
6465
"type": "string"
6566
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Smallest possible API template
2+
Transform: AWS::Serverless-2016-10-31
3+
Parameters:
4+
StringParameter:
5+
Type: String
6+
Default: 'String'
7+
NumberParameter:
8+
Type: Number
9+
Default: 2
10+
CommaDelimitedListParameter:
11+
Type: CommaDelimitedList
12+
Default: 'String,1,6'
13+
AWSZoneParameter:
14+
Type: "AWS::EC2::AvailabilityZone::Name"
15+
Default: 'us-east-1'
16+
AWSImageId:
17+
Type: AWS::EC2::Image::Id
18+
Default: 'Image_ID_1'
19+
AWSInstanceID:
20+
Type: AWS::EC2::Instance::Id
21+
Default: 'Instance_ID_1'
22+
AWSKeyPairName:
23+
Type: AWS::EC2::KeyPair::KeyName
24+
Default: 'Key_Name_1'
25+
AWSSecurityGroupName:
26+
Type: AWS::EC2::SecurityGroup::GroupName
27+
Default: 'Group_Name_1'
28+
AWSSecurityGroupID:
29+
Type: AWS::EC2::SecurityGroup::Id
30+
Default: 'Sec_Group_ID_1'
31+
AWSSubnetID:
32+
Type: AWS::EC2::Subnet::Id
33+
Default: 'Sub_net_ID_1'
34+
AWSVolumeID:
35+
Type: AWS::EC2::Volume::Id
36+
Default: 'Vol_ID_1'
37+
AWSVPCID:
38+
Type: AWS::EC2::VPC::Id
39+
Default: 'VPC_ID_1'
40+
AWSHostedZoneID:
41+
Type: AWS::Route53::HostedZone::Id
42+
Default: 'Hosted_Zone_ID_1'
43+
AWSParameterValue:
44+
Type: AWS::SSM::Parameter::Value<String>
45+
Default: 'Parameter_SSM_1'
46+
StringParameterList:
47+
Type: List<String>
48+
Default:
49+
- 'String'
50+
- 'Other srtring'
51+
NumberParameterList:
52+
Type: List<Number>
53+
Default:
54+
- 1
55+
- 2
56+
AWSZoneParameterList:
57+
Type: List<AWS::EC2::AvailabilityZone::Name>
58+
Default:
59+
- 'us-east-1'
60+
- 'us-east-2'
61+
AWSImageIDList:
62+
Type: List<AWS::EC2::Image::Id>
63+
Default:
64+
- 'Image_ID_1'
65+
- 'Image_ID_2'
66+
AWSInstanceIDList:
67+
Type: List<AWS::EC2::Instance::Id>
68+
Default:
69+
- 'Instance_ID_1'
70+
- 'Instance_ID_2'
71+
AWSSecurityGroupNameList:
72+
Type: AWS::EC2::SecurityGroup::GroupName
73+
Default:
74+
- 'Group_Name_1'
75+
- 'Group_Name_2'
76+
AWSSecurityGroupIDList:
77+
Type: List<AWS::EC2::SecurityGroup::Id>
78+
Default:
79+
- 'Sec_Group_ID_1'
80+
- 'Sec_Group_ID_2'
81+
AWSSubnetIDList:
82+
Type: List<AWS::EC2::Subnet::Id>
83+
Default:
84+
- 'Sub_net_ID_1'
85+
- 'Sub_net_ID_2'
86+
AWSVolumeIDList:
87+
Type: List<AWS::EC2::Volume::Id>
88+
Default:
89+
- 'Vol_ID_1'
90+
- 'Vol_ID_2'
91+
AWSVPCIDList:
92+
Type: List<AWS::EC2::VPC::Id>
93+
Default:
94+
- 'VPC_ID_1'
95+
- 'VPC_ID_2'
96+
AWSHostedZoneIDList:
97+
Type: List<AWS::Route53::HostedZone::Id>
98+
Default:
99+
- 'Hosted_Zone_ID_1'
100+
- 'Hosted_Zone_ID_2'
101+
BadTypeParameter:
102+
Type: OtherThatIsNotOnTheEnumLikeTheOnesAbove
103+
Default: 'This will trigger an error'
104+
Resources:
105+
MyApi:
106+
Type: AWS::Serverless::Api
107+
Properties:
108+
StageName: Stage Name
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Smallest possible API template
2+
Transform: AWS::Serverless-2016-10-31
3+
Parameters:
4+
StringParameter:
5+
Type: String
6+
Default: 'String'
7+
NumberParameter:
8+
Type: Number
9+
Default: 2
10+
CommaDelimitedListParameter:
11+
Type: CommaDelimitedList
12+
Default: 'String,1,6'
13+
AWSZoneParameter:
14+
Type: "AWS::EC2::AvailabilityZone::Name"
15+
Default: 'us-east-1'
16+
AWSImageId:
17+
Type: AWS::EC2::Image::Id
18+
Default: 'Image_ID_1'
19+
AWSInstanceID:
20+
Type: AWS::EC2::Instance::Id
21+
Default: 'Instance_ID_1'
22+
AWSKeyPairName:
23+
Type: AWS::EC2::KeyPair::KeyName
24+
Default: 'Key_Name_1'
25+
AWSSecurityGroupName:
26+
Type: AWS::EC2::SecurityGroup::GroupName
27+
Default: 'Group_Name_1'
28+
AWSSecurityGroupID:
29+
Type: AWS::EC2::SecurityGroup::Id
30+
Default: 'Sec_Group_ID_1'
31+
AWSSubnetID:
32+
Type: AWS::EC2::Subnet::Id
33+
Default: 'Sub_net_ID_1'
34+
AWSVolumeID:
35+
Type: AWS::EC2::Volume::Id
36+
Default: 'Vol_ID_1'
37+
AWSVPCID:
38+
Type: AWS::EC2::VPC::Id
39+
Default: 'VPC_ID_1'
40+
AWSHostedZoneID:
41+
Type: AWS::Route53::HostedZone::Id
42+
Default: 'Hosted_Zone_ID_1'
43+
AWSParameterValue:
44+
Type: AWS::SSM::Parameter::Value<String>
45+
Default: 'Parameter_SSM_1'
46+
StringParameterList:
47+
Type: List<String>
48+
Default:
49+
- 'String'
50+
- 'Other srtring'
51+
NumberParameterList:
52+
Type: List<Number>
53+
Default:
54+
- 1
55+
- 2
56+
AWSZoneParameterList:
57+
Type: List<AWS::EC2::AvailabilityZone::Name>
58+
Default:
59+
- 'us-east-1'
60+
- 'us-east-2'
61+
AWSImageIDList:
62+
Type: List<AWS::EC2::Image::Id>
63+
Default:
64+
- 'Image_ID_1'
65+
- 'Image_ID_2'
66+
AWSInstanceIDList:
67+
Type: List<AWS::EC2::Instance::Id>
68+
Default:
69+
- 'Instance_ID_1'
70+
- 'Instance_ID_2'
71+
AWSSecurityGroupNameList:
72+
Type: AWS::EC2::SecurityGroup::GroupName
73+
Default:
74+
- 'Group_Name_1'
75+
- 'Group_Name_2'
76+
AWSSecurityGroupIDList:
77+
Type: List<AWS::EC2::SecurityGroup::Id>
78+
Default:
79+
- 'Sec_Group_ID_1'
80+
- 'Sec_Group_ID_2'
81+
AWSSubnetIDList:
82+
Type: List<AWS::EC2::Subnet::Id>
83+
Default:
84+
- 'Sub_net_ID_1'
85+
- 'Sub_net_ID_2'
86+
AWSVolumeIDList:
87+
Type: List<AWS::EC2::Volume::Id>
88+
Default:
89+
- 'Vol_ID_1'
90+
- 'Vol_ID_2'
91+
AWSVPCIDList:
92+
Type: List<AWS::EC2::VPC::Id>
93+
Default:
94+
- 'VPC_ID_1'
95+
- 'VPC_ID_2'
96+
AWSHostedZoneID:
97+
Type: List<AWS::Route53::HostedZone::Id>
98+
Default:
99+
- 'Hosted_Zone_ID_1'
100+
- 'Hosted_Zone_ID_2'
101+
Resources:
102+
MyApi:
103+
Type: AWS::Serverless::Api
104+
Properties:
105+
StageName: Stage Name
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
"[Parameters.BadTypeParameter.Type] 'OtherThatIsNotOnTheEnumLikeTheOnesAbove' is not one of ['String', 'Number', 'List<Number>', 'CommaDelimitedList', 'AWS::EC2::AvailabilityZone::Name', 'AWS::EC2::Image::Id', 'AWS::EC2::Instance::Id', 'AWS::EC2::KeyPair::KeyName', 'AWS::EC2::SecurityGroup::GroupName', 'AWS::EC2::SecurityGroup::Id', 'AWS::EC2::Subnet::Id', 'AWS::EC2::Volume::Id', 'AWS::EC2::VPC::Id', 'AWS::Route53::HostedZone::Id', 'List<AWS::EC2::AvailabilityZone::Name>', 'List<AWS::EC2::Image::Id>', 'List<AWS::EC2::Instance::Id>', 'List<AWS::EC2::SecurityGroup::GroupName>', 'List<AWS::EC2::SecurityGroup::Id>', 'List<AWS::EC2::Subnet::Id>', 'List<AWS::EC2::Volume::Id>', 'List<AWS::EC2::VPC::Id>', 'List<AWS::Route53::HostedZone::Id>', 'List<String>', 'AWS::SSM::Parameter::Value<String>']"
3+
]

tests/validator/test_validator_root.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class TestValidatorRoot(TestValidatorBase):
1616
[
1717
"error_awstemplateformatversion_unknown",
1818
"error_empty_template",
19+
"error_minimal_template_with_parameters",
1920
"error_resources_empty",
2021
"error_resources_missing",
2122
"error_resources_not_object",
@@ -28,6 +29,7 @@ def test_errors(self, template):
2829

2930
@parameterized.expand(
3031
[
32+
"success_minimal_template_with_parameters",
3133
"success_minimal_template",
3234
],
3335
)

0 commit comments

Comments
 (0)