Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ Supported pseudo parameters:
- AWS::AccountId
- AWS::Partition
- AWS::StackName (returns the literal string "StackName")
- AWS::StackId (returns a dummy StackId)
- AWS::NoValue

[Dynamic SSM references](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html) are supported, but must have a version number. This is to help ensure the same parameter that is validated is the one that is deployed. This restriction can be overridden with the --allow-dynamic-ref-without-version argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def evaluate(self, resource_logical_name_or_param, visited_nodes=None):
# just return some default value, we won't know this in advance
return "StackName"

if resource_logical_name_or_param == "AWS::StackId":
# build a well-formatted default StackId, we won't know this in advance
return ":".join(["arn", self.account_config.partition, "cloudformation", self.account_config.region,
self.account_config.account_id, "stack/StackName/00000000-0000-0000-0000-000000000000"])

if resource_logical_name_or_param == "AWS::NoValue":
return NoValue()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_returns_the_region(self):

class WhenEvaluatingAPolicyWithARefToStackName(unittest.TestCase):
@mock_node_evaluator_setup()
def test_returns_the_partition(self):
def test_returns_the_stack_name(self):
template = load_resources({
'ResourceA': {
'Type': 'AWS::Random::Service',
Expand All @@ -89,6 +89,27 @@ def test_returns_the_partition(self):
result = node_evaluator.eval(template['Resources']['ResourceA']['Properties']['PropertyA'])
self.assertEqual(result, 'StackName')

class WhenEvaluatingAPolicyWithARefToStackId(unittest.TestCase):
@mock_node_evaluator_setup()
def test_returns_the_stack_id(self):
template = load_resources({
'ResourceA': {
'Type': 'AWS::Random::Service',
'Properties': {
'PropertyA': {
"Ref": "AWS::StackId"
}
}
}
})

node_evaluator = build_node_evaluator(template)

result = node_evaluator.eval(template['Resources']['ResourceA']['Properties']['PropertyA'])
self.assertEqual(result, ":".join(["arn", account_config.partition, "cloudformation",
account_config.region, account_config.account_id,
"stack/StackName/00000000-0000-0000-0000-000000000000"]))


class WhenEvaluatingAPolicyWithARefToAnArn(unittest.TestCase):
@mock_node_evaluator_setup()
Expand Down
Empty file modified scripts/run_all_tests.sh
100644 → 100755
Empty file.
Empty file modified scripts/run_integration_tests.sh
100644 → 100755
Empty file.
Empty file modified scripts/run_unit_tests.sh
100644 → 100755
Empty file.
10 changes: 9 additions & 1 deletion test_files/test_file_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
"BucketName": {
"Fn::Sub": "${EnvironmentName}-app-artifacts"
},
"AccessControl": "BucketOwnerFullControl"
"AccessControl": "BucketOwnerFullControl",
"Tags": [
{
"Key": "parentStackId",
"Value": {
"Ref": "AWS::StackId"
}
}
]
}
},
"MyTopic": {
Expand Down
3 changes: 3 additions & 0 deletions test_files/test_file_2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Resources:
Properties:
BucketName: !Sub ${EnvironmentName}-app-artifacts
AccessControl: BucketOwnerFullControl
Tags:
- Key: 'ParentStackId'
Value: !Ref AWS::StackId

MyTopic:
Type: AWS::SNS::Topic
Expand Down