Day 01-Workshop Google Cloud Platform Get-Started

上一篇:Day 01-引言:Terraform 是个好东西

课程内容与代码会放在 Github 上: https://github.com/chechiachang/terraform-30-days

赛後文章会整理放到个人的部落格上 http://chechia.net/

追踪粉专可以收到文章的主动推播

https://ithelp.ithome.com.tw/upload/images/20210901/20120327NvpHVr2QC0.jpg


本文简短说明如何搭配 Google Cloud Platform 使用 Terraform

还请参考官方文件 GCP terraform get-started

Prerequiesites

  • 一个 google account
  • 一个 Gcloud billing account
    • 需要绑定信用卡
    • 需要启用计费
  • gcloud SDK
    • 登入
    • 有效的 project

Gcloud SDK

下载并安装 gcloud sdk

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 config

进行 gcloud init

  • 设定本地 config 档案
  • 透过 web browser 登入 google 帐号
  • 产生 gcloud project,容纳所有云端资源 (很不精确的描述,类似 azure resource group 与 aws account)
    • 可能需要选择不同 project 名称
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: [[email protected]].

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

Provision GCS Terraform Backend (foundation)

为了产生 foundation 我们使用 root account

  • 建立 google bucket storage
  • 建立 terraform 专属的 service account
    • 避免使用 root user account 执行 Terraform 权限太大
    • 避免在本机留下 local credential,十分不安全
  • 只有在初始化 GCS backend 才使用 owner account,其他时间使用 terraform service 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

Use service account

  • 使用 gcp/foundation/us-west1/terraform_backend 产生
    • service account
    • local service accoint credential json key
  • 目前的 terragrunt module 会使用本地 credential key

Example: vpc networking

完成上述设定後,可以使用 terragrunt 操作 terraform。关於 terragrunt 细节请见第六天左右。

cd gcp/foundation/compute_network

terragrunt init
terragrunt plan
terragrunt apply

<<:  从零开始学3D游戏开发 Roblox Studio 简介 Part.1

>>:  Day 01 「科学 v.s. 数学」前言

[ JS个人笔记 ] 各种讨人厌的运算&转型案例—DAY2

特殊的数字 Infinity 系列: Infinity + Infinity // Infinity...

第26天 - 文件审核系统(4)_删除档案的部分

删除档案的部分,首先要先把栏位列印出来 资料表一样参考第23天的文章 https://ithelp....

Day 06: Python基础必备小知识(上)

那麽在前篇,我们已经安装建置好整个Python运行环境,接下来就可以学习如何编写简单的程序了! 以下...

[第一天]从0开始的UnityAR手机游戏开发-前言

AR介绍 AR为Augmented Reality(扩增实境)的简称,透过照相镜头和APP将真实世界...

DAY4 - 认识Nx

在上一篇,建立起一个Angular+Nestjs的Nx专案,那麽这一篇就要来好好介绍什麽是Nx。 安...