Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ses): add configurationSetArn property on configurationSet resource #29903

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/aws-cdk-lib/aws-ses/lib/configuration-set.ts
Expand Up @@ -15,6 +15,13 @@ export interface IConfigurationSet extends IResource {
* @attribute
*/
readonly configurationSetName: string;

/**
* The ARN of the configuration set
*
* @attribute
*/
readonly configurationSetArn: string;
Comment on lines +22 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @attribute might not be appropriate since it's derived from the resource ref, a maintainer should weigh in on this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case it helps, the exemple construct from the coding guideline uses @attribute for the ARN property even if it is computed manually (like in this case) :

  • exempleResourceArn is tagged with @attribute

/**
* The ARN of example resource.
* Equivalent to doing `{ 'Fn::GetAtt': ['LogicalId', 'Arn' ]}`
* in CloudFormation if the underlying CloudFormation resource
* surfaces the ARN as a return value -
* if not, we usually construct the ARN "by hand" in the construct,
* using the Fn::Join function.
*
* It needs to be annotated with '@attribute' if the underlying CloudFormation resource
* surfaces the ARN as a return value.
*
* @attribute
*/
readonly exampleResourceArn: string;

  • exempleResourceArn is constructed manually in from static methods and constructor
    public readonly exampleResourceName = exampleResourceName;
    // Since we have the name, we have to generate the ARN,
    // using the Stack.formatArn helper method from the core library.
    // We have to know the ARN components of ExampleResource in a few places, so,
    // to avoid duplication, extract that into a module-private function
    public readonly exampleResourceArn = core.Stack.of(scope)
    .formatArn(exampleResourceArnComponents(exampleResourceName));

The only doubt I have is regarding this precision : It needs to be annotated with '@attribute' if the underlying CloudFormation resource surfaces the ARN as a return value.
CloudFormation does not surface AWS::SES::ConfigurationSet ARN.

}

/**
Expand Down Expand Up @@ -111,15 +118,27 @@ export enum SuppressionReasons {
COMPLAINTS_ONLY = 'COMPLAINTS_ONLY',
}

abstract class ConfigurationSetBase extends Resource implements IConfigurationSet {
public abstract configurationSetName: string;

public get configurationSetArn(): string {
return this.stack.formatArn({
service: 'ses',
resource: 'configuration-set',
resourceName: this.configurationSetName,
});
}
}

/**
* A configuration set
*/
export class ConfigurationSet extends Resource implements IConfigurationSet {
export class ConfigurationSet extends ConfigurationSetBase {
/**
* Use an existing configuration set
*/
public static fromConfigurationSetName(scope: Construct, id: string, configurationSetName: string): IConfigurationSet {
class Import extends Resource implements IConfigurationSet {
class Import extends ConfigurationSetBase {
public readonly configurationSetName = configurationSetName;
}
return new Import(scope, id);
Expand Down
35 changes: 35 additions & 0 deletions packages/aws-cdk-lib/aws-ses/test/configuration-set.test.ts
Expand Up @@ -40,3 +40,38 @@ test('configuration set with options', () => {
},
});
});

test('renders the correct ARN for owned ConfigurationSet', () => {
const configurationSet = new ConfigurationSet(stack, 'ConfigurationSet');
const arn = stack.resolve(configurationSet.configurationSetArn);
expect(arn).toEqual({
'Fn::Join': ['', [
'arn:',
{ Ref: 'AWS::Partition' },
':ses:',
{ Ref: 'AWS::Region' },
':',
{ Ref: 'AWS::AccountId' },
':configuration-set/',
{
Ref: 'ConfigurationSet3DD38186',
},
]],
});
});

test('renders the correct ARN for unowned ConfigurationSet', () => {
const unownedConfigurationSet = ConfigurationSet.fromConfigurationSetName(stack, 'ConfigurationSet', 'my-imported-configuration-set');
const arn = stack.resolve(unownedConfigurationSet.configurationSetArn);
expect(arn).toEqual({
'Fn::Join': ['', [
'arn:',
{ Ref: 'AWS::Partition' },
':ses:',
{ Ref: 'AWS::Region' },
':',
{ Ref: 'AWS::AccountId' },
':configuration-set/my-imported-configuration-set',
]],
});
});