Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
refactor: use name instead of id for stacks
Browse files Browse the repository at this point in the history
BREAKING CHANGE: this changes APIs and environment variables

How to migrate:

- replace `STACK_ID` with `STACK_NAME` in your environment
  variable definitions
  • Loading branch information
coderbyheart committed Oct 7, 2020
1 parent 7cc656d commit 866d26f
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Generate Stack ID
run: |
RANDOM_STRING=`node -e "const crypto = require('crypto'); process.stdout.write(crypto.randomBytes(Math.ceil(8 * 0.5)).toString('hex').slice(0, 8));"`
echo "::set-env name=STACK_ID::bifravst-${{ runner.OS }}-${RANDOM_STRING}"
echo "::set-env name=STACK_NAME::bifravst-${{ runner.OS }}-${RANDOM_STRING}"
- name: Set up stack for End-to-End tests
run: |
npx cdk -a 'node --unhandled-rejections=strict dist/cdk/cloudformation-sourcecode.js' deploy
Expand All @@ -90,7 +90,7 @@ jobs:
node cli purge-buckets
npx cdk -a 'node --unhandled-rejections=strict dist/cdk/cloudformation-test.js' destroy -f '*'
# Delete sourcecode bucket
SOURCE_CODE_BUCKET=`aws cloudformation describe-stacks --stack-name $STACK_ID-sourcecode | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "bucketName") | .OutputValue'`
SOURCE_CODE_BUCKET=`aws cloudformation describe-stacks --stack-name $STACK_NAME-sourcecode | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "bucketName") | .OutputValue'`
aws s3 rb s3://$SOURCE_CODE_BUCKET --force
# Delete the sourceode stack
npx cdk -a 'node --unhandled-rejections=strict dist/cdk/cloudformation-sourcecode.js' destroy -f '*'
Expand Down
2 changes: 1 addition & 1 deletion cdk/helper/getLambdaSourceCodeBucketName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CloudFormation } from 'aws-sdk'
import { SOURCECODE_STACK_NAME } from '../stacks/stackId'
import { SOURCECODE_STACK_NAME } from '../stacks/stackName'

