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

deploy: Modularize gcp terraform #717

Merged
merged 31 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a079fb0
Adds gcp project-credentials and vpc terraform modules
jlerche Jul 29, 2019
cfac212
More progress
jlerche Jul 30, 2019
0646f9e
intermediate commit
jlerche Jul 30, 2019
a39858f
More refactoring of gcp terraform into modules
jlerche Jul 30, 2019
60492b0
Correctly passes module outputs to variables
jlerche Jul 31, 2019
9d485e1
Correctly set taints and selectors on node pools
jlerche Aug 1, 2019
d15a095
Adds base values for GCP
jlerche Aug 1, 2019
e1e8a21
Adds formatting pass
jlerche Aug 1, 2019
17629ab
Fixes to get the helm provider to work
jlerche Aug 2, 2019
ca71692
Removes local variable that was no longer necessary
jlerche Aug 2, 2019
cf89eae
Uncomments and fixes data.tf
jlerche Aug 2, 2019
b38f8d5
Merge branch 'master' into modularize_gcp_terraform
Aug 2, 2019
d825c03
Fixes formatting, removes unnecessary variables, refactors
jlerche Aug 2, 2019
bc229a8
Refactors some names and formats
jlerche Aug 2, 2019
7480cdd
Add maintenance time variable with default
jlerche Aug 6, 2019
c801a64
Changes bastion image to centos
jlerche Aug 6, 2019
2799672
Adds comment to bastion module explaining empty access_config block
jlerche Aug 6, 2019
df29390
Merge branch 'master' into modularize_gcp_terraform
Aug 6, 2019
1dd4b96
Removes empty data.tf
jlerche Aug 6, 2019
4258766
Merge branch 'modularize_gcp_terraform' of github.com:jlerche/tidb-op…
jlerche Aug 6, 2019
239918f
Removes tidb-cluster-values.yaml.tpl
jlerche Aug 7, 2019
284415f
helm doesn't install a release unless there's wait = false
jlerche Aug 8, 2019
a9cc9c4
Removes storage size override in default.yaml
jlerche Aug 8, 2019
cd4dacf
Refactors the tidb operator chart version variables
jlerche Aug 8, 2019
d8ba365
Moves pv reclaimpolicy=delete to tidb-cluster module
jlerche Aug 9, 2019
a87796c
fix create-service-account.sh
gregwebs Aug 9, 2019
886adbf
Removes destroy trigger for patching reclaimpolicy PV
jlerche Aug 14, 2019
93db57b
Adds bash script to change pv reclaimpolicy from Retain to Delete
jlerche Aug 14, 2019
9f32741
Formatting pass
jlerche Aug 14, 2019
adda73b
Formatting pass
jlerche Aug 14, 2019
c84d1d1
Merge branch 'master' into modularize_gcp_terraform
gregwebs Aug 15, 2019
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
22 changes: 22 additions & 0 deletions deploy/gcp/change-pv-reclaimpolicy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Set the ReclaimPolicy of persistent volumes bound to PVCs for a TiDB cluster in a given namespace
# Inputs: Path to a valid kubeconfig file and the namespace in which the PVCs live.
# Run before terraform destroy

set -euo pipefail
set -x

KUBECONFIGFILE=$1
NAMESPACE=$2

if [[ ! -f ${KUBECONFIGFILE} ]]; then
echo "The given kubeconfig file does not exist"
exit 1
fi

if ! kubectl --kubeconfig ${KUBECONFIGFILE} get ns ${NAMESPACE}; then
echo "The given namespace was not found in the kubernetes cluster for the given kubeconfig file"
exit 1
fi

kubectl --kubeconfig ${KUBECONFIGFILE} get pvc -n ${NAMESPACE} -o jsonpath='{.items[*].spec.volumeName}'|fmt -1 | xargs -I {} kubectl --kubeconfig ${KUBECONFIGFILE} patch pv {} -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'
46 changes: 35 additions & 11 deletions deploy/gcp/create-service-account.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/usr/bin/env bash
# Create a service account with permissions needed for the terraform
#
# This script is currently designed to be idempotent and re-runnable, like terraform.
#
# We could write this in terraform, but there is a bootstrapping issue,
# so it cannot just be added to the existing terraform.

set -euo pipefail
cd "$(dirname "$0")"
PROJECT="${TF_VAR_GCP_PROJECT:-$(cat terraform.tfvars | awk -F '=' '/GCP_PROJECT/ {print $2}' | cut -d '"' -f 2)}"
echo "$PROJECT"
echo "using project: $PROJECT"

cred_file=credentials.auto.tfvars
if test -f "$cred_file" ; then
Expand All @@ -13,15 +19,33 @@ if test -f "$cred_file" ; then
fi
fi

gcloud iam service-accounts create --display-name terraform terraform
email="terraform@${PROJECT}.iam.gserviceaccount.com"
gcloud projects add-iam-policy-binding "$PROJECT" --member "$email" --role roles/container.clusterAdmin
gcloud projects add-iam-policy-binding "$PROJECT" --member "$email" --role roles/compute.networkAdmin
gcloud projects add-iam-policy-binding "$PROJECT" --member "$email" --role roles/compute.viewer
gcloud projects add-iam-policy-binding "$PROJECT" --member "$email" --role roles/compute.securityAdmin
gcloud projects add-iam-policy-binding "$PROJECT" --member "$email" --role roles/iam.serviceAccountUser
gcloud projects add-iam-policy-binding "$PROJECT" --member "$email" --role roles/compute.instanceAdmin.v1
GCLOUD="gcloud --project $PROJECT"

mkdir -p credentials
gcloud iam service-accounts keys create credentials/terraform-key.json --iam-account "$email"
echo GCP_CREDENTIALS_PATH="$(pwd)/credentials/terraform-key.json" > "$cred_file"
key_file=credentials/terraform-key.json
email="terraform@${PROJECT}.iam.gserviceaccount.com"

sas=$($GCLOUD iam service-accounts list)
if echo "$sas" | grep terraform >/dev/null ; then
if test -f $key_file && grep "$PROJECT" $key_file >/dev/null ; then
echo "service account terraform already exists along with the key file. Will set terraform variables"
else
echo "service account terraform already exists, will get a key for it"
$GCLOUD iam service-accounts keys create $key_file --iam-account "$email"
fi
else
echo "creating a new service account terraform"
$GCLOUD iam service-accounts create --display-name terraform terraform
$GCLOUD iam service-accounts keys create $key_file --iam-account "$email"
fi

chmod 0600 $key_file

$GCLOUD projects add-iam-policy-binding "$PROJECT" --member "serviceAccount:$email" --role roles/container.clusterAdmin
$GCLOUD projects add-iam-policy-binding "$PROJECT" --member "serviceAccount:$email" --role roles/compute.networkAdmin
$GCLOUD projects add-iam-policy-binding "$PROJECT" --member "serviceAccount:$email" --role roles/compute.viewer
$GCLOUD projects add-iam-policy-binding "$PROJECT" --member "serviceAccount:$email" --role roles/compute.securityAdmin
$GCLOUD projects add-iam-policy-binding "$PROJECT" --member "serviceAccount:$email" --role roles/iam.serviceAccountUser
$GCLOUD projects add-iam-policy-binding "$PROJECT" --member "serviceAccount:$email" --role roles/compute.instanceAdmin.v1

echo GCP_CREDENTIALS_PATH="\"$(pwd)/$key_file\"" > "$cred_file"
35 changes: 0 additions & 35 deletions deploy/gcp/data.tf

This file was deleted.

Loading