Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
Use fromAttributes to lookup hosted zone
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunklas committed Nov 12, 2020
1 parent 27e07b8 commit d08bccc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: youyo/aws-cdk-github-actions@v1
with:
working_dir: 'gfa-iac'
cdk_subcommand: "deploy -c artifactsBucketName=${{ secrets.S3_ARTIFACT_BUCKET }} -c version=${{ steps.pull_request.outputs.number }} -c hostedZoneId=${{ secrets.HOSTED_ZONE_ID }} -c apiDomainName=${{ secrets.API_DOMAIN_NAME }}"
cdk_subcommand: "deploy -c artifactsBucketName=${{ secrets.S3_ARTIFACT_BUCKET }} -c version=${{ steps.pull_request.outputs.number }} -c hostedZoneId=${{ secrets.HOSTED_ZONE_ID }} -c domainName=${{ secrets.DOMAIN_NAME }}"
actions_comment: false

deploy-frontend:
Expand Down
4 changes: 2 additions & 2 deletions gfa-iac/bin/gfa-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const artifactsBucketName = app.node.tryGetContext('artifactsBucketName');
const version = app.node.tryGetContext('version');

const hostedZoneId = app.node.tryGetContext('hostedZoneId');
const apiDomainName = app.node.tryGetContext('apiDomainName');
const domainName = app.node.tryGetContext('domainName');

const gfaStack = new GbgFarligtAvfallStack(app, 'GbgFarligtAvfallStack', {
artifactsBucketName,
version,
hostedZoneId,
apiDomainName
domainName
});
15 changes: 10 additions & 5 deletions gfa-iac/lib/gfa-api-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface ApiStackProps extends NestedStackProps {
stopsBucket: IBucket,
stopsPath: string,
hostedZoneId?: string,
apiDomainName?: string,
domainName?: string,
}

export class ApiStack extends NestedStack {
Expand Down Expand Up @@ -46,20 +46,25 @@ export class ApiStack extends NestedStack {
const stopsResource = this.api.root.addResource('stops');
stopsResource.addMethod('GET', getStopsIntegration);

if (props.hostedZoneId && props.apiDomainName) {
if (props.hostedZoneId && props.domainName) {
const apiDomainName = `gfa-api.${props.domainName}`;
HostedZone.fromHostedZoneAttributes(this, 'e-hostedzone', {
hostedZoneId: props.hostedZoneId,
zoneName: props.domainName,
});
const hostedZone = HostedZone.fromHostedZoneId(this, 'external-hostedzone', props.hostedZoneId);
const apiCert = new Certificate(this, 'gfa-api-certificate', {
domainName: props.apiDomainName,
domainName: `gfa-api.${props.domainName}`,
validation: CertificateValidation.fromDns(hostedZone),
});
this.api.addDomainName('gfa-api-domain', {
domainName: props.apiDomainName,
domainName: apiDomainName,
certificate: apiCert,
});
new ARecord(this, 'gfa-api-domain-record', {
zone: hostedZone,
target: RecordTarget.fromAlias(new targets.ApiGateway(this.api)),
recordName: props.apiDomainName,
recordName: apiDomainName,
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions gfa-iac/lib/gfa-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface GbgFarligtAvfallStackProps extends StackProps {
artifactsBucketName: string,
version: string,
hostedZoneId: string,
apiDomainName: string,
domainName: string,
}

export class GbgFarligtAvfallStack extends Stack {
Expand Down Expand Up @@ -42,7 +42,7 @@ export class GbgFarligtAvfallStack extends Stack {
stopsBucket: stopsBucket,
stopsPath: stopsS3Path,
hostedZoneId: props.hostedZoneId,
apiDomainName: props.apiDomainName,
domainName: props.domainName,
});

new CfnOutput(this, 'WebBucket', {
Expand Down

0 comments on commit d08bccc

Please sign in to comment.