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

AV-2058: Add subdomain stack for beta environment #2069

Merged
merged 1 commit into from
Oct 5, 2023
Merged
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
6 changes: 6 additions & 0 deletions cdk/bin/opendata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {MonitoringStack} from "../lib/monitoring-stack";
import {LambdaStack} from "../lib/lambda-stack";
import {DomainStack} from "../lib/domain-stack";
import {CiTestStack} from "../lib/ci-test-stack";
import {SubDomainStack} from "../lib/sub-domain-stack";

// load .env file, shared with docker setup
// mainly for ECR repo and image tag information
Expand Down Expand Up @@ -694,6 +695,11 @@ const domainStackProd = new DomainStack(app, 'DomainStack-prod', {
crossAccountId: betaProps.account
})

const subDomainStackBeta = new SubDomainStack(app, 'SubDomainStack-beta', {
prodAccountId: prodProps.account,
subDomainName: betaProps.environment
})

const ciTestStackBeta = new CiTestStack(app, 'CiTestStack-beta', {
env: {
account: betaProps.account,
Expand Down
7 changes: 7 additions & 0 deletions cdk/lib/sub-domain-stack-props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {aws_route53, StackProps} from "aws-cdk-lib";
import {ApplicationLoadBalancer} from "aws-cdk-lib/aws-elasticloadbalancingv2";

export interface SubDomainStackProps extends StackProps {
prodAccountId: string;
subDomainName: string;
}
33 changes: 33 additions & 0 deletions cdk/lib/sub-domain-stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {aws_iam, aws_route53, aws_route53_targets, Stack} from "aws-cdk-lib";
import {Construct} from "constructs";
import {SubDomainStackProps} from "./sub-domain-stack-props";

export class SubDomainStack extends Stack {
readonly subZone: aws_route53.PublicHostedZone;
readonly newSubZone: aws_route53.PublicHostedZone;
constructor(scope: Construct, id: string, props: SubDomainStackProps) {
super(scope, id, props);

this.subZone = new aws_route53.PublicHostedZone(this, 'SubZone', {
zoneName: props.subDomainName + ".avoindata.suomi.fi"
})

const delegationRoleArn = Stack.of(this).formatArn({
region: '',
service: 'iam',
account: props.prodAccountId,
resource: 'role',
resourceName: 'Route53CrossDelegateRole'
})

const delegationRole = aws_iam.Role.fromRoleArn(this, 'delegationRole', delegationRoleArn)

new aws_route53.CrossAccountZoneDelegationRecord(this, 'delegate', {
delegatedZone: this.subZone,
delegationRole: delegationRole,
parentHostedZoneName: "avoindata.suomi.fi"
})

}

}
Loading