-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Francis <[email protected]>
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...-integ/test/custom-resources/test/aws-custom-resource/integ.aws-custom-resource-ssm-ff.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { IntegTest } from '@aws-cdk/integ-tests-alpha'; | ||
import { App, CfnOutput, Stack, StackProps } from 'aws-cdk-lib'; | ||
import { StringParameter } from 'aws-cdk-lib/aws-ssm'; | ||
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from 'aws-cdk-lib/custom-resources'; | ||
import { LOG_API_RESPONSE_DATA_PROPERTY_TRUE_DEFAULT } from 'aws-cdk-lib/cx-api'; | ||
import { Construct } from 'constructs'; | ||
|
||
const app = new App({ postCliContext: { [LOG_API_RESPONSE_DATA_PROPERTY_TRUE_DEFAULT]: true } }); | ||
|
||
class CreateParameterStack extends Stack { | ||
public readonly parameterName: string; | ||
|
||
public constructor(scope: Construct, id: string, props: StackProps = {}) { | ||
super(scope, id, props); | ||
|
||
const parameter = new StringParameter(this, 'Secret', { | ||
parameterName: 'Password', | ||
stringValue: 'ThisIsMyPassword', | ||
}); | ||
|
||
this.parameterName = parameter.parameterName; | ||
} | ||
} | ||
|
||
interface GetParameterStackProps extends StackProps { | ||
readonly parameterName: string; | ||
} | ||
|
||
class GetParameterStack extends Stack { | ||
public constructor(scope: Construct, id: string, props: GetParameterStackProps) { | ||
super(scope, id, props); | ||
|
||
const getSecret = new AwsCustomResource(this, 'GetSecret', { | ||
onUpdate: { | ||
service: 'SSM', | ||
action: 'GetParameter', | ||
parameters: { | ||
Name: props.parameterName, | ||
WithDecryption: true, | ||
}, | ||
physicalResourceId: PhysicalResourceId.of(props.parameterName), | ||
}, | ||
policy: AwsCustomResourcePolicy.fromSdkCalls({ | ||
resources: AwsCustomResourcePolicy.ANY_RESOURCE, | ||
}), | ||
}); | ||
|
||
const value = getSecret.getResponseField('Parameter.Value'); | ||
new CfnOutput(this, 'RevealSecret', { value }); | ||
} | ||
} | ||
|
||
const createParameterStack = new CreateParameterStack(app, 'CreateParameterStack'); | ||
const getParameterStack = new GetParameterStack(app, 'GetParameterStack', { | ||
parameterName: createParameterStack.parameterName, | ||
}); | ||
|
||
getParameterStack.addDependency(createParameterStack); | ||
|
||
new IntegTest(app, 'AwsCustomResourceSsmInteg', { | ||
testCases: [createParameterStack, getParameterStack], | ||
}); |