How to use terraform cloud

Terraform

Installation

1
brew install terraform

Setup

1
terraform login

Get Started

Reference official tutorials

設定 backendremote,會將 .tfstat 存至 terraform cloud

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# main.tf
terraform {
backend "remote" {
organization = "${YOUR_ORG}"

workspaces {
name = "${YOUR_WORKSPACE}"
}
}
}

provider "google" {
credentials = file("${YOUR_GCLOUD_SA_KEY}")
project = "${YOUR_PROJECT_ID}"
region = "asia-east1"
zone = "asia-east1-c"
}

Init

初始化 terraform

1
terraform init

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# storage.tf
## set a bucket for static site
resource "google_storage_bucket" "static-site" {
name = "image-store.com"
location = "US"
force_destroy = true

uniform_bucket_level_access = true

website {
main_page_suffix = "index.html"
not_found_page = "404.html"
}
cors {
origin = ["http://image-store.com"]
response_header = ["*"]
max_age_seconds = 3600
}
}

## set public access control for static site
resource "google_storage_bucket_iam_binding" "public_binding" {
bucket = google_storage_bucket.static-site.name
role = "roles/storage.objectViewer"
members = [
"allUsers",
]
}