Showing posts with label terraform. Show all posts
Showing posts with label terraform. Show all posts

Tuesday, February 22, 2022

Reverse engineering an existing GCP project with terraformer

It can be tough to try to reverse engineer an existing project that has never used terraform. Terraformer can look at an existing project and generate the corresponding terraform code for you. 

I tried it out on an existing legacy project which used Google Cloud Storage, BigQuery and various service accounts. The setup was a little tricky so I put together a script to simply things. The script assumes you have gcloud setup or a service account key/impersonation and you may need to adjust the --resources parameter.



You may be in for a shock when you examine the generated code. Terraform works well when you think of you application are modules. A module that groups together a variety of resources (gcs bucket + service account + compute engine) that forms part of the application is far more valuable then simply considering each resource by itself. Terraformer has no idea how these resources are used or grouped. So you might need to consider refactoring the generated code into more manageable modules.

I would definitely use the tool again on projects where there is no Terraform or where there has been significant infrastructure drift. There's also Pulumi, maybe for another day.

Saturday, July 25, 2020

Wednesday, February 05, 2020

Cloud Billing Budget API in beta

You can finally set budgets via the API in GCP. This is a huge relief to all those org admins out there who have had to do this manually.

AND, hold on to your hats, there's terraform support as well! 

Looks like Christmas came late....


data "google_billing_account" "account" {
  provider = google-beta
  billing_account = "000000-0000000-0000000-000000"
}

resource "google_billing_budget" "budget" {
  provider = google-beta
  billing_account = data.google_billing_account.account.id
  display_name = "Example Billing Budget"
  amount {
    specified_amount {
      currency_code = "USD"
      units = "100000"
    }
  }
  threshold_rules {
      threshold_percent =  0.5
  }
}

Saturday, August 17, 2019

Saturday, April 20, 2019

Terraform init in the real world

Rather than fully configuring your backend.tf in a file.
terraform {
 backend "gcs" {
   bucket  = "my-bucket-123"
  prefix  = "terraform/state" 
}
I prefer to use the command line in order avoid polluting the code with any environment specific names.

terraform init \    
           -backend-config="bucket=my-bucket-123" \     
           -backend-config="prefix=terraform/state
As Google Cloud Storage buckets are unique across all projects, they will change as you move from project to project.

Sunday, February 17, 2019

Opinionated Google Cloud Platform projects

I'm glad Google are finally starting to embrace Terraform by creating their own modules. Version 0.1.0 of the project-factory looks really promising.