Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/aws-cdk-lib/aws-appconfig/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ export interface ConfigurationOptions {
*/
readonly type?: ConfigurationType;

/**
* The type of configuration as a string. Use this to specify custom configuration types
* that are not available in the ConfigurationType enum.
*
* This property takes precedence over the 'type' property if both are specified.
*
* @default - Uses the 'type' property value
*/
readonly typeAsString?: string;

/**
* The list of environments to deploy the configuration to.
*
Expand Down Expand Up @@ -136,6 +146,11 @@ export interface IConfiguration extends IConstruct {
*/
readonly type?: ConfigurationType;

/**
* The configuration type as a string.
*/
readonly typeAsString?: string;

/**
* The environments to deploy to.
*/
Expand Down Expand Up @@ -186,6 +201,11 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
*/
public readonly type?: ConfigurationType;

/**
* The configuration type as a string.
*/
public readonly typeAsString?: string;

/**
* The deployment key for the configuration.
*/
Expand All @@ -210,6 +230,7 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
this.application = props.application;
this.applicationId = this.application.applicationId;
this.type = props.type;
this.typeAsString = props.typeAsString;
this.validators = props.validators;
this.description = props.description;
this.deployTo = props.deployTo;
Expand Down Expand Up @@ -349,6 +370,13 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
environment.addDeployment(this);
});
}

/**
* Gets the effective configuration type, with typeAsString taking precedence over type.
*/
protected effectiveType(): string | undefined {
return this.typeAsString || this.type;
}
}

/**
Expand Down Expand Up @@ -469,7 +497,7 @@ export class HostedConfiguration extends ConfigurationBase {
locationUri: 'hosted',
name: this.name!,
description: this.description,
type: this.type,
type: this.effectiveType(),
validators: this.validators,
deletionProtectionCheck: this.deletionProtectionCheck,
kmsKeyIdentifier: props.kmsKey?.keyRef.keyArn,
Expand Down Expand Up @@ -609,7 +637,7 @@ export class SourcedConfiguration extends ConfigurationBase {
name: this.name!,
description: this.description,
retrievalRoleArn: this.retrievalRole?.roleArn,
type: this.type,
type: this.effectiveType(),
validators: this.validators,
deletionProtectionCheck: this.deletionProtectionCheck,
});
Expand Down
52 changes: 52 additions & 0 deletions packages/aws-cdk-lib/aws-appconfig/test/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,58 @@ describe('configuration', () => {
Template.fromStack(stack).resourceCountIs('AWS::AppConfig::Deployment', 0);
});

test('configuration profile with typeAsString feature flags', () => {
const stack = new cdk.Stack();
const app = new Application(stack, 'MyAppConfig');
new HostedConfiguration(stack, 'MyConfigurationProfile', {
name: 'TestConfigProfile',
application: app,
typeAsString: 'AWS.AppConfig.FeatureFlags',
content: ConfigurationContent.fromInlineText('This is my content'),
});

Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', {
Name: 'TestConfigProfile',
Type: 'AWS.AppConfig.FeatureFlags',
LocationUri: 'hosted',
});
});

test('configuration profile with typeAsString freeform', () => {
const stack = new cdk.Stack();
const app = new Application(stack, 'MyAppConfig');
new HostedConfiguration(stack, 'MyConfigurationProfile', {
name: 'TestConfigProfile',
application: app,
typeAsString: 'AWS.Freeform',
content: ConfigurationContent.fromInlineText('This is my content'),
});

Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', {
Name: 'TestConfigProfile',
Type: 'AWS.Freeform',
LocationUri: 'hosted',
});
});

test('configuration profile typeAsString takes precedence over type', () => {
const stack = new cdk.Stack();
const app = new Application(stack, 'MyAppConfig');
new HostedConfiguration(stack, 'MyConfigurationProfile', {
name: 'TestConfigProfile',
application: app,
type: ConfigurationType.FEATURE_FLAGS,
typeAsString: 'AWS.Freeform',
content: ConfigurationContent.fromInlineText('This is my content'),
});

Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', {
Name: 'TestConfigProfile',
Type: 'AWS.Freeform',
LocationUri: 'hosted',
});
});

test('configuration profile with description', () => {
const stack = new cdk.Stack();
const app = new Application(stack, 'MyAppConfig');
Expand Down
Loading