Shrashti
Shrashti

Reputation: 150

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.

Upvotes: 1

Views: 3151

Answers (3)

Kannappan Sirchabesan
Kannappan Sirchabesan

Reputation: 1382

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"
}

Upvotes: 6

Jonathan Sharley
Jonathan Sharley

Reputation: 11

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.

Upvotes: 1

Brandon Miller
Brandon Miller

Reputation: 5065

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.

Upvotes: 2

Related Questions