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

Moved from PR provisioning to CodeBuild provisioning #41

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 0 additions & 10 deletions environment-templates/vpc-env/v1/infrastructure/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,4 @@ terraform {
# Configure the AWS Provider
provider "aws" {
region = var.aws_region
default_tags {
tags = {
proton:environment = var.environment.name
}
}
}

variable "aws_region" {
type = string
default = "us-east-1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

curl -Os https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip && \
curl -Os https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS && \
curl https://keybase.io/hashicorp/pgp_keys.asc | gpg --import && \
curl -Os https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS.sig && \
gpg --verify terraform_${TF_VERSION}_SHA256SUMS.sig terraform_${TF_VERSION}_SHA256SUMS && \
shasum -a 256 -c terraform_${TF_VERSION}_SHA256SUMS 2>&1 | grep "${TF_VERSION}_linux_amd64.zip:\sOK" && \
unzip -o terraform_${TF_VERSION}_linux_amd64.zip -d /usr/local/bin && \
terraform --version
44 changes: 41 additions & 3 deletions environment-templates/vpc-env/v1/infrastructure/manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
infrastructure:
templates:
- file: "*"
rendering_engine: hcl
template_language: terraform
- rendering_engine: codebuild
settings:
image: aws/codebuild/standard:6.0
runtimes:
golang: 1.18
env:
variables:
TF_VERSION: 1.3.4

provision:
# install terraform cli
- echo "Installing Terraform CLI ${TF_VERSION}"
- chmod +x ./install-terraform.sh && ./install-terraform.sh ${TF_VERSION}

# get user-named proton input
- export PROTON_ENV=$(cat proton-inputs.json | jq '.environment.name' -r)
- export VPC_REGION=$(cat proton-inputs.json | jq '.environment.inputs.aws_region' -r)
- export TF_STATE_BUCKET=$(cat proton-inputs.json | jq '.environment.inputs.tf_state_bucket' -r)
- export TF_STATE_BUCKET_REGION=$(cat proton-inputs.json | jq '.environment.inputs.tf_state_bucket_region' -r)

# provision, storing state in an s3 bucket using the proton environment.service.instance as the key
- terraform init -backend-config="bucket=${TF_STATE_BUCKET}" -backend-config="key=${PROTON_ENV}.tfstate" -backend-config="region=${TF_STATE_BUCKET_REGION}"
- terraform apply -var-file=proton-inputs.json -var="aws_region=${VPC_REGION}" -auto-approve

# pass terraform output to proton
- chmod +x ./output.sh && ./output.sh

deprovision:
# install terraform cli
- echo "Installing Terraform CLI ${TF_VERSION}"
- chmod +x ./install-terraform.sh && ./install-terraform.sh ${TF_VERSION}

# get user-named proton input
- export PROTON_ENV=$(cat proton-inputs.json | jq '.environment.name' -r)
- export VPC_REGION=$(cat proton-inputs.json | jq '.environment.inputs.aws_region' -r)
- export TF_STATE_BUCKET=$(cat proton-inputs.json | jq '.environment.inputs.tf_state_bucket' -r)
- export TF_STATE_BUCKET_REGION=$(cat proton-inputs.json | jq '.environment.inputs.tf_state_bucket_region' -r)

# destroy environment
- terraform init -backend-config="bucket=${TF_STATE_BUCKET}" -backend-config="key=${PROTON_ENV}.tfstate" -backend-config="aws_region=${TF_STATE_BUCKET_REGION}"
- terraform destroy -var-file=proton-inputs.json -var="aws_region=${VPC_REGION}" -auto-approve
4 changes: 4 additions & 0 deletions environment-templates/vpc-env/v1/infrastructure/output.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e
terraform output -json | jq 'to_entries | map({key:.key, valueString:.value.value})' > output.json
aws proton notify-resource-deployment-status-change --resource-arn ${RESOURCE_ARN} --status IN_PROGRESS --outputs file://./output.json
15 changes: 15 additions & 0 deletions environment-templates/vpc-env/v1/infrastructure/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "aws_region" {
description = "AWS region where resources will be provisioned"
type = string
default = "us-east-1"
}

# required by proton
variable "environment" {
description = "The Proton Environment"
type = object({
name = string
inputs = map(string)
})
default = null
}
15 changes: 15 additions & 0 deletions environment-templates/vpc-env/v1/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,18 @@ schema:
description: "The CIDR range for private subnet two"
default: 10.0.192.0/18
pattern: ([0-9]{1,3}\.){3}[0-9]{1,3}($|/(16|18|24))
aws_region:
title: AWS Region
type: string
description: AWS Region where resources will reside
default: us-east-1
tf_state_bucket:
title: Terraform state storage S3 bucket
type: string
description: S3 Bucket to store Terraform state
default: s3-bucket-name-here
tf_state_bucket_region:
title: State bucket AWS Region
type: string
description: AWS Region where state bucket resides
default: us-east-1