const cf = new CloudFormation({
region: process.env.AWS_DEFAULT_REGION,
Expand Down
4 changes: 2 additions & 2 deletions cdk/resources/WebAppCD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as CodeBuild from '@aws-cdk/aws-codebuild'
import * as CodePipeline from '@aws-cdk/aws-codepipeline'
import * as S3 from '@aws-cdk/aws-s3'
import * as SSM from '@aws-cdk/aws-ssm'
import { CORE_STACK_NAME } from '../stacks/stackId'
import { CORE_STACK_NAME } from '../stacks/stackName'

export const BuildActionCodeBuild = {
category: 'Build',
Expand Down Expand Up @@ -75,7 +75,7 @@ export class WebAppCD extends CloudFormation.Construct {
image: 'aws/codebuild/standard:3.0',
environmentVariables: [
{
name: 'STACK_ID',
name: 'STACK_NAME',
value: CORE_STACK_NAME,
},
{
Expand Down
2 changes: 1 addition & 1 deletion cdk/stacks/Bifravst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CellGeolocation } from '../resources/CellGeolocation'
import { CellGeolocationApi } from '../resources/CellGeolocationApi'
import { ThingGroupLambda } from '../resources/ThingGroupLambda'
import { ThingGroup } from '../resources/ThingGroup'
import { CORE_STACK_NAME } from './stackId'
import { CORE_STACK_NAME } from './stackName'
import { LambdasWithLayer } from '../resources/LambdasWithLayer'
import { lambdasOnS3 } from '../resources/lambdasOnS3'

Expand Down
2 changes: 1 addition & 1 deletion cdk/stacks/ContinuousDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as CodePipeline from '@aws-cdk/aws-codepipeline'
import * as SSM from '@aws-cdk/aws-ssm'
import * as S3 from '@aws-cdk/aws-s3'
import { BuildActionCodeBuild, WebAppCD } from '../resources/WebAppCD'
import { CONTINUOUS_DEPLOYMENT_STACK_NAME } from './stackId'
import { CONTINUOUS_DEPLOYMENT_STACK_NAME } from './stackName'

/**
* This is the CloudFormation stack sets up the continuous deployment of the project.
Expand Down
2 changes: 1 addition & 1 deletion cdk/stacks/FirmwareCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as S3 from '@aws-cdk/aws-s3'
import { FirmwareCI } from '../resources/FirmwareCI'
import { ThingGroupLambda } from '../resources/ThingGroupLambda'
import { CDKLambdas, PackedLambdas } from '../prepare-resources'
import { FIRMWARE_CI_STACK_NAME } from './stackId'
import { FIRMWARE_CI_STACK_NAME } from './stackName'
import { lambdasOnS3 } from '../resources/lambdasOnS3'

export class FirmwareCIStack extends CloudFormation.Stack {
Expand Down
2 changes: 1 addition & 1 deletion cdk/stacks/LambdaSourceCodeStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App, CfnOutput, RemovalPolicy, Stack } from '@aws-cdk/core'
import { Bucket } from '@aws-cdk/aws-s3'
import { SOURCECODE_STACK_NAME } from './stackId'
import { SOURCECODE_STACK_NAME } from './stackName'

/**
* This stack provides a bucket to store the source code for the lambda functions
Expand Down
2 changes: 1 addition & 1 deletion cdk/stacks/WebApps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as CloudFormation from '@aws-cdk/core'
import { WebAppHosting } from '../resources/WebAppHosting'
import { WEBAPPS_STACK_NAME } from './stackId'
import { WEBAPPS_STACK_NAME } from './stackName'

export class WebAppsStack extends CloudFormation.Stack {
public constructor(parent: CloudFormation.App) {
Expand Down
6 changes: 0 additions & 6 deletions cdk/stacks/stackId.ts

This file was deleted.

6 changes: 6 additions & 0 deletions cdk/stacks/stackName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const STACK_NAME = process.env.STACK_NAME ?? 'bifravst'
export const CORE_STACK_NAME = STACK_NAME
export const WEBAPPS_STACK_NAME = `${STACK_NAME}-webapps`
export const SOURCECODE_STACK_NAME = `${STACK_NAME}-sourcecode`
export const CONTINUOUS_DEPLOYMENT_STACK_NAME = `${STACK_NAME}-continuous-deployment`
export const FIRMWARE_CI_STACK_NAME = `${STACK_NAME}-firmware-ci`
2 changes: 1 addition & 1 deletion cli/commands/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { stackOutput } from '@bifravst/cloudformation-helpers'
import { CloudFormation } from 'aws-sdk'
import { region } from '../../cdk/regions'
import * as chalk from 'chalk'
import { WEBAPPS_STACK_NAME } from '../../cdk/stacks/stackId'
import { WEBAPPS_STACK_NAME } from '../../cdk/stacks/stackName'

export const connectCommand = ({
endpoint,
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/firmware-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CommandDefinition } from './CommandDefinition'
import * as chalk from 'chalk'
import { region } from '../../cdk/regions'
import { StackOutputs as FirmwareCIStackOutputs } from '../../cdk/stacks/FirmwareCI'
import { FIRMWARE_CI_STACK_NAME } from '../../cdk/stacks/stackId'
import { FIRMWARE_CI_STACK_NAME } from '../../cdk/stacks/stackName'
import { stackOutput } from '@bifravst/cloudformation-helpers'
import { createDevice } from '../firmware-ci/createDevice'
import { deviceFileLocations } from '../jitp/deviceFileLocations'
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/historical-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { deviceMessagesFields } from '../../historicalData/deviceMessages'
import { region } from '../../cdk/regions'
import { stackOutput } from '@bifravst/cloudformation-helpers'
import { StackOutputs } from '../../cdk/stacks/Bifravst'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackId'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

export const historicalDataCommand = (): CommandDefinition => ({
command: 'historical-data',
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { stackOutput } from '@bifravst/cloudformation-helpers'
import * as chalk from 'chalk'
import { CloudFormation } from 'aws-sdk'
import { region } from '../../cdk/regions'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackId'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

export const infoCommand = (): CommandDefinition => ({
command: 'info',
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloudFormation, CloudWatchLogs } from 'aws-sdk'
import { CommandDefinition } from './CommandDefinition'
import * as chalk from 'chalk'
import { region } from '../../cdk/regions'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackId'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

export const logsCommand = (): CommandDefinition => ({
command: 'logs',
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/purge-buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { S3, CloudFormation } from 'aws-sdk'
import * as chalk from 'chalk'
import { retry } from './retry'
import { region } from '../../cdk/regions'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackId'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

export const purgeBucketsCommand = (): CommandDefinition => ({
command: 'purge-buckets',
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/purge-cas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Iot, CloudFormation } from 'aws-sdk'
import { paginate } from '../../util/paginate'
import { stackOutput } from '@bifravst/cloudformation-helpers'
import { region } from '../../cdk/regions'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackId'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

const purgeCACertificate = ({
iot,
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/purge-iot-user-policy-principals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { stackOutput } from '@bifravst/cloudformation-helpers'
import { Iot, CloudFormation } from 'aws-sdk'
import { paginate } from '../../util/paginate'
import { region } from '../../cdk/regions'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackId'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

export const purgeIotUserPolicyPrincipals = (): CommandDefinition => ({
command: 'purge-iot-user-policy-principals',
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/react-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../../historicalData/settings'
import { stackOutput, objectToEnv } from '@bifravst/cloudformation-helpers'
import { CloudFormation } from 'aws-sdk'
import { CORE_STACK_NAME, WEBAPPS_STACK_NAME } from '../../cdk/stacks/stackId'
import { CORE_STACK_NAME, WEBAPPS_STACK_NAME } from '../../cdk/stacks/stackName'
import { region } from '../../cdk/regions'

export const reactConfigCommand = (): CommandDefinition => ({
Expand Down
2 changes: 1 addition & 1 deletion cli/jitp/createCA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { caFileLocations } from './caFileLocations'
import { run } from '../process/run'
import { toObject } from '@bifravst/cloudformation-helpers'
import { region } from '../../cdk/regions'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackId'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

/**
* Creates a CA certificate and registers it for Just-in-time provisioning
Expand Down
5 changes: 4 additions & 1 deletion feature-runner/run-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import { uuidHelper } from './steps/uuidHelper'
import { STS, CloudFormation } from 'aws-sdk'
import { v4 } from 'uuid'
import { region } from '../cdk/regions'
import { CORE_STACK_NAME, FIRMWARE_CI_STACK_NAME } from '../cdk/stacks/stackId'
import {
CORE_STACK_NAME,
FIRMWARE_CI_STACK_NAME,
} from '../cdk/stacks/stackName'
import { promises as fs } from 'fs'
import * as path from 'path'
import { firmwareCIStepRunners } from './steps/firmwareCI'
Expand Down
2 changes: 1 addition & 1 deletion historicalData/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CORE_STACK_NAME } from '../cdk/stacks/stackId'
import { CORE_STACK_NAME } from '../cdk/stacks/stackName'

export const DataBaseName = (): string =>
`${CORE_STACK_NAME.replace(/-/g, '_')}_historicaldata`
Expand Down

0 comments on commit 866d26f

Please sign in to comment.