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

fix(acm): support Tokens for domainName in Certificate #4251

Merged
merged 2 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Construct, IResource, Resource } from '@aws-cdk/core';
import { Construct, IResource, Resource, Token } from '@aws-cdk/core';
import { CfnCertificate } from './certificatemanager.generated';
import { apexDomain } from './util';

Expand Down Expand Up @@ -103,11 +103,15 @@ export class Certificate extends Resource implements ICertificate {
* Closes over props.
*/
function domainValidationOption(domainName: string): CfnCertificate.DomainValidationOptionProperty {
const overrideDomain = props.validationDomains && props.validationDomains[domainName];
return {
domainName,
validationDomain: overrideDomain || apexDomain(domainName)
};
let validationDomain = props.validationDomains && props.validationDomains[domainName];
if (validationDomain === undefined) {
if (Token.isUnresolved(domainName)) {
throw new Error(`When using Tokens for domain names, 'validationDomains' needs to be supplied`);
}
validationDomain = apexDomain(domainName);
}

return { domainName, validationDomain };
}
}
}
Expand Down
39 changes: 37 additions & 2 deletions packages/@aws-cdk/aws-certificatemanager/test/test.certificate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { Stack } from '@aws-cdk/core';
import { Lazy, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { Certificate, ValidationMethod } from '../lib';

Expand Down Expand Up @@ -54,7 +54,7 @@ export = {
test.done();
},

'can configure validatin method'(test: Test) {
'can configure validation method'(test: Test) {
const stack = new Stack();

new Certificate(stack, 'Certificate', {
Expand All @@ -69,4 +69,39 @@ export = {

test.done();
},

'needs validation domain supplied if domain contains a token'(test: Test) {
const stack = new Stack();

test.throws(() => {
const domainName = Lazy.stringValue({ produce: () => 'example.com' });
new Certificate(stack, 'Certificate', {
domainName,
});
}, /'validationDomains' needs to be supplied/);

test.done();
},

'validationdomains can be given for a Token'(test: Test) {
const stack = new Stack();

const domainName = Lazy.stringValue({ produce: () => 'my.example.com' });
new Certificate(stack, 'Certificate', {
domainName,
validationDomains: {
[domainName]: 'example.com'
}
});

expect(stack).to(haveResource('AWS::CertificateManager::Certificate', {
DomainName: 'my.example.com',
DomainValidationOptions: [{
DomainName: 'my.example.com',
ValidationDomain: 'example.com'
}]
}));

test.done();
},
};