-
Notifications
You must be signed in to change notification settings - Fork 1
feat: acm certificate v2 component #91
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
12bd0dd
Create acm certificate v2 component
bornast b8b8d94
Implement acm certificate tests
bornast 431039c
Add legacy prefix to certificate v1 component
bornast 1c98b9e
Add acm certificate namespace for types
bornast 06184a8
Remove legacy prefix from v1 certificate component
bornast 50ff252
Rename test assertions
bornast 5082c38
Fallback to hosted zone id arg if zone is not found by domain name
bornast 46ca7e8
Fix get zone method args
bornast 359a94b
Add ICB prefix to env variables
bornast e56724e
Export certificate using esmodule syntax
bornast fbf61a3
Merge branch 'master' into task/certificate-v2-component
bornast 18fa3b6
Move setup to the top-level to prevent false positives
bornast e6e8fcf
Merge branch 'master' into task/certificate-v2-component
bornast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import * as pulumi from '@pulumi/pulumi'; | ||
| import * as aws from '@pulumi/aws'; | ||
| import { commonTags } from '../../../constants'; | ||
|
|
||
| export type AcmCertificateArgs = { | ||
bornast marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| domain: pulumi.Input<string>; | ||
| hostedZoneId: pulumi.Input<string>; | ||
| }; | ||
|
|
||
| export class AcmCertificate extends pulumi.ComponentResource { | ||
| certificate: aws.acm.Certificate; | ||
|
|
||
| constructor( | ||
| name: string, | ||
| args: AcmCertificateArgs, | ||
| opts: pulumi.ComponentResourceOptions = {}, | ||
| ) { | ||
| super('studion:acm:Certificate', name, {}, opts); | ||
|
|
||
| this.certificate = new aws.acm.Certificate( | ||
| `${args.domain}-certificate`, | ||
| { domainName: args.domain, validationMethod: 'DNS', tags: commonTags }, | ||
| { parent: this }, | ||
| ); | ||
|
|
||
| const certificateValidationDomain = new aws.route53.Record( | ||
| `${args.domain}-cert-validation-domain`, | ||
| { | ||
| name: this.certificate.domainValidationOptions[0].resourceRecordName, | ||
| type: this.certificate.domainValidationOptions[0].resourceRecordType, | ||
| zoneId: args.hostedZoneId, | ||
| records: [ | ||
| this.certificate.domainValidationOptions[0].resourceRecordValue, | ||
| ], | ||
| ttl: 600, | ||
| }, | ||
| { | ||
| parent: this, | ||
| deleteBeforeReplace: true, | ||
| }, | ||
| ); | ||
|
|
||
| const certificateValidation = new aws.acm.CertificateValidation( | ||
| `${args.domain}-cert-validation`, | ||
| { | ||
| certificateArn: this.certificate.arn, | ||
| validationRecordFqdns: [certificateValidationDomain.fqdn], | ||
| }, | ||
| { parent: this }, | ||
| ); | ||
|
|
||
| this.registerOutputs(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import * as assert from 'node:assert'; | ||
| import * as automation from '../automation'; | ||
| import { InlineProgramArgs } from '@pulumi/pulumi/automation'; | ||
| import { ACMClient } from '@aws-sdk/client-acm'; | ||
| import { Route53Client } from '@aws-sdk/client-route-53'; | ||
| import { backOff } from 'exponential-backoff'; | ||
| import { | ||
| DescribeCertificateCommand, | ||
| CertificateType, | ||
| } from '@aws-sdk/client-acm'; | ||
| import { ListResourceRecordSetsCommand } from '@aws-sdk/client-route-53'; | ||
| import { AcmCertificateTestContext } from './test-context'; | ||
| import { describe, it, before, after } from 'node:test'; | ||
|
|
||
| const programArgs: InlineProgramArgs = { | ||
| stackName: 'dev', | ||
| projectName: 'icb-test-acm-certificate', | ||
| program: () => import('./infrastructure'), | ||
| }; | ||
|
|
||
| describe('ACM Certificate component deployment', () => { | ||
| const region = process.env.AWS_REGION; | ||
| const domainName = process.env.DOMAIN_NAME; | ||
| const hostedZoneName = process.env.HOSTED_ZONE_NAME; | ||
| if (!region || !domainName || !hostedZoneName) { | ||
| throw new Error( | ||
| 'AWS_REGION, DOMAIN_NAME and HOSTED_ZONE_NAME environment variables are required', | ||
| ); | ||
| } | ||
|
|
||
| const ctx: AcmCertificateTestContext = { | ||
| outputs: {}, | ||
| config: { | ||
| certificateName: 'acm-cert-test-cert', | ||
| exponentialBackOffConfig: { | ||
| delayFirstAttempt: true, | ||
| numOfAttempts: 5, | ||
| startingDelay: 2000, | ||
| timeMultiple: 1.5, | ||
| jitter: 'full', | ||
| }, | ||
| }, | ||
| clients: { | ||
| acm: new ACMClient({ region }), | ||
| route53: new Route53Client({ region }), | ||
| }, | ||
| }; | ||
|
|
||
| before(async () => { | ||
| ctx.outputs = await automation.deploy(programArgs); | ||
| }); | ||
|
|
||
| after(() => automation.destroy(programArgs)); | ||
|
|
||
| it('should create certificate with correct domain name', async () => { | ||
| const certificate = ctx.outputs.certificate.value; | ||
| assert.ok(certificate.certificate, 'Should have certificate property'); | ||
| assert.ok(certificate.certificate.arn, 'Certificate should have ARN'); | ||
|
|
||
| return backOff(async () => { | ||
| const certResult = await ctx.clients.acm.send( | ||
| new DescribeCertificateCommand({ | ||
| CertificateArn: certificate.certificate.arn, | ||
| }), | ||
| ); | ||
|
|
||
| const cert = certResult.Certificate; | ||
| assert.ok(cert, 'Certificate should exist'); | ||
| assert.strictEqual( | ||
| cert.DomainName, | ||
| domainName, | ||
| 'Certificate domain should match', | ||
| ); | ||
| assert.strictEqual( | ||
| cert.Type, | ||
| CertificateType.AMAZON_ISSUED, | ||
| 'Should be Amazon issued certificate', | ||
| ); | ||
| }, ctx.config.exponentialBackOffConfig); | ||
| }); | ||
|
|
||
| it('should have validation record with correct resource record value', async () => { | ||
| const certificate = ctx.outputs.certificate.value; | ||
| const hostedZone = ctx.outputs.hostedZone.value; | ||
|
|
||
| const certResult = await ctx.clients.acm.send( | ||
| new DescribeCertificateCommand({ | ||
| CertificateArn: certificate.certificate.arn, | ||
| }), | ||
| ); | ||
|
|
||
| const domainValidation = | ||
| certResult.Certificate?.DomainValidationOptions?.[0]; | ||
| assert.ok(domainValidation, 'Should have domain validation options'); | ||
| assert.ok( | ||
| domainValidation.ResourceRecord, | ||
| 'Should have resource record for validation', | ||
bornast marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| const recordsResult = await ctx.clients.route53.send( | ||
| new ListResourceRecordSetsCommand({ | ||
| HostedZoneId: hostedZone.zoneId, | ||
| }), | ||
| ); | ||
|
|
||
| const records = recordsResult.ResourceRecordSets || []; | ||
| const validationRecord = records.find( | ||
| record => record.Name === domainValidation.ResourceRecord?.Name, | ||
| ); | ||
|
|
||
| assert.ok( | ||
| validationRecord, | ||
| 'Validation record should exist with correct name', | ||
bornast marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| assert.strictEqual( | ||
| validationRecord.TTL, | ||
| 600, | ||
| 'Validation record should have 600 TTL', | ||
| ); | ||
| assert.strictEqual( | ||
| validationRecord.ResourceRecords?.[0]?.Value, | ||
| domainValidation.ResourceRecord?.Value, | ||
| 'Validation record should have correct value', | ||
| ); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { next as studion } from '@studion/infra-code-blocks'; | ||
| import * as aws from '@pulumi/aws'; | ||
|
|
||
| const appName = 'acm-certificate-test'; | ||
|
|
||
| const hostedZone = aws.route53.getZoneOutput({ | ||
| name: process.env.HOSTED_ZONE_NAME, | ||
| privateZone: false, | ||
| }); | ||
bornast marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const certificate = new studion.AcmCertificate(`${appName}-certificate`, { | ||
| domain: process.env.DOMAIN_NAME!, | ||
| hostedZoneId: hostedZone.zoneId, | ||
| }); | ||
|
|
||
| module.exports = { | ||
bornast marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| certificate, | ||
| hostedZone, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { OutputMap } from '@pulumi/pulumi/automation'; | ||
| import { ACMClient } from '@aws-sdk/client-acm'; | ||
| import { Route53Client } from '@aws-sdk/client-route-53'; | ||
|
|
||
| interface AcmCertificateTestConfig { | ||
| certificateName: string; | ||
| exponentialBackOffConfig: { | ||
| delayFirstAttempt: boolean; | ||
| numOfAttempts: number; | ||
| startingDelay: number; | ||
| timeMultiple: number; | ||
| jitter: 'full' | 'none'; | ||
| }; | ||
| } | ||
|
|
||
| interface ConfigContext { | ||
| config: AcmCertificateTestConfig; | ||
| } | ||
|
|
||
| interface PulumiProgramContext { | ||
| outputs: OutputMap; | ||
| } | ||
|
|
||
| interface AwsContext { | ||
| clients: { | ||
| acm: ACMClient; | ||
| route53: Route53Client; | ||
| }; | ||
| } | ||
|
|
||
| export interface AcmCertificateTestContext | ||
| extends ConfigContext, | ||
| PulumiProgramContext, | ||
| AwsContext {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.