![](/style/images/good.png)
![](/style/images/bad.png)
Manage Terraform State on Google Cloud Storage(GCS)
source link: https://www.pkslow.com/archives/terraform-gcs-en
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
调角断清秋,征人倚戍楼。
It's a best pratice to manage Terraform state on central storage like GCS for GCP.
We need to create a Bucket to store the state files:
$ gsutil mb -p pkslow -l us-west1 -b on gs://pkslow-terraform
Creating gs://pkslow-terraform/...
$ gsutil ls gs://
gs://pkslow-terraform/
Define the backend "gcs" in Terraform code:
terraform {
backend "gcs" {
bucket = "pkslow-terraform"
prefix = "state/gcp/pubsub"
}
}
Initiate the Terraform project, it will help to create folder in the Bucket:
$ terraform init -plugin-dir=${TERRAFORM_PLUGIN}
Apply the change:
$ terraform apply -auto-approve
Check on the GCP Console, the state file is created:
What's more, we can also fetch the data from the remote state:
data "terraform_remote_state" "foo" {
backend = "gcs"
config = {
bucket = "terraform-state"
prefix = "prod"
}
}
resource "template_file" "bar" {
template = "${greeting}"
vars {
greeting = "${data.terraform_remote_state.foo.greeting}"
}
}
Code on GitHub: https://github.com/LarryDpk/pkslow-samples
Reference:
Manage GCP Pubsub with Terraform
欢迎关注微信公众号<南瓜慢说>,将持续为你更新...
推荐阅读:
如何制定切实可行的计划并好好执行
容器技术(Docker-Kubernetes)
SpringBoot-Cloud相关
Https专题
- 本文作者: 南瓜慢说
- 本文链接: https://www.pkslow.com/archives/terraform-gcs-en
- 版权声明: 本博客所有文章除特别声明外,不可转载!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK