From de0a9e218eeccbe4f685e45f93e25a250733dc51 Mon Sep 17 00:00:00 2001 From: Jane Chen <125300057+chenjane-dev@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:57:52 -0500 Subject: [PATCH] feat(appconfig): inline YAML support for hosted configuration (#27696) Adding an additional helper for using inline content for a YAML config ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../@aws-cdk/aws-appconfig-alpha/README.md | 8 ++ .../aws-appconfig-alpha/lib/configuration.ts | 12 ++ .../test/configuration.test.ts | 33 +++++ ...efaultTestDeployAssert6752CD38.assets.json | 2 +- .../aws-appconfig-configuration.assets.json | 6 +- .../aws-appconfig-configuration.template.json | 54 ++++++++ .../integ.configuration.js.snapshot/cdk.out | 2 +- .../integ.json | 2 +- .../manifest.json | 30 ++++- .../integ.configuration.js.snapshot/tree.json | 116 +++++++++++++++++- .../test/integ.configuration.ts | 8 ++ 11 files changed, 259 insertions(+), 14 deletions(-) diff --git a/packages/@aws-cdk/aws-appconfig-alpha/README.md b/packages/@aws-cdk/aws-appconfig-alpha/README.md index e5247dd5c7e59..dabcd2f4d27a9 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/README.md +++ b/packages/@aws-cdk/aws-appconfig-alpha/README.md @@ -83,6 +83,14 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', { }); ``` +You can define hosted configuration content using any of the following ConfigurationContent methods: + +* `fromFile` - Defines the hosted configuration content from a file. +* `fromInlineText` - Defines the hosted configuration from inline text. +* `fromInlineJson` - Defines the hosted configuration from inline JSON. +* `fromInlineYaml` - Defines the hosted configuration from inline YAML. +* `fromInline` - Defines the hosted configuration from user-specified content types. + AWS AppConfig supports the following types of configuration profiles. * **Feature flag**: Use a feature flag configuration to turn on new features that require a timely deployment, such as a product launch or announcement. diff --git a/packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts b/packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts index de7f0668d6980..25eb4adbacc02 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts +++ b/packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts @@ -828,6 +828,18 @@ export abstract class ConfigurationContent { }; } + /** + * Defines the hosted configuration content as YAML from inline code. + * + * @param content The inline code that defines the configuration content + */ + public static fromInlineYaml(content: string): ConfigurationContent { + return { + content, + contentType: 'application/x-yaml', + }; + } + /** * The configuration content. */ diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/configuration.test.ts b/packages/@aws-cdk/aws-appconfig-alpha/test/configuration.test.ts index 5e4479b61979b..5dea1759339fc 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/configuration.test.ts +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/configuration.test.ts @@ -434,6 +434,39 @@ describe('configuration', () => { }); }); + test('default configuration from inline yaml', () => { + const stack = new cdk.Stack(); + const app = new Application(stack, 'MyAppConfig'); + new HostedConfiguration(stack, 'MyConfiguration', { + deploymentStrategy: new DeploymentStrategy(stack, 'MyDeploymentStrategy', { + rolloutStrategy: RolloutStrategy.linear({ + growthFactor: 15, + deploymentDuration: cdk.Duration.minutes(30), + }), + }), + application: app, + content: ConfigurationContent.fromInlineYaml('This should be of content type application/x-yaml'), + }); + + Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', { + Name: 'MyConfiguration', + ApplicationId: { + Ref: 'MyAppConfigB4B63E75', + }, + LocationUri: 'hosted', + }); + Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::HostedConfigurationVersion', { + ApplicationId: { + Ref: 'MyAppConfigB4B63E75', + }, + ConfigurationProfileId: { + Ref: 'MyConfigurationConfigurationProfileEE0ECA85', + }, + Content: 'This should be of content type application/x-yaml', + ContentType: 'application/x-yaml', + }); + }); + test('configuration profile with name', () => { const stack = new cdk.Stack(); const app = new Application(stack, 'MyAppConfig'); diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/appconfigconfigurationDefaultTestDeployAssert6752CD38.assets.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/appconfigconfigurationDefaultTestDeployAssert6752CD38.assets.json index e88b36a4a2c59..6514b84869734 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/appconfigconfigurationDefaultTestDeployAssert6752CD38.assets.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/appconfigconfigurationDefaultTestDeployAssert6752CD38.assets.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.assets.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.assets.json index 3f2c4e58bfe66..43f8777cfacf7 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.assets.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.assets.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "files": { "e2277687077a2abf9ae1af1cc9565e6715e2ebb62f79ec53aa75a1af9298f642": { "source": { @@ -53,7 +53,7 @@ } } }, - "76b9cabe996a7bad89a83038f1c4375968b6a16e8f5f1e2ce353b667d8576cbe": { + "cdb2df2d01c3d2e405d608dcfa9a277a475d8574f0ef1bf555da9d71547f5b97": { "source": { "path": "aws-appconfig-configuration.template.json", "packaging": "file" @@ -61,7 +61,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "76b9cabe996a7bad89a83038f1c4375968b6a16e8f5f1e2ce353b667d8576cbe.json", + "objectKey": "cdb2df2d01c3d2e405d608dcfa9a277a475d8574f0ef1bf555da9d71547f5b97.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.template.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.template.json index 6dbdcb9b930ac..1f33df5bfaab8 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.template.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.template.json @@ -24,6 +24,15 @@ "Name": "awsappconfigconfiguration-MyAppConfig-HostedEnvFromJson-140D2DDD" } }, + "MyAppConfigHostedEnvFromYaml82D3D1B2": { + "Type": "AWS::AppConfig::Environment", + "Properties": { + "ApplicationId": { + "Ref": "MyAppConfigB4B63E75" + }, + "Name": "awsappconfigconfiguration-MyAppConfig-HostedEnvFromYaml-BB2C802A" + } + }, "MyAppConfigParameterEnvD769FB19": { "Type": "AWS::AppConfig::Environment", "Properties": { @@ -175,6 +184,51 @@ } } }, + "MyHostedConfigFromYamlConfigurationProfile7C77A435": { + "Type": "AWS::AppConfig::ConfigurationProfile", + "Properties": { + "ApplicationId": { + "Ref": "MyAppConfigB4B63E75" + }, + "LocationUri": "hosted", + "Name": "awsappconfigconfiguration-MyHostedConfigFromYaml-87E9786A" + } + }, + "MyHostedConfigFromYaml13C5BE35": { + "Type": "AWS::AppConfig::HostedConfigurationVersion", + "Properties": { + "ApplicationId": { + "Ref": "MyAppConfigB4B63E75" + }, + "ConfigurationProfileId": { + "Ref": "MyHostedConfigFromYamlConfigurationProfile7C77A435" + }, + "Content": "This is the configuration content", + "ContentType": "application/x-yaml" + }, + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "MyHostedConfigFromYamlDeploymentFE9624CBE5FC6": { + "Type": "AWS::AppConfig::Deployment", + "Properties": { + "ApplicationId": { + "Ref": "MyAppConfigB4B63E75" + }, + "ConfigurationProfileId": { + "Ref": "MyHostedConfigFromYamlConfigurationProfile7C77A435" + }, + "ConfigurationVersion": { + "Ref": "MyHostedConfigFromYaml13C5BE35" + }, + "DeploymentStrategyId": { + "Ref": "MyDeployStrategy062CAEA2" + }, + "EnvironmentId": { + "Ref": "MyAppConfigHostedEnvFromYaml82D3D1B2" + } + } + }, "MyValidatorFunctionServiceRole5CD02390": { "Type": "AWS::IAM::Role", "Properties": { diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/cdk.out b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/cdk.out index f0b901e7c06e5..2313ab5436501 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"32.0.0"} \ No newline at end of file +{"version":"34.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/integ.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/integ.json index 7d30ed8fc2aa4..af87c578c3c90 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/integ.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "testCases": { "appconfig-configuration/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/manifest.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/manifest.json index 803f0bed5f4f7..f6e79236ae967 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "32.0.0", + "version": "34.0.0", "artifacts": { "aws-appconfig-configuration.assets": { "type": "cdk:asset-manifest", @@ -14,10 +14,11 @@ "environment": "aws://unknown-account/unknown-region", "properties": { "templateFile": "aws-appconfig-configuration.template.json", + "terminationProtection": false, "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}/76b9cabe996a7bad89a83038f1c4375968b6a16e8f5f1e2ce353b667d8576cbe.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/cdb2df2d01c3d2e405d608dcfa9a277a475d8574f0ef1bf555da9d71547f5b97.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -51,6 +52,12 @@ "data": "MyAppConfigHostedEnvFromJson9E6E36C4" } ], + "/aws-appconfig-configuration/MyAppConfig/HostedEnvFromYaml/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyAppConfigHostedEnvFromYaml82D3D1B2" + } + ], "/aws-appconfig-configuration/MyAppConfig/ParameterEnv/Resource": [ { "type": "aws:cdk:logicalId", @@ -123,6 +130,24 @@ "data": "MyHostedConfigFromJsonDeploymentCD82E3049E374" } ], + "/aws-appconfig-configuration/MyHostedConfigFromYaml/ConfigurationProfile": [ + { + "type": "aws:cdk:logicalId", + "data": "MyHostedConfigFromYamlConfigurationProfile7C77A435" + } + ], + "/aws-appconfig-configuration/MyHostedConfigFromYaml/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyHostedConfigFromYaml13C5BE35" + } + ], + "/aws-appconfig-configuration/MyHostedConfigFromYaml/DeploymentFE962": [ + { + "type": "aws:cdk:logicalId", + "data": "MyHostedConfigFromYamlDeploymentFE9624CBE5FC6" + } + ], "/aws-appconfig-configuration/MyValidatorFunction/ServiceRole/Resource": [ { "type": "aws:cdk:logicalId", @@ -403,6 +428,7 @@ "environment": "aws://unknown-account/unknown-region", "properties": { "templateFile": "appconfigconfigurationDefaultTestDeployAssert6752CD38.template.json", + "terminationProtection": false, "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}", diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/tree.json b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/tree.json index df892fd33b39c..198b0457aea04 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/tree.json @@ -80,6 +80,33 @@ "version": "0.0.0" } }, + "HostedEnvFromYaml": { + "id": "HostedEnvFromYaml", + "path": "aws-appconfig-configuration/MyAppConfig/HostedEnvFromYaml", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-appconfig-configuration/MyAppConfig/HostedEnvFromYaml/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AppConfig::Environment", + "aws:cdk:cloudformation:props": { + "applicationId": { + "Ref": "MyAppConfigB4B63E75" + }, + "name": "awsappconfigconfiguration-MyAppConfig-HostedEnvFromYaml-BB2C802A" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_appconfig.CfnEnvironment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-appconfig-alpha.Environment", + "version": "0.0.0" + } + }, "ParameterEnv": { "id": "ParameterEnv", "path": "aws-appconfig-configuration/MyAppConfig/ParameterEnv", @@ -409,6 +436,83 @@ "version": "0.0.0" } }, + "MyHostedConfigFromYaml": { + "id": "MyHostedConfigFromYaml", + "path": "aws-appconfig-configuration/MyHostedConfigFromYaml", + "children": { + "ConfigurationProfile": { + "id": "ConfigurationProfile", + "path": "aws-appconfig-configuration/MyHostedConfigFromYaml/ConfigurationProfile", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AppConfig::ConfigurationProfile", + "aws:cdk:cloudformation:props": { + "applicationId": { + "Ref": "MyAppConfigB4B63E75" + }, + "locationUri": "hosted", + "name": "awsappconfigconfiguration-MyHostedConfigFromYaml-87E9786A" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_appconfig.CfnConfigurationProfile", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-appconfig-configuration/MyHostedConfigFromYaml/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AppConfig::HostedConfigurationVersion", + "aws:cdk:cloudformation:props": { + "applicationId": { + "Ref": "MyAppConfigB4B63E75" + }, + "configurationProfileId": { + "Ref": "MyHostedConfigFromYamlConfigurationProfile7C77A435" + }, + "content": "This is the configuration content", + "contentType": "application/x-yaml" + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_appconfig.CfnHostedConfigurationVersion", + "version": "0.0.0" + } + }, + "DeploymentFE962": { + "id": "DeploymentFE962", + "path": "aws-appconfig-configuration/MyHostedConfigFromYaml/DeploymentFE962", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::AppConfig::Deployment", + "aws:cdk:cloudformation:props": { + "applicationId": { + "Ref": "MyAppConfigB4B63E75" + }, + "configurationProfileId": { + "Ref": "MyHostedConfigFromYamlConfigurationProfile7C77A435" + }, + "configurationVersion": { + "Ref": "MyHostedConfigFromYaml13C5BE35" + }, + "deploymentStrategyId": { + "Ref": "MyDeployStrategy062CAEA2" + }, + "environmentId": { + "Ref": "MyAppConfigHostedEnvFromYaml82D3D1B2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_appconfig.CfnDeployment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-appconfig-alpha.HostedConfiguration", + "version": "0.0.0" + } + }, "MyValidatorFunction": { "id": "MyValidatorFunction", "path": "aws-appconfig-configuration/MyValidatorFunction", @@ -2554,13 +2658,13 @@ }, "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.69" + "version": "10.2.70" } } }, "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.69" + "version": "10.2.70" } }, "prod": { @@ -2743,13 +2847,13 @@ }, "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.69" + "version": "10.2.70" } } }, "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.69" + "version": "10.2.70" } } }, @@ -2860,7 +2964,7 @@ "path": "appconfig-configuration/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.69" + "version": "10.2.70" } }, "DeployAssert": { @@ -2906,7 +3010,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.2.69" + "version": "10.2.70" } } }, diff --git a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.ts b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.ts index ff28df311f576..bdab02a875d17 100644 --- a/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.ts +++ b/packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.ts @@ -70,6 +70,14 @@ new HostedConfiguration(stack, 'MyHostedConfigFromJson', { deploymentStrategy, }); +const hostedEnvFromYaml = appConfigApp.addEnvironment('HostedEnvFromYaml'); +new HostedConfiguration(stack, 'MyHostedConfigFromYaml', { + application: appConfigApp, + content: ConfigurationContent.fromInlineYaml('This is the configuration content'), + deployTo: [hostedEnvFromYaml], + deploymentStrategy, +}); + // ssm paramter as configuration source const func = new Function(stack, 'MyValidatorFunction', { runtime: Runtime.PYTHON_3_8,