課程內容與代碼會放在 Github 上: https://github.com/chechiachang/terraform-30-days
賽後文章會整理放到個人的部落格上 http://chechia.net/
本文簡短說明如何搭配 Google Cloud Platform 使用 Terraform
還請參考官方文件 GCP terraform get-started
Prerequiesites
VERSION=351.0.0
OS=darwin
ARCH=x86_64
cd # home
wget "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${VERSION}-${OS}-${ARCH}.tar.gz"
tar -zxf google-cloud-sdk-${VERSION}-${OS}-${ARCH}.tar.gz
ls google-cloud-sdk/bin
把下面這端加到 ~/.bashrc 或 ~/.zshrc
# Google SDK
export PATH="$PATH:/Users/${USER}/google-cloud-sdk/bin"
if [ -f '/Users/${USER}/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/${USER}/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/${USER}/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/${USER}/google-cloud-sdk/completion.zsh.inc'; fi
進行 gcloud init
gcloud init
Pick configuration to use:
[1] Create a new configuration
Choose the account you would like to use to perform operations for
this configuration:
[1] Log in with a new account
You are logged in as: [chechia@chechia.net].
Pick cloud project to use:
[1] Create a new project
Enter a Project ID. Note that a Project ID CANNOT be changed later.
Project IDs must be 6-30 characters (lowercase ASCII, digits, or
hyphens) in length and start with a lowercase letter. terraform-30-days
為了產生 foundation 我們使用 root account
本地產生 credential
gcloud auth application-default login
Credentials saved to file: [~/.config/gcloud/application_default_credentials.json]
cd gcp/foundation/us-west1/terraform_backend
terraform init
terraform plan
terraform apply
gcp/foundation/us-west1/terraform_backend
產生
完成上述設定後,可以使用 terragrunt 操作 terraform。關於 terragrunt 細節請見第六天左右。
cd gcp/foundation/compute_network
terragrunt init
terragrunt plan
terragrunt apply