Skip to content

Commit

Permalink
chore: add integ test for cross-region refs (#27118)
Browse files Browse the repository at this point in the history
Adds integration test for using cross-region reference custom resource handlers. Currently cross region multi-stack tests in `IntegTest` are not super well supported so assertions aren't a great option but a successful stack deploy and delete does indicate success of the CRs currently.

Closes #27069

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
MrArnoldPalmer authored Sep 12, 2023
1 parent 480b1f5 commit 8c76349
Show file tree
Hide file tree
Showing 15 changed files with 1,545 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "34.0.0",
"files": {
"863f318b36ec4666a297aefb6cf8390c2f0bb6ec4ef3ae0040a63a0727f50ccf": {
"source": {
"path": "asset.863f318b36ec4666a297aefb6cf8390c2f0bb6ec4ef3ae0040a63a0727f50ccf",
"packaging": "zip"
},
"destinations": {
"current_account-us-east-2": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-2",
"objectKey": "863f318b36ec4666a297aefb6cf8390c2f0bb6ec4ef3ae0040a63a0727f50ccf.zip",
"region": "us-east-2",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-2"
}
}
},
"f9d53aeabbd76f4bab5deb04ef649d0ebf6875c5bd7bba157d72aa0a8003ac46": {
"source": {
"path": "CrossRegionRefConsumerInteg.template.json",
"packaging": "file"
},
"destinations": {
"current_account-us-east-2": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-2",
"objectKey": "f9d53aeabbd76f4bab5deb04ef649d0ebf6875c5bd7bba157d72aa0a8003ac46.json",
"region": "us-east-2",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-2"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"Resources": {
"SomeParameterMirroredE2D8F3B8": {
"Type": "AWS::SSM::Parameter",
"Properties": {
"Name": "KNOWN_PARAMETER_NAME",
"Type": "String",
"Value": {
"Fn::GetAtt": [
"ExportsReader8B249524",
"/cdk/exports/CrossRegionRefConsumerInteg/CrossRegionRefProducerInteguseast1FnGetAttSomeParameterB1EDD45BValue399DD9D8"
]
}
}
},
"ExportsReader8B249524": {
"Type": "Custom::CrossRegionExportReader",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"CustomCrossRegionExportReaderCustomResourceProviderHandler46647B68",
"Arn"
]
},
"ReaderProps": {
"region": "us-east-2",
"prefix": "CrossRegionRefConsumerInteg",
"imports": {
"/cdk/exports/CrossRegionRefConsumerInteg/CrossRegionRefProducerInteguseast1FnGetAttSomeParameterB1EDD45BValue399DD9D8": "{{resolve:ssm:/cdk/exports/CrossRegionRefConsumerInteg/CrossRegionRefProducerInteguseast1FnGetAttSomeParameterB1EDD45BValue399DD9D8}}"
}
}
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"CustomCrossRegionExportReaderCustomResourceProviderRole10531BBD": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
},
"ManagedPolicyArns": [
{
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
],
"Policies": [
{
"PolicyName": "Inline",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ssm:us-east-2:",
{
"Ref": "AWS::AccountId"
},
":parameter/cdk/exports/CrossRegionRefConsumerInteg/*"
]
]
},
"Action": [
"ssm:AddTagsToResource",
"ssm:RemoveTagsFromResource",
"ssm:GetParameters"
]
}
]
}
}
]
}
},
"CustomCrossRegionExportReaderCustomResourceProviderHandler46647B68": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-2"
},
"S3Key": "863f318b36ec4666a297aefb6cf8390c2f0bb6ec4ef3ae0040a63a0727f50ccf.zip"
},
"Timeout": 900,
"MemorySize": 128,
"Handler": "__entrypoint__.handler",
"Role": {
"Fn::GetAtt": [
"CustomCrossRegionExportReaderCustomResourceProviderRole10531BBD",
"Arn"
]
},
"Runtime": "nodejs18.x"
},
"DependsOn": [
"CustomCrossRegionExportReaderCustomResourceProviderRole10531BBD"
]
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "34.0.0",
"files": {
"1a067234d252533a95ecaaccd4b3e821e6a69df0b03b918b596fc5a40eeb71a1": {
"source": {
"path": "asset.1a067234d252533a95ecaaccd4b3e821e6a69df0b03b918b596fc5a40eeb71a1",
"packaging": "zip"
},
"destinations": {
"current_account-us-east-1": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1",
"objectKey": "1a067234d252533a95ecaaccd4b3e821e6a69df0b03b918b596fc5a40eeb71a1.zip",
"region": "us-east-1",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1"
}
}
},
"de0260269768be40f7cca7a538a2cd2a560a133f1e3d18b60a42d270ecb20120": {
"source": {
"path": "CrossRegionRefProducerInteg.template.json",
"packaging": "file"
},
"destinations": {
"current_account-us-east-1": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1",
"objectKey": "de0260269768be40f7cca7a538a2cd2a560a133f1e3d18b60a42d270ecb20120.json",
"region": "us-east-1",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"Resources": {
"SomeParameterB1EDD45B": {
"Type": "AWS::SSM::Parameter",
"Properties": {
"Name": "KNOWN_PARAMETER_NAME",
"Type": "String",
"Value": "MY_PARAMETER_VALUE"
}
},
"ExportsWriteruseast2828FA26B86FBEFA7": {
"Type": "Custom::CrossRegionExportWriter",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"CustomCrossRegionExportWriterCustomResourceProviderHandlerD8786E8A",
"Arn"
]
},
"WriterProps": {
"region": "us-east-2",
"exports": {
"/cdk/exports/CrossRegionRefConsumerInteg/CrossRegionRefProducerInteguseast1FnGetAttSomeParameterB1EDD45BValue399DD9D8": {
"Fn::GetAtt": [
"SomeParameterB1EDD45B",
"Value"
]
}
}
}
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"CustomCrossRegionExportWriterCustomResourceProviderRoleC951B1E1": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
},
"ManagedPolicyArns": [
{
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
],
"Policies": [
{
"PolicyName": "Inline",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:ssm:us-east-2:",
{
"Ref": "AWS::AccountId"
},
":parameter/cdk/exports/*"
]
]
}
],
"Action": [
"ssm:DeleteParameters",
"ssm:ListTagsForResource",
"ssm:GetParameters",
"ssm:PutParameter"
]
}
]
}
}
]
}
},
"CustomCrossRegionExportWriterCustomResourceProviderHandlerD8786E8A": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1"
},
"S3Key": "1a067234d252533a95ecaaccd4b3e821e6a69df0b03b918b596fc5a40eeb71a1.zip"
},
"Timeout": 900,
"MemorySize": 128,
"Handler": "__entrypoint__.handler",
"Role": {
"Fn::GetAtt": [
"CustomCrossRegionExportWriterCustomResourceProviderRoleC951B1E1",
"Arn"
]
},
"Runtime": "nodejs18.x"
},
"DependsOn": [
"CustomCrossRegionExportWriterCustomResourceProviderRoleC951B1E1"
]
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "34.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "CrossRegionSSMReferenceTestDefaultTestDeployAssert2460BCA3.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Loading

0 comments on commit 8c76349

Please sign in to comment.