Skip to content

Commit

Permalink
feat(infra): parametrize environment
Browse files Browse the repository at this point in the history
  • Loading branch information
wolverian committed Sep 12, 2024
1 parent 638758d commit d877973
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
packages: write
id-token: write

env:
KITU_ENV: dev
ACCOUNT_ID: "682033502734"

steps:
- uses: actions/checkout@v4
- name: Build and push Docker image
Expand All @@ -28,11 +32,11 @@ jobs:
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- run: docker push ghcr.io/opetushallitus/koto-rekisteri:$GITHUB_SHA
if: github.ref_name == 'main'
- name: Log in to dev
- name: Log in to $KITU_ENV
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-1
role-to-assume: arn:aws:iam::682033502734:role/kitu-github-actions-role
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/kitu-github-actions-role
- name: Diff
if: github.ref_name != 'main'
run: |
Expand Down
42 changes: 31 additions & 11 deletions infra/bin/infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,45 @@ import { InfraStack } from "../lib/infra-stack";
// VPCs: 10.15.0.0/18, 10.15.64.0/18, 10.15.128.0/18, 10.15.192.0/18 (16382 addresses)
// Subnets: (let AWS calculate these for us)

const accounts = {
const environments = {
dev: {
account: "682033502734",
region: "eu-west-1",
},
network: {
cidrs: {
dev: "10.15.0.0/18",
network: {
cidr: "10.15.0.0/18",
maxAzs: 2,
},
maxAzs: {
dev: 2,
},
test: {
account: "682033502734",
region: "eu-west-1",
network: {
cidr: "10.15.64.0/18",
maxAzs: 3,
},
},
};

type EnvName = keyof typeof environments;

const app = new cdk.App();

const devStack = new InfraStack(app, "InfraStack", {
env: accounts.dev,
cidrBlock: accounts.network.cidrs.dev,
maxAzs: accounts.network.maxAzs.dev,
const envName = process.env.KITU_ENV;

if (envName === undefined) {
throw new Error("KITU_ENV required");
}

if (environments[envName as EnvName] === undefined) {
throw new Error(
`KITU_ENV invalid value ${envName}, expected one of ${Object.keys(environments).join(", ")}`,
);
}

const env = environments[envName as EnvName];

new InfraStack(app, "InfraStack", {
env,
cidrBlock: env.network.cidr,
maxAzs: env.network.maxAzs,
});

0 comments on commit d877973

Please sign in to comment.