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

Add basic secrets processing for GitHub integration #246

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 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
19 changes: 19 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,22 @@ jobs:
run: |
echo Pubber output logs:
cat pubber.out || true

terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/[email protected]
- name: Setup config
env:
TERRAFORM_CONFIG: ${{ secrets.TERRAFORM_CONFIG }}
if: "${{ env.TERRAFORM_CONFIG != '' }}"
run: |
base64 -d <<< "$TERRAFORM_CONFIG" > config.sh
cat config.sh | fgrep -v _CREDS=
- name: Setup terraform
run: (! test -f config.sh) || (source config.sh; cloud/gcp/bin/setup)
- name: Init terraform
run: (! test -f config.sh) || (source config.sh; cloud/gcp/bin/init)
- name: Apply terraform
run: (! test -f config.sh) || (source config.sh; cloud/gcp/bin/apply)
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ cloud/gcp/terraform.tfvars
cloud/gcp/udmi-sites.tf
cloud/gcp/main.tf
cloud/gcp/auth/credentials.json
cloud/gcp/.terraform*
cloud/gcp/.terraform/
cloud/gcp/.terraform.lock.hcl
cloud/gcp/config.out
7 changes: 7 additions & 0 deletions cloud/gcp/bin/apply
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -ex

cd $(realpath $(dirname $0)/..)

echo Applying terraform to project ${GCP_PROJECT_NAME}

terraform apply
5 changes: 5 additions & 0 deletions cloud/gcp/bin/clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e

echo Cleaning existing state...

terraform state rm `terraform state list`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The terraform state is kept in the remote backend bucket, it must not be erased

18 changes: 18 additions & 0 deletions cloud/gcp/bin/init
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -ex

cd $(realpath $(dirname $0)/..)

echo Initializing terraform for project ${GCP_PROJECT_NAME}

for file in main.tf udmi-sites.tf terraform.tfvars; do
if [[ ! -f $file ]]; then
echo Configuration file $file does not exist, did you run bin/setup?
false
fi
done

terraform init $*

terraform import google_project.udmi-project ${GCP_PROJECT_NAME:?}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be removed because the state already includes the project


terraform import google_storage_bucket.tf-bucket ${GCP_PROJECT_NAME}-terraform
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be removed because the state already includes the storage bucket

47 changes: 47 additions & 0 deletions cloud/gcp/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash -e

cd $(realpath $(dirname $0)/..)

CRED_FILE=auth/credentials.json
CONFIG_FILE=config.out

if [[ -f $CRED_FILE ]]; then
echo Cowardly refusing to overwrite existing $CRED_FILE
else
echo Writing creds to $CRED_FILE
base64 -d <<< "${GCP_PROJECT_CREDS:?}" > $CRED_FILE
fi

cat <<EOF > $CONFIG_FILE
export GCP_PROJECT_NAME=${GCP_PROJECT_NAME:?}
export GCP_PROJECT_ID=${GCP_PROJECT_ID:?}
export GCP_PROJECT_REGION=${GCP_PROJECT_REGION:?}
export GCP_PROJECT_GROUP=${GCP_PROJECT_GROUP:?}
export GCP_PROJECT_CREDS="`base64 -w 0 $CRED_FILE`"
export UDMI_SITE_NAME=${UDMI_SITE_NAME:?}
export UDMI_SITE_REGION=${UDMI_SITE_REGION:?}
export UDMI_SITE_GROUP=${UDMI_SITE_GROUP:?}
EOF

echo Config saved to $CONFIG_FILE
sha256sum $CONFIG_FILE $CRED_FILE
cat $CONFIG_FILE | fgrep -v _CREDS=

echo Creating main.tf
sed -E < main.tf.template > main.tf \
-e "s/@GCP_PROJECT_ID@/${GCP_PROJECT_ID}/"

echo Creating udmi-sites.tf
sed -E < udmi-sites.tf.template > udmi-sites.tf \
-e "s/@UDMI_SITE_NAME@/${UDMI_SITE_NAME}/" \
-e "s/@UDMI_SITE_REGION@/${UDMI_SITE_REGION}/" \
-e "s/@UDMI_SITE_GROUP@/${UDMI_SITE_GROUP}/"

echo Creating terraform.tfvars
sed -E < terraform.tfvars.template > terraform.tfvars \
-e "s/@GCP_PROJECT_NAME@/${GCP_PROJECT_NAME}/g" \
-e "s/@GCP_PROJECT_ID@/${GCP_PROJECT_ID}/" \
-e "s/@GCP_PROJECT_REGION@/${GCP_PROJECT_REGION}/" \
-e "s/@GCP_PROJECT_GROUP@/${GCP_RPOJECT_GROUP}/"

echo Done with terraform setup.
33 changes: 0 additions & 33 deletions cloud/gcp/setup.sh

This file was deleted.

7 changes: 7 additions & 0 deletions cloud/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ variable "gcp_auth_file" {
description = "GCP authentication file"
}

# GCP flaky control
variable "gcp_flakiness_sleep" {
type = number
description = "GCP provisioning sleep to control flakiness"
default = 2
}

variable "tf-state-bucket-name" {
type = string
description = "The name of the Google Storage Bucket to create to store the Terraform state"
Expand Down