Skip to content

Commit

Permalink
Merge pull request #652 from trade-tariff/hott-3622-deploy-tf
Browse files Browse the repository at this point in the history
HOTT-3622: Add CI config to deploy Terraform
  • Loading branch information
amberstarlight committed Jul 14, 2023
2 parents aa58b79 + c511a3b commit e1814fe
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 6 deletions.
135 changes: 131 additions & 4 deletions .circleci/config.yml
Expand Up @@ -3,6 +3,7 @@ version: 2.1

orbs:
aws-cli: circleci/aws-cli@2.0.3
terraform: circleci/terraform@3.2.1
cloudfoundry: circleci/cloudfoundry@1.0
cypress: cypress-io/cypress@1.27.0
node: circleci/node@5
Expand All @@ -11,6 +12,16 @@ orbs:
queue: eddiewebb/queue@1.6.4
tariff: trade-tariff/trade-tariff-ci-orb@0

executors:
terraform:
docker:
- image: hashicorp/terraform:1.4.6
resource_class: small
working_directory: "/tmp/terraform"
environment:
TF_INPUT: 0
TF_IN_AUTOMATION: 1

commands:
cf_deploy_docker:
parameters:
Expand Down Expand Up @@ -84,6 +95,71 @@ commands:
template: basic_success_1

jobs:
write_docker_tag:
parameters:
environment:
type: string
docker:
- image: cimg/base:stable
steps:
- checkout
- run: echo "docker_tag = \"$(git rev-parse --short HEAD)\"" >> terraform/config_<< parameters.environment >>.tfvars
- persist_to_workspace:
root: .
paths:
- terraform/

fmt_validate_terraform:
executor: terraform
parameters:
environment:
type: string
steps:
- checkout
- attach_workspace:
at: .
- terraform/init:
path: terraform/
backend_config_file: backends/<< parameters.environment >>.tfbackend
- terraform/fmt:
path: terraform/
- terraform/validate:
path: terraform/

plan_terraform:
executor: terraform
parameters:
environment:
type: string
steps:
- checkout
- attach_workspace:
at: .
- terraform/init:
path: terraform/
backend_config_file: backends/<< parameters.environment >>.tfbackend
- terraform/plan:
path: terraform/
backend_config_file: backends/<< parameters.environment >>.tfbackend
var_file: config_<< parameters.environment >>.tfvars

apply_terraform:
executor: terraform
parameters:
environment:
type: string
steps:
- checkout
- attach_workspace:
at: .
- terraform/init:
path: terraform/
backend_config_file: backends/<< parameters.environment >>.tfbackend
- terraform/apply:
path: terraform/
backend_config_file: backends/<< parameters.environment >>.tfbackend
var_file: config_<< parameters.environment >>.tfvars

checking:
docker:
- image: cimg/ruby:3.2.2-node
Expand Down Expand Up @@ -224,6 +300,9 @@ workflows:
version: 2
build_and_test:
jobs:
- write_docker_tag:
environment: development

- checking

- test:
Expand All @@ -233,8 +312,31 @@ workflows:
ignore:
- main

- fmt_validate_terraform:
context: trade-tariff-terraform-aws-development
environment: development
filters:
branches:
ignore:
- main
- /^dependabot/(?!docker/).*/
- /^hotfix\/.+/

- plan_terraform:
context: trade-tariff-terraform-aws-development
environment: development
requires:
- write_docker_tag
- fmt_validate_terraform
filters:
branches:
ignore:
- main
- /^dependabot/(?!docker/).*/
- /^hotfix\/.+/

- build:
name: build_dev
name: build_paas_development
context: trade-tariff
dev-build: true
filters:
Expand All @@ -246,6 +348,19 @@ workflows:
requires:
- test

- tariff/build-and-push:
name: build_and_push_dev
context: trade-tariff-terraform-aws-development
environment: development
image_name: tariff-duty-calculator
ssm_parameter: "/development/DUTY_CALCULATOR_ECR_URL"
filters:
branches:
ignore:
- main
- /^dependabot/(?!docker/).*/
- /^hotfix\/.+/

- deploy_dev:
context: trade-tariff
filters:
Expand All @@ -255,7 +370,19 @@ workflows:
- /^hotfix\/.+/
- /^dependabot/(?!docker/).*/
requires:
- build_dev
- build_paas_development

- apply_terraform:
context: trade-tariff-terraform-aws-development
environment: development
requires:
- plan_terraform
- build_and_push_dev
filters:
branches:
ignore:
- /^dependabot/(?!docker/).*/
- /^hotfix\/.+/

- tariff/smoketests:
name: smoketest_dev
Expand All @@ -271,7 +398,7 @@ workflows:
- /^hotfix\/.+/

- build:
name: build_live
name: build_paas_live
context: trade-tariff
filters:
branches:
Expand All @@ -287,7 +414,7 @@ workflows:
- main
- /^hotfix\/.+/
requires:
- build_live
- build_paas_live

- tariff/smoketests:
name: smoketest_staging
Expand Down
2 changes: 1 addition & 1 deletion terraform/README.md
Expand Up @@ -19,7 +19,7 @@ Terraform to deploy the service into AWS.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_service"></a> [service](#module\_service) | git@github.com:trade-tariff/trade-tariff-platform-terraform-modules.git//aws/ecs-service | aws/ecs-service-v1.6.0 |
| <a name="module_service"></a> [service](#module\_service) | git@github.com:trade-tariff/trade-tariff-platform-terraform-modules.git//aws/ecs-service | aws/ecs-service-v1.6.1 |

## Resources

Expand Down
2 changes: 1 addition & 1 deletion terraform/main.tf
@@ -1,5 +1,5 @@
module "service" {
source = "git@github.com:trade-tariff/trade-tariff-platform-terraform-modules.git//aws/ecs-service?ref=aws/ecs-service-v1.6.0"
source = "git@github.com:trade-tariff/trade-tariff-platform-terraform-modules.git//aws/ecs-service?ref=aws/ecs-service-v1.6.1"

environment = var.environment
region = var.region
Expand Down

0 comments on commit e1814fe

Please sign in to comment.