Skip to content

Commit

Permalink
feat(appconfig): add deploy method to configuration constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjane-dev committed Nov 28, 2023
1 parent c9c4e51 commit 5f1030b
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 25 deletions.
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-appconfig-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
});
```

If you want to deploy a configuration to an environment later and not on creation, you can call the `deploy` method on the configuration.

```ts
declare const application: appconfig.Application;
declare const env: appconfig.Environment;

const config = new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
application,
content: appconfig.ConfigurationContent.fromInlineText('This is my configuration content.'),
});

config.deploy(env);
```

### SourcedConfiguration

A sourced configuration represents configuration stored in an Amazon S3 bucket, AWS Secrets Manager secret, Systems Manager
Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,24 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
this.extensible.addExtension(extension);
}

/**
* Deploys the configuration to the specified environment.
*
* @param environment The environment to deploy the configuration to
*/
public deploy(environment: IEnvironment) {
const logicalId = `Deployment${this.getDeploymentHash(environment)}`;
new CfnDeployment(this, logicalId, {
applicationId: this.application.applicationId,
configurationProfileId: this.configurationProfileId,
deploymentStrategyId: this.deploymentStrategy!.deploymentStrategyId,
environmentId: environment.environmentId,
configurationVersion: this.versionNumber!,
description: this.description,
kmsKeyIdentifier: this.deploymentKey?.keyArn,
});
}

protected addExistingEnvironmentsToApplication() {
this.deployTo?.forEach((environment) => {
if (!this.application.environments.includes(environment)) {
Expand Down
39 changes: 39 additions & 0 deletions packages/@aws-cdk/aws-appconfig-alpha/test/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,45 @@ describe('configuration', () => {
Template.fromStack(stack).resourceCountIs('AWS::AppConfig::Deployment', 1);
});

test('configuration using deploy method', () => {
const stack = new cdk.Stack();
const app = new Application(stack, 'MyAppConfig', {
name: 'MyApplication',
});
app.addEnvironment('MyEnv1');
const env = app.addEnvironment('MyEnv2');
const config = new HostedConfiguration(stack, 'MyHostedConfig', {
content: ConfigurationContent.fromInlineText('This is my content'),
application: app,
deploymentStrategy: new DeploymentStrategy(stack, 'MyDeploymentStrategy', {
rolloutStrategy: RolloutStrategy.linear({
growthFactor: 15,
deploymentDuration: cdk.Duration.minutes(30),
}),
}),
});
config.deploy(env);

Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::Deployment', {
ApplicationId: {
Ref: 'MyAppConfigB4B63E75',
},
EnvironmentId: {
Ref: 'MyAppConfigMyEnv2350437D6',
},
ConfigurationVersion: {
Ref: 'MyHostedConfig51D3877D',
},
ConfigurationProfileId: {
Ref: 'MyHostedConfigConfigurationProfile2E1A2BBC',
},
DeploymentStrategyId: {
Ref: 'MyDeploymentStrategy60D31FB0',
},
});
Template.fromStack(stack).resourceCountIs('AWS::AppConfig::Deployment', 1);
});

test('configuration with two configurations specified', () => {
const stack = new cdk.Stack();
const app = new Application(stack, 'MyAppConfig', {
Expand Down
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
"Name": "awsappconfigconfiguration-MyAppConfig-HostedEnvFromYaml-BB2C802A"
}
},
"MyAppConfigEnvDeployLater26FA1032": {
"Type": "AWS::AppConfig::Environment",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"Name": "awsappconfigconfiguration-MyAppConfig-EnvDeployLater-91038922"
}
},
"MyAppConfigParameterEnvD769FB19": {
"Type": "AWS::AppConfig::Environment",
"Properties": {
Expand Down Expand Up @@ -184,6 +193,26 @@
}
}
},
"MyHostedConfigFromJsonDeploymentEFECDBC4087F1": {
"Type": "AWS::AppConfig::Deployment",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"ConfigurationProfileId": {
"Ref": "MyHostedConfigFromJsonConfigurationProfile863E1E42"
},
"ConfigurationVersion": {
"Ref": "MyHostedConfigFromJsonD8CF9BE4"
},
"DeploymentStrategyId": {
"Ref": "MyDeployStrategy062CAEA2"
},
"EnvironmentId": {
"Ref": "MyAppConfigEnvDeployLater26FA1032"
}
}
},
"MyHostedConfigFromYamlConfigurationProfile7C77A435": {
"Type": "AWS::AppConfig::ConfigurationProfile",
"Properties": {
Expand Down Expand Up @@ -565,7 +594,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "e2277687077a2abf9ae1af1cc9565e6715e2ebb62f79ec53aa75a1af9298f642.zip"
"S3Key": "3fb6287214999ddeafa7cd0e3e58bc5144c8678bb720f3b5e45e8fd32f333eb3.zip"
},
"Description": "/opt/awscli/aws"
}
Expand Down Expand Up @@ -736,7 +765,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "9eb41a5505d37607ac419321497a4f8c21cf0ee1f9b4a6b29aa04301aea5c7fd.zip"
"S3Key": "e976a796f036a5efbf44b99e44cfb5a961df08d8dbf7cd37e60bf216fb982a00.zip"
},
"Environment": {
"Variables": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5f1030b

Please sign in to comment.