diff --git a/packages/@aws-cdk/aws-ssm/test/integ.list-parameter-as-cfn-parameter.ts b/packages/@aws-cdk/aws-ssm/test/integ.list-parameter-as-cfn-parameter.ts new file mode 100644 index 0000000000000..11da7403dfa24 --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/integ.list-parameter-as-cfn-parameter.ts @@ -0,0 +1,89 @@ +import * as cdk from '@aws-cdk/core'; +import { IntegTest, ExpectedResult, Match } from '@aws-cdk/integ-tests'; +import { Construct } from 'constructs'; +import * as ssm from '../lib'; +const paramName = 'integ-list-param'; +const paramValue = ['value1', 'value2']; + +class TestCaseBase extends cdk.Stack { + public readonly listParam: ssm.IStringListParameter; + constructor(scope: Construct, id: string) { + super(scope, id); + + this.listParam = new ssm.StringListParameter(this, 'ListParam', { + parameterName: paramName, + stringListValue: paramValue, + }); + } +} + + +const app = new cdk.App({ + treeMetadata: false, +}); +/** + * This test case is to verify the previous behavior of the @aws-cdk/aws-ssm:importParameterAsDynamicReference Feature Flag + */ +app.node.setContext('@aws-cdk/aws-ssm:importParameterAsDynamicReference', false); +app.node.setContext('@aws-cdk/core:newStyleStackSynthesis', true); +const base = new TestCaseBase(app, 'base'); +const testCase = new cdk.Stack(app, 'list-param'); + +// creates the dependency between stacks +new cdk.CfnOutput(testCase, 'Output', { + value: cdk.Fn.join(',', base.listParam.stringListValue), +}); + + +/** + * get the value from the `base` stack and then write it to a new parameter + * We will then assert that the value that is written is the correct value + * This validates that the `fromXXX` and `valueForXXX` imports the value correctly + */ + +const fromAttrs = ssm.StringListParameter.fromListParameterAttributes(testCase, 'FromAttrs', { + parameterName: paramName, + elementType: ssm.ParameterValueType.STRING, +}); +const ssmAttrsValue = new ssm.CfnParameter(testCase, 'attrs-test', { + type: 'StringList', + value: cdk.Fn.join(',', fromAttrs.stringListValue), +}); + +const value = ssm.StringListParameter.valueForTypedListParameter(testCase, paramName, ssm.ParameterValueType.STRING); +const ssmValue = new ssm.CfnParameter(testCase, 'value-test', { + type: 'StringList', + value: cdk.Fn.join(',', value), +}); + +const versionValue = ssm.StringListParameter.valueForTypedListParameter(testCase, paramName, ssm.ParameterValueType.STRING, 1); +const ssmVersionValue = new ssm.CfnParameter(testCase, 'version-value-test', { + type: 'StringList', + value: cdk.Fn.join(',', versionValue), +}); + + +const integ = new IntegTest(app, 'ssm-string-param', { + testCases: [ + testCase, + ], +}); + +// list the parameters +const actualAttrs = integ.assertions.awsApiCall('SSM', 'getParameters', { + Names: [ssmVersionValue.ref, ssmValue.ref, ssmAttrsValue.ref], +}); + +actualAttrs.expect(ExpectedResult.objectLike({ + Parameters: Match.arrayWith([ + Match.objectLike({ + Value: paramValue.join(','), + }), + Match.objectLike({ + Value: paramValue.join(','), + }), + Match.objectLike({ + Value: paramValue.join(','), + }), + ]), +})); diff --git a/packages/@aws-cdk/aws-ssm/test/integ.list-parameter.ts b/packages/@aws-cdk/aws-ssm/test/integ.list-parameter.ts index 81d438fa96f9c..d7dd8929f54de 100644 --- a/packages/@aws-cdk/aws-ssm/test/integ.list-parameter.ts +++ b/packages/@aws-cdk/aws-ssm/test/integ.list-parameter.ts @@ -21,6 +21,10 @@ class TestCaseBase extends cdk.Stack { const app = new cdk.App({ treeMetadata: false, }); +/** + * This test case is to verify the current behavior of the @aws-cdk/aws-ssm:importParameterAsDynamicReference Feature Flag + */ +app.node.setContext('@aws-cdk/aws-ssm:importParameterAsDynamicReference', true); app.node.setContext('@aws-cdk/core:newStyleStackSynthesis', true); const base = new TestCaseBase(app, 'base'); const testCase = new cdk.Stack(app, 'list-param'); diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/asset.84802aa01d2d2c9e7d8d69705ee832c97f1ebad2d73c72be5c32d53f16cf90a7.bundle/index.js b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/asset.84802aa01d2d2c9e7d8d69705ee832c97f1ebad2d73c72be5c32d53f16cf90a7.bundle/index.js new file mode 100644 index 0000000000000..ba956d47f51fe --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/asset.84802aa01d2d2c9e7d8d69705ee832c97f1ebad2d73c72be5c32d53f16cf90a7.bundle/index.js @@ -0,0 +1,612 @@ +"use strict"; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// lib/assertions/providers/lambda-handler/index.ts +var lambda_handler_exports = {}; +__export(lambda_handler_exports, { + handler: () => handler +}); +module.exports = __toCommonJS(lambda_handler_exports); + +// ../assertions/lib/matcher.ts +var Matcher = class { + static isMatcher(x) { + return x && x instanceof Matcher; + } +}; +var MatchResult = class { + constructor(target) { + this.failures = []; + this.captures = /* @__PURE__ */ new Map(); + this.finalized = false; + this.target = target; + } + push(matcher, path, message) { + return this.recordFailure({ matcher, path, message }); + } + recordFailure(failure) { + this.failures.push(failure); + return this; + } + hasFailed() { + return this.failures.length !== 0; + } + get failCount() { + return this.failures.length; + } + compose(id, inner) { + const innerF = inner.failures; + this.failures.push(...innerF.map((f) => { + return { path: [id, ...f.path], message: f.message, matcher: f.matcher }; + })); + inner.captures.forEach((vals, capture) => { + vals.forEach((value) => this.recordCapture({ capture, value })); + }); + return this; + } + finished() { + if (this.finalized) { + return this; + } + if (this.failCount === 0) { + this.captures.forEach((vals, cap) => cap._captured.push(...vals)); + } + this.finalized = true; + return this; + } + toHumanStrings() { + return this.failures.map((r) => { + const loc = r.path.length === 0 ? "" : ` at ${r.path.join("")}`; + return "" + r.message + loc + ` (using ${r.matcher.name} matcher)`; + }); + } + recordCapture(options) { + let values = this.captures.get(options.capture); + if (values === void 0) { + values = []; + } + values.push(options.value); + this.captures.set(options.capture, values); + } +}; + +// ../assertions/lib/private/matchers/absent.ts +var AbsentMatch = class extends Matcher { + constructor(name) { + super(); + this.name = name; + } + test(actual) { + const result = new MatchResult(actual); + if (actual !== void 0) { + result.recordFailure({ + matcher: this, + path: [], + message: `Received ${actual}, but key should be absent` + }); + } + return result; + } +}; + +// ../assertions/lib/private/type.ts +function getType(obj) { + return Array.isArray(obj) ? "array" : typeof obj; +} + +// ../assertions/lib/match.ts +var Match = class { + static absent() { + return new AbsentMatch("absent"); + } + static arrayWith(pattern) { + return new ArrayMatch("arrayWith", pattern); + } + static arrayEquals(pattern) { + return new ArrayMatch("arrayEquals", pattern, { subsequence: false }); + } + static exact(pattern) { + return new LiteralMatch("exact", pattern, { partialObjects: false }); + } + static objectLike(pattern) { + return new ObjectMatch("objectLike", pattern); + } + static objectEquals(pattern) { + return new ObjectMatch("objectEquals", pattern, { partial: false }); + } + static not(pattern) { + return new NotMatch("not", pattern); + } + static serializedJson(pattern) { + return new SerializedJson("serializedJson", pattern); + } + static anyValue() { + return new AnyMatch("anyValue"); + } + static stringLikeRegexp(pattern) { + return new StringLikeRegexpMatch("stringLikeRegexp", pattern); + } +}; +var LiteralMatch = class extends Matcher { + constructor(name, pattern, options = {}) { + super(); + this.name = name; + this.pattern = pattern; + this.partialObjects = options.partialObjects ?? false; + if (Matcher.isMatcher(this.pattern)) { + throw new Error("LiteralMatch cannot directly contain another matcher. Remove the top-level matcher or nest it more deeply."); + } + } + test(actual) { + if (Array.isArray(this.pattern)) { + return new ArrayMatch(this.name, this.pattern, { subsequence: false, partialObjects: this.partialObjects }).test(actual); + } + if (typeof this.pattern === "object") { + return new ObjectMatch(this.name, this.pattern, { partial: this.partialObjects }).test(actual); + } + const result = new MatchResult(actual); + if (typeof this.pattern !== typeof actual) { + result.recordFailure({ + matcher: this, + path: [], + message: `Expected type ${typeof this.pattern} but received ${getType(actual)}` + }); + return result; + } + if (actual !== this.pattern) { + result.recordFailure({ + matcher: this, + path: [], + message: `Expected ${this.pattern} but received ${actual}` + }); + } + return result; + } +}; +var ArrayMatch = class extends Matcher { + constructor(name, pattern, options = {}) { + super(); + this.name = name; + this.pattern = pattern; + this.subsequence = options.subsequence ?? true; + this.partialObjects = options.partialObjects ?? false; + } + test(actual) { + if (!Array.isArray(actual)) { + return new MatchResult(actual).recordFailure({ + matcher: this, + path: [], + message: `Expected type array but received ${getType(actual)}` + }); + } + if (!this.subsequence && this.pattern.length !== actual.length) { + return new MatchResult(actual).recordFailure({ + matcher: this, + path: [], + message: `Expected array of length ${this.pattern.length} but received ${actual.length}` + }); + } + let patternIdx = 0; + let actualIdx = 0; + const result = new MatchResult(actual); + while (patternIdx < this.pattern.length && actualIdx < actual.length) { + const patternElement = this.pattern[patternIdx]; + const matcher = Matcher.isMatcher(patternElement) ? patternElement : new LiteralMatch(this.name, patternElement, { partialObjects: this.partialObjects }); + const matcherName = matcher.name; + if (this.subsequence && (matcherName == "absent" || matcherName == "anyValue")) { + throw new Error(`The Matcher ${matcherName}() cannot be nested within arrayWith()`); + } + const innerResult = matcher.test(actual[actualIdx]); + if (!this.subsequence || !innerResult.hasFailed()) { + result.compose(`[${actualIdx}]`, innerResult); + patternIdx++; + actualIdx++; + } else { + actualIdx++; + } + } + for (; patternIdx < this.pattern.length; patternIdx++) { + const pattern = this.pattern[patternIdx]; + const element = Matcher.isMatcher(pattern) || typeof pattern === "object" ? " " : ` [${pattern}] `; + result.recordFailure({ + matcher: this, + path: [], + message: `Missing element${element}at pattern index ${patternIdx}` + }); + } + return result; + } +}; +var ObjectMatch = class extends Matcher { + constructor(name, pattern, options = {}) { + super(); + this.name = name; + this.pattern = pattern; + this.partial = options.partial ?? true; + } + test(actual) { + if (typeof actual !== "object" || Array.isArray(actual)) { + return new MatchResult(actual).recordFailure({ + matcher: this, + path: [], + message: `Expected type object but received ${getType(actual)}` + }); + } + const result = new MatchResult(actual); + if (!this.partial) { + for (const a of Object.keys(actual)) { + if (!(a in this.pattern)) { + result.recordFailure({ + matcher: this, + path: [`/${a}`], + message: "Unexpected key" + }); + } + } + } + for (const [patternKey, patternVal] of Object.entries(this.pattern)) { + if (!(patternKey in actual) && !(patternVal instanceof AbsentMatch)) { + result.recordFailure({ + matcher: this, + path: [`/${patternKey}`], + message: `Missing key '${patternKey}' among {${Object.keys(actual).join(",")}}` + }); + continue; + } + const matcher = Matcher.isMatcher(patternVal) ? patternVal : new LiteralMatch(this.name, patternVal, { partialObjects: this.partial }); + const inner = matcher.test(actual[patternKey]); + result.compose(`/${patternKey}`, inner); + } + return result; + } +}; +var SerializedJson = class extends Matcher { + constructor(name, pattern) { + super(); + this.name = name; + this.pattern = pattern; + } + test(actual) { + const result = new MatchResult(actual); + if (getType(actual) !== "string") { + result.recordFailure({ + matcher: this, + path: [], + message: `Expected JSON as a string but found ${getType(actual)}` + }); + return result; + } + let parsed; + try { + parsed = JSON.parse(actual); + } catch (err) { + if (err instanceof SyntaxError) { + result.recordFailure({ + matcher: this, + path: [], + message: `Invalid JSON string: ${actual}` + }); + return result; + } else { + throw err; + } + } + const matcher = Matcher.isMatcher(this.pattern) ? this.pattern : new LiteralMatch(this.name, this.pattern); + const innerResult = matcher.test(parsed); + result.compose(`(${this.name})`, innerResult); + return result; + } +}; +var NotMatch = class extends Matcher { + constructor(name, pattern) { + super(); + this.name = name; + this.pattern = pattern; + } + test(actual) { + const matcher = Matcher.isMatcher(this.pattern) ? this.pattern : new LiteralMatch(this.name, this.pattern); + const innerResult = matcher.test(actual); + const result = new MatchResult(actual); + if (innerResult.failCount === 0) { + result.recordFailure({ + matcher: this, + path: [], + message: `Found unexpected match: ${JSON.stringify(actual, void 0, 2)}` + }); + } + return result; + } +}; +var AnyMatch = class extends Matcher { + constructor(name) { + super(); + this.name = name; + } + test(actual) { + const result = new MatchResult(actual); + if (actual == null) { + result.recordFailure({ + matcher: this, + path: [], + message: "Expected a value but found none" + }); + } + return result; + } +}; +var StringLikeRegexpMatch = class extends Matcher { + constructor(name, pattern) { + super(); + this.name = name; + this.pattern = pattern; + } + test(actual) { + const result = new MatchResult(actual); + const regex = new RegExp(this.pattern, "gm"); + if (typeof actual !== "string") { + result.recordFailure({ + matcher: this, + path: [], + message: `Expected a string, but got '${typeof actual}'` + }); + } + if (!regex.test(actual)) { + result.recordFailure({ + matcher: this, + path: [], + message: `String '${actual}' did not match pattern '${this.pattern}'` + }); + } + return result; + } +}; + +// lib/assertions/providers/lambda-handler/base.ts +var https = __toESM(require("https")); +var url = __toESM(require("url")); +var CustomResourceHandler = class { + constructor(event, context) { + this.event = event; + this.context = context; + this.timedOut = false; + this.timeout = setTimeout(async () => { + await this.respond({ + status: "FAILED", + reason: "Lambda Function Timeout", + data: this.context.logStreamName + }); + this.timedOut = true; + }, context.getRemainingTimeInMillis() - 1200); + this.event = event; + this.physicalResourceId = extractPhysicalResourceId(event); + } + async handle() { + try { + console.log(`Event: ${JSON.stringify({ ...this.event, ResponseURL: "..." })}`); + const response = await this.processEvent(this.event.ResourceProperties); + console.log(`Event output : ${JSON.stringify(response)}`); + await this.respond({ + status: "SUCCESS", + reason: "OK", + data: response + }); + } catch (e) { + console.log(e); + await this.respond({ + status: "FAILED", + reason: e.message ?? "Internal Error" + }); + } finally { + clearTimeout(this.timeout); + } + } + respond(response) { + if (this.timedOut) { + return; + } + const cfResponse = { + Status: response.status, + Reason: response.reason, + PhysicalResourceId: this.physicalResourceId, + StackId: this.event.StackId, + RequestId: this.event.RequestId, + LogicalResourceId: this.event.LogicalResourceId, + NoEcho: false, + Data: response.data + }; + const responseBody = JSON.stringify(cfResponse); + console.log("Responding to CloudFormation", responseBody); + const parsedUrl = url.parse(this.event.ResponseURL); + const requestOptions = { + hostname: parsedUrl.hostname, + path: parsedUrl.path, + method: "PUT", + headers: { "content-type": "", "content-length": responseBody.length } + }; + return new Promise((resolve, reject) => { + try { + const request2 = https.request(requestOptions, resolve); + request2.on("error", reject); + request2.write(responseBody); + request2.end(); + } catch (e) { + reject(e); + } + }); + } +}; +function extractPhysicalResourceId(event) { + switch (event.RequestType) { + case "Create": + return event.LogicalResourceId; + case "Update": + case "Delete": + return event.PhysicalResourceId; + } +} + +// lib/assertions/providers/lambda-handler/assertion.ts +var AssertionHandler = class extends CustomResourceHandler { + async processEvent(request2) { + let actual = decodeCall(request2.actual); + const expected = decodeCall(request2.expected); + let result; + const matcher = new MatchCreator(expected).getMatcher(); + console.log(`Testing equality between ${JSON.stringify(request2.actual)} and ${JSON.stringify(request2.expected)}`); + const matchResult = matcher.test(actual); + matchResult.finished(); + if (matchResult.hasFailed()) { + result = { + data: JSON.stringify({ + status: "fail", + message: [ + ...matchResult.toHumanStrings(), + JSON.stringify(matchResult.target, void 0, 2) + ].join("\n") + }) + }; + if (request2.failDeployment) { + throw new Error(result.data); + } + } else { + result = { + data: JSON.stringify({ + status: "success" + }) + }; + } + return result; + } +}; +var MatchCreator = class { + constructor(obj) { + this.parsedObj = { + matcher: obj + }; + } + getMatcher() { + try { + const final = JSON.parse(JSON.stringify(this.parsedObj), function(_k, v) { + const nested = Object.keys(v)[0]; + switch (nested) { + case "$ArrayWith": + return Match.arrayWith(v[nested]); + case "$ObjectLike": + return Match.objectLike(v[nested]); + case "$StringLike": + return Match.stringLikeRegexp(v[nested]); + default: + return v; + } + }); + if (Matcher.isMatcher(final.matcher)) { + return final.matcher; + } + return Match.exact(final.matcher); + } catch { + return Match.exact(this.parsedObj.matcher); + } + } +}; +function decodeCall(call) { + if (!call) { + return void 0; + } + try { + const parsed = JSON.parse(call); + return parsed; + } catch (e) { + return call; + } +} + +// lib/assertions/providers/lambda-handler/utils.ts +function decode(object) { + return JSON.parse(JSON.stringify(object), (_k, v) => { + switch (v) { + case "TRUE:BOOLEAN": + return true; + case "FALSE:BOOLEAN": + return false; + default: + return v; + } + }); +} + +// lib/assertions/providers/lambda-handler/sdk.ts +function flatten(object) { + return Object.assign( + {}, + ...function _flatten(child, path = []) { + return [].concat(...Object.keys(child).map((key) => { + const childKey = Buffer.isBuffer(child[key]) ? child[key].toString("utf8") : child[key]; + return typeof childKey === "object" && childKey !== null ? _flatten(childKey, path.concat([key])) : { [path.concat([key]).join(".")]: childKey }; + })); + }(object) + ); +} +var AwsApiCallHandler = class extends CustomResourceHandler { + async processEvent(request2) { + const AWS = require("aws-sdk"); + console.log(`AWS SDK VERSION: ${AWS.VERSION}`); + const service = new AWS[request2.service](); + const response = await service[request2.api](request2.parameters && decode(request2.parameters)).promise(); + console.log(`SDK response received ${JSON.stringify(response)}`); + delete response.ResponseMetadata; + const respond = { + apiCallResponse: response + }; + const flatData = { + ...flatten(respond) + }; + return request2.flattenResponse === "true" ? flatData : respond; + } +}; + +// lib/assertions/providers/lambda-handler/types.ts +var ASSERT_RESOURCE_TYPE = "Custom::DeployAssert@AssertEquals"; +var SDK_RESOURCE_TYPE_PREFIX = "Custom::DeployAssert@SdkCall"; + +// lib/assertions/providers/lambda-handler/index.ts +async function handler(event, context) { + const provider = createResourceHandler(event, context); + await provider.handle(); +} +function createResourceHandler(event, context) { + if (event.ResourceType.startsWith(SDK_RESOURCE_TYPE_PREFIX)) { + return new AwsApiCallHandler(event, context); + } + switch (event.ResourceType) { + case ASSERT_RESOURCE_TYPE: + return new AssertionHandler(event, context); + default: + throw new Error(`Unsupported resource type "${event.ResourceType}`); + } +} +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + handler +}); diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/base.assets.json b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/base.assets.json new file mode 100644 index 0000000000000..9f0c6525d7f91 --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/base.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "1caf5ea1b3cc1aedc4ec46feb2680836eae5804fa1ae1d8a572944636e88531b": { + "source": { + "path": "base.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "1caf5ea1b3cc1aedc4ec46feb2680836eae5804fa1ae1d8a572944636e88531b.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/base.template.json b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/base.template.json new file mode 100644 index 0000000000000..c2bdff818119f --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/base.template.json @@ -0,0 +1,59 @@ +{ + "Resources": { + "ListParam66ABDC3F": { + "Type": "AWS::SSM::Parameter", + "Properties": { + "Type": "StringList", + "Value": "value1,value2", + "Name": "integ-list-param" + } + } + }, + "Outputs": { + "ExportsOutputFnGetAttListParam66ABDC3FValue8C623E22": { + "Value": { + "Fn::GetAtt": [ + "ListParam66ABDC3F", + "Value" + ] + }, + "Export": { + "Name": "base:ExportsOutputFnGetAttListParam66ABDC3FValue8C623E22" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "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." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/integ.json b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/integ.json new file mode 100644 index 0000000000000..1e9ee364aca3e --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "21.0.0", + "testCases": { + "ssm-string-param/DefaultTest": { + "stacks": [ + "list-param" + ], + "assertionStack": "ssm-string-param/DefaultTest/DeployAssert", + "assertionStackName": "ssmstringparamDefaultTestDeployAssert9C612E37" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/list-param.assets.json b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/list-param.assets.json new file mode 100644 index 0000000000000..47303559bc7be --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/list-param.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "f21f04e61fc048db023578e8c9bdab9b7f45992bd3d533bcf7fb9eb87991bc95": { + "source": { + "path": "list-param.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "f21f04e61fc048db023578e8c9bdab9b7f45992bd3d533bcf7fb9eb87991bc95.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/list-param.template.json b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/list-param.template.json new file mode 100644 index 0000000000000..304d3b6c0aa15 --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/list-param.template.json @@ -0,0 +1,129 @@ +{ + "Outputs": { + "Output": { + "Value": { + "Fn::Join": [ + ",", + { + "Fn::Split": [ + ",", + { + "Fn::ImportValue": "base:ExportsOutputFnGetAttListParam66ABDC3FValue8C623E22" + } + ] + } + ] + } + }, + "ExportsOutputRefversionvaluetestB139B4AA": { + "Value": { + "Ref": "versionvaluetest" + }, + "Export": { + "Name": "list-param:ExportsOutputRefversionvaluetestB139B4AA" + } + }, + "ExportsOutputRefvaluetest4DD5FF9D": { + "Value": { + "Ref": "valuetest" + }, + "Export": { + "Name": "list-param:ExportsOutputRefvaluetest4DD5FF9D" + } + }, + "ExportsOutputRefattrstestCCA64863": { + "Value": { + "Ref": "attrstest" + }, + "Export": { + "Name": "list-param:ExportsOutputRefattrstestCCA64863" + } + } + }, + "Parameters": { + "FromAttrsParameter": { + "Type": "AWS::SSM::Parameter::Value>", + "Default": "integ-list-param" + }, + "SsmParameterValueinteglistparamC96584B6F00A464EAD1953AFF4B05118Parameter": { + "Type": "AWS::SSM::Parameter::Value>", + "Default": "integ-list-param" + }, + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Resources": { + "attrstest": { + "Type": "AWS::SSM::Parameter", + "Properties": { + "Type": "StringList", + "Value": { + "Fn::Join": [ + ",", + { + "Ref": "FromAttrsParameter" + } + ] + } + } + }, + "valuetest": { + "Type": "AWS::SSM::Parameter", + "Properties": { + "Type": "StringList", + "Value": { + "Fn::Join": [ + ",", + { + "Ref": "SsmParameterValueinteglistparamC96584B6F00A464EAD1953AFF4B05118Parameter" + } + ] + } + } + }, + "versionvaluetest": { + "Type": "AWS::SSM::Parameter", + "Properties": { + "Type": "StringList", + "Value": { + "Fn::Join": [ + ",", + { + "Ref": "SsmParameterValueinteglistparamC96584B6F00A464EAD1953AFF4B05118Parameter" + } + ] + } + } + } + }, + "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." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/manifest.json new file mode 100644 index 0000000000000..791c72c5ee145 --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/manifest.json @@ -0,0 +1,244 @@ +{ + "version": "21.0.0", + "artifacts": { + "base.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "base.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "base": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "base.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/1caf5ea1b3cc1aedc4ec46feb2680836eae5804fa1ae1d8a572944636e88531b.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "base.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "base.assets" + ], + "metadata": { + "/base/ListParam/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ListParam66ABDC3F" + } + ], + "/base/Exports/Output{\"Fn::GetAtt\":[\"ListParam66ABDC3F\",\"Value\"]}": [ + { + "type": "aws:cdk:logicalId", + "data": "ExportsOutputFnGetAttListParam66ABDC3FValue8C623E22" + } + ], + "/base/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/base/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "base" + }, + "list-param.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "list-param.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "list-param": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "list-param.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f21f04e61fc048db023578e8c9bdab9b7f45992bd3d533bcf7fb9eb87991bc95.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "list-param.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "base", + "list-param.assets" + ], + "metadata": { + "/list-param/Output": [ + { + "type": "aws:cdk:logicalId", + "data": "Output" + } + ], + "/list-param/FromAttrs.Parameter": [ + { + "type": "aws:cdk:logicalId", + "data": "FromAttrsParameter" + } + ], + "/list-param/attrs-test": [ + { + "type": "aws:cdk:logicalId", + "data": "attrstest" + } + ], + "/list-param/SsmParameterValue:integ-list-param:C96584B6-F00A-464E-AD19-53AFF4B05118.Parameter": [ + { + "type": "aws:cdk:logicalId", + "data": "SsmParameterValueinteglistparamC96584B6F00A464EAD1953AFF4B05118Parameter" + } + ], + "/list-param/value-test": [ + { + "type": "aws:cdk:logicalId", + "data": "valuetest" + } + ], + "/list-param/version-value-test": [ + { + "type": "aws:cdk:logicalId", + "data": "versionvaluetest" + } + ], + "/list-param/Exports/Output{\"Ref\":\"versionvaluetest\"}": [ + { + "type": "aws:cdk:logicalId", + "data": "ExportsOutputRefversionvaluetestB139B4AA" + } + ], + "/list-param/Exports/Output{\"Ref\":\"valuetest\"}": [ + { + "type": "aws:cdk:logicalId", + "data": "ExportsOutputRefvaluetest4DD5FF9D" + } + ], + "/list-param/Exports/Output{\"Ref\":\"attrstest\"}": [ + { + "type": "aws:cdk:logicalId", + "data": "ExportsOutputRefattrstestCCA64863" + } + ], + "/list-param/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/list-param/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "list-param" + }, + "ssmstringparamDefaultTestDeployAssert9C612E37.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "ssmstringparamDefaultTestDeployAssert9C612E37.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "ssmstringparamDefaultTestDeployAssert9C612E37": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "ssmstringparamDefaultTestDeployAssert9C612E37.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d9d35ed1a28ac10976e4dd9b6ddc013b41b4a32c67f31023436759ece92ecb46.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "ssmstringparamDefaultTestDeployAssert9C612E37.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "list-param", + "ssmstringparamDefaultTestDeployAssert9C612E37.assets" + ], + "metadata": { + "/ssm-string-param/DefaultTest/DeployAssert/AwsApiCallSSMgetParameters/Default/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "AwsApiCallSSMgetParameters" + } + ], + "/ssm-string-param/DefaultTest/DeployAssert/AwsApiCallSSMgetParameters/AssertEqualsSSMgetParameters/Default/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "AwsApiCallSSMgetParametersAssertEqualsSSMgetParametersE460052D" + } + ], + "/ssm-string-param/DefaultTest/DeployAssert/AwsApiCallSSMgetParameters/AssertEqualsSSMgetParameters/AssertionResults": [ + { + "type": "aws:cdk:logicalId", + "data": "AssertionResultsAssertEqualsSSMgetParameters44682b4e52cb075e09546c5d91dc958e" + } + ], + "/ssm-string-param/DefaultTest/DeployAssert/SingletonFunction1488541a7b23466481b69b4408076b81/Role": [ + { + "type": "aws:cdk:logicalId", + "data": "SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73" + } + ], + "/ssm-string-param/DefaultTest/DeployAssert/SingletonFunction1488541a7b23466481b69b4408076b81/Handler": [ + { + "type": "aws:cdk:logicalId", + "data": "SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F" + } + ], + "/ssm-string-param/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/ssm-string-param/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "ssm-string-param/DefaultTest/DeployAssert" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/ssmstringparamDefaultTestDeployAssert9C612E37.assets.json b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/ssmstringparamDefaultTestDeployAssert9C612E37.assets.json new file mode 100644 index 0000000000000..6535cdd85cb7b --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/ssmstringparamDefaultTestDeployAssert9C612E37.assets.json @@ -0,0 +1,32 @@ +{ + "version": "21.0.0", + "files": { + "84802aa01d2d2c9e7d8d69705ee832c97f1ebad2d73c72be5c32d53f16cf90a7": { + "source": { + "path": "asset.84802aa01d2d2c9e7d8d69705ee832c97f1ebad2d73c72be5c32d53f16cf90a7.bundle", + "packaging": "zip" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "84802aa01d2d2c9e7d8d69705ee832c97f1ebad2d73c72be5c32d53f16cf90a7.zip", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + }, + "d9d35ed1a28ac10976e4dd9b6ddc013b41b4a32c67f31023436759ece92ecb46": { + "source": { + "path": "ssmstringparamDefaultTestDeployAssert9C612E37.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "d9d35ed1a28ac10976e4dd9b6ddc013b41b4a32c67f31023436759ece92ecb46.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/ssmstringparamDefaultTestDeployAssert9C612E37.template.json b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/ssmstringparamDefaultTestDeployAssert9C612E37.template.json new file mode 100644 index 0000000000000..264267a2c6500 --- /dev/null +++ b/packages/@aws-cdk/aws-ssm/test/list-parameter-as-cfn-parameter.integ.snapshot/ssmstringparamDefaultTestDeployAssert9C612E37.template.json @@ -0,0 +1,160 @@ +{ + "Resources": { + "AwsApiCallSSMgetParameters": { + "Type": "Custom::DeployAssert@SdkCallSSMgetParameters", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F", + "Arn" + ] + }, + "service": "SSM", + "api": "getParameters", + "parameters": { + "Names": [ + { + "Fn::ImportValue": "list-param:ExportsOutputRefversionvaluetestB139B4AA" + }, + { + "Fn::ImportValue": "list-param:ExportsOutputRefvaluetest4DD5FF9D" + }, + { + "Fn::ImportValue": "list-param:ExportsOutputRefattrstestCCA64863" + } + ] + }, + "flattenResponse": "false", + "salt": "1664301025137" + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "AwsApiCallSSMgetParametersAssertEqualsSSMgetParametersE460052D": { + "Type": "Custom::DeployAssert@AssertEquals", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F", + "Arn" + ] + }, + "actual": { + "Fn::GetAtt": [ + "AwsApiCallSSMgetParameters", + "apiCallResponse" + ] + }, + "expected": "{\"$ObjectLike\":{\"Parameters\":{\"$ArrayWith\":[{\"$ObjectLike\":{\"Value\":\"value1,value2\"}},{\"$ObjectLike\":{\"Value\":\"value1,value2\"}},{\"$ObjectLike\":{\"Value\":\"value1,value2\"}}]}}}", + "salt": "1664301025138" + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73": { + "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": [ + { + "Action": [ + "ssm:GetParameters" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ] + } + } + ] + } + }, + "SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Runtime": "nodejs14.x", + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "S3Key": "84802aa01d2d2c9e7d8d69705ee832c97f1ebad2d73c72be5c32d53f16cf90a7.zip" + }, + "Timeout": 120, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73", + "Arn" + ] + } + } + } + }, + "Outputs": { + "AssertionResultsAssertEqualsSSMgetParameters44682b4e52cb075e09546c5d91dc958e": { + "Value": { + "Fn::GetAtt": [ + "AwsApiCallSSMgetParametersAssertEqualsSSMgetParametersE460052D", + "data" + ] + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "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." + } + ] + } + } +} \ No newline at end of file