terraformterraform-provider-gcp

Create google cloud bucket and save terraform state to it with the same terraform script?


I'm new to terraform, and am trying to use it to create and configure an entire project from scratch. We're currently thinking about it as 1 google project is one environment.

It seems reasonable to store the terraform remote state inside of a bucket in the project that it is configuring. i.e. have terraform create the google cloud project, create a bucket, and then store its own remote state in that bucket that it just created. That also seems very advanced and potentially chicken / egg.

Is it possible to store terraform scripts remote state in the project that the terraform script itself is creating?


Solution

  • You could use terraform to create the project and bucket and then migrate the state into that bucket. But this is a chicken/egg scenario that begs the question, what happens if you need to delete/rebuild the bucket containing the state?

    A more sensible approach would be to manually create a master project and remote state bucket. From there you would have a base for a project vending machine to spin up new projects and baseline config.