简体   繁体   中英

Google Cloud Composer using Terraform

I am new to Terraform, is there any straight forward way to manage and create Google Cloud Composer environment using Terraform?

I checked the supported list of components for GCP seems like Google Cloud Composer is not there as of now. As a work around I am thinking of creating a shell script including required gcloud composer cli commands and run it using Terraform, is it a right approach? Please suggest alternatives.

Google Cloud Composer is now supported in Terraform: https://www.terraform.io/docs/providers/google/r/composer_environment

It can be used as below

resource "google_composer_environment" "test" {
  name   = "my-composer-env"
  region = "us-central1"
}

That is an option. You can use a null_resource and local-exec to run commands:

resource "null_resource" "composer" {
  provisioner "local-exec" {
    inline = [
      "gcloud beta composer <etc..>"
    ]
  }
}

Just keep in mind when using local-exec :

Note that even though the resource will be fully created when the provisioner is run, there is no guarantee that it will be in an operable state

It looks like Google Cloud Composer is really new and still in beta. Hopefully Terraform will support it in the future.

I found that I had to use a slightly different syntax with the provisioner that included a command parameter.

resource "null_resource" "composer" {
  provisioner "local-exec" {
    command = "gcloud composer environments create <name> --project <project> --location us-central1 --zone us-central1-a --machine-type n1-standard-8"
  }
}

While this works, it is disconnected from the actual resource state in GCP. It'll rely on the state file to say whether it exists, and I found I had to taint it to get the command to run again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM