-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from bcgov/feat/57-tf-bootstrap-migration
chore/57 tf bootstrap migration
- Loading branch information
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
kind: Secret | ||
apiVersion: v1 | ||
metadata: | ||
name: gcp-credentials-secret | ||
labels: | ||
{{ include "cas-provision.labels" . | indent 4 }} | ||
type: Opaque | ||
stringData: | ||
gcp_project_id: "{{ .Values.gcpTerraform.projectId }}" | ||
tf_backend: | | ||
bucket = "{{ .Release.Namespace }}-state" | ||
prefix = "terraform/state" | ||
credentials = "/etc/gcp/credentials.json" | ||
sa_json: {{ .Values.gcpTerraform.serviceAccountCredentials | quote }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/bin/bash | ||
set -uo pipefail | ||
|
||
usage() { | ||
cat << EOF | ||
$0 [OPTIONS] | ||
Runs the GCP CLI to provision storage buckets for Terraform usage. | ||
The list of namespaces affected by the script is defined by the | ||
"--project-prefixes" and "--project-suffixes" options (see below). | ||
For instance, "--project-prefixes abc123,456qwe --project-suffixes dev,test" | ||
would affect the following namespaces: abc123-dev, abc123-test, 456qwe-dev and 456qwe-test | ||
Options: | ||
-pp, --project-prefixes | ||
The comma-separated project prefixes of the project to create buckets for. e.g. "abc123,456qwe" | ||
-ps, --project-suffixes | ||
The comma-separated project suffixes of the project to create buckets for. Defaults to "dev,test,prod" | ||
-gcp, --google-cloud-project | ||
The google cloud project id where the buckets will be created. | ||
-gcr, --google-cloud-region | ||
The google cloud region where the buckets will be created. Defaults to "northamerica-northeast1", in Montreal. | ||
-h, --help | ||
Prints this message | ||
EOF | ||
} | ||
|
||
# default options | ||
declare -a suffixes=("dev" "test" "prod") | ||
google_region="northamerica-northeast1" # Montreal | ||
|
||
while [[ -n ${1+x} && "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in | ||
-pp | --project-prefixes ) | ||
shift | ||
IFS=',' read -r -a prefixes <<< "$1" | ||
;; | ||
-ps | --project-suffixes ) | ||
shift | ||
IFS=',' read -r -a suffixes <<< "$1" | ||
;; | ||
-gcp | --google-cloud-project ) | ||
shift | ||
google_project=$1 | ||
;; | ||
-gcr | --google-cloud-region ) | ||
shift | ||
google_region=$1 | ||
;; | ||
-h | --help ) | ||
usage | ||
exit 0 | ||
;; | ||
esac; shift; done | ||
|
||
|
||
|
||
for prefix in "${prefixes[@]}"; do | ||
for suffix in "${suffixes[@]}"; do | ||
|
||
namespace=$prefix-$suffix | ||
bucket="gs://${namespace}-state" | ||
echo "Creating TF state bucket $bucket for $namespace namespace" | ||
gcloud storage buckets create $bucket --project=$google_project --location=$google_region | ||
|
||
done | ||
done | ||
|