How to Destroy Infrastructure GCP

Use Case

If you are completely done with a specific Telestream Cloud Storage location (for example, you are switching to a new account) and you wish to remove the AWS bucket and all resources associated with the Telestream Cloud Storage including all objects inside the bucket, you would use the set of steps outlined below to remove the bucket and all resources associated with this.
Once you do this, you must delete the Telestream Cloud Store associated with this resource.

Terraform Build Infrastructure Documentation can be found here

Go into the directory with the and terraform.tfstate to run the terraform destroy command.

Initialize the Directory

When you create a new configuration — or check out an existing configuration from version control — you need to initialize the directory with terraform init.

Initializing a configuration directory downloads and installs the providers defined in the configuration, which in this case is the GCP provider. Terraform documentation can be found here

terraform init


$ terraform init
Initializing modules...
- bucket in

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/azurerm versions matching "3.47.0"...
- Installing hashicorp/azurerm v3.47.0...
- Installed hashicorp/azurerm v3.47.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Destroy Infrastructure

The terraform destroy command destroys all of the resources being managed by the current working directory and workspace, using state data to determine which real world objects correspond to managed resources. Like terraform apply, it asks for confirmation before proceeding. Terraform documentation can be found here

terraform destroy


$ terraform destroy
module.bucket.google_service_account.service_account[0]: Refreshing state... [id=projects/gcp-project-123/serviceAccounts/[email protected]]
module.bucket.google_storage_bucket.bucket[0]: Refreshing state... [id=fake-bucket-name-1]
module.bucket.google_storage_hmac_key.key[0]: Refreshing state... [id=projects/gcp-project-123/hmacKeys/GOOG1EC62JWZUXHHAQ3GRARQS4G2E3DASPOBYFAKEACCESSKEYID]
module.bucket.google_storage_bucket_iam_binding.binding[0]: Refreshing state... [id=b/fake-bucket-name-1/roles/storage.admin]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # module.bucket.google_service_account.service_account[0] will be destroyed
  - resource "google_service_account" "service_account" {
      - account_id  = "tcloud-tf-dev-service" -> null
      - description = "Service Account used to allow telestream cloud access the azure buckets" -> null
      - disabled    = false -> null
      - email       = "[email protected]" -> null
      - id          = "projects/gcp-project-123/serviceAccounts/[email protected]" -> null
      - member      = "serviceAccount:[email protected]" -> null
      - name        = "projects/gcp-project-123/serviceAccounts/[email protected]" -> null
      - project     = "gcp-project-123" -> null
      - unique_id   = "107999680400370368728" -> null

  # module.bucket.google_storage_bucket.bucket[0] will be destroyed
  - resource "google_storage_bucket" "bucket" {
      - default_event_based_hold    = false -> null
      - force_destroy               = false -> null
      - id                          = "fake-bucket-name-1" -> null
      - labels                      = {} -> null
      - location                    = "US-EAST1" -> null
      - name                        = "fake-bucket-name-1" -> null
      - project                     = "gcp-project-123" -> null
      - public_access_prevention    = "enforced" -> null
      - requester_pays              = false -> null
      - self_link                   = "" -> null
      - storage_class               = "STANDARD" -> null
      - uniform_bucket_level_access = false -> null
      - url                         = "gs://fake-bucket-name-1" -> null

  # module.bucket.google_storage_bucket_iam_binding.binding[0] will be destroyed
  - resource "google_storage_bucket_iam_binding" "binding" {
      - bucket  = "b/fake-bucket-name-1" -> null
      - etag    = "CAI=" -> null
      - id      = "b/fake-bucket-name-1/roles/storage.admin" -> null
      - members = [
          - "serviceAccount:[email protected]",
        ] -> null
      - role    = "roles/storage.admin" -> null

  # module.bucket.google_storage_hmac_key.key[0] will be destroyed
  - resource "google_storage_hmac_key" "key" {
      - access_id             = "GOOG1EC62JWZUXHHAQ3GRARQS4G2E3DASPOBYFAKEACCESSKEYID" -> null
      - id                    = "projects/gcp-project-123/hmacKeys/GOOG1EC62JWZUXHHAQ3GRARQS4G2E3DASPOBYFAKEACCESSKEYID" -> null
      - project               = "gcp-project-123" -> null
      - secret                = (sensitive value)
      - service_account_email = "[email protected]" -> null
      - state                 = "ACTIVE" -> null
      - time_created          = "2023-04-04T14:40:12.792Z" -> null
      - updated               = "2023-04-04T14:40:12.792Z" -> null

Plan: 0 to add, 0 to change, 4 to destroy.

Changes to Outputs:
  - Access_Key   = "projects/gcp-project-123/hmacKeys/GOOG1EC62JWZUXHHAQ3GRARQS4G2E3DASPOBYFAKEACCESSKEYID" -> null
  - Secret_Key   = (sensitive value)
  - bucket_names = "fake-bucket-name-1" -> null

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

module.bucket.google_storage_bucket_iam_binding.binding[0]: Destroying... [id=b/fake-bucket-name-1/roles/storage.admin]
module.bucket.google_storage_hmac_key.key[0]: Destroying... [id=projects/gcp-project-123/hmacKeys/GOOG1EC62JWZUXHHAQ3GRARQS4G2E3DASPOBYFAKEACCESSKEYID]
module.bucket.google_storage_hmac_key.key[0]: Destruction complete after 2s
module.bucket.google_storage_bucket_iam_binding.binding[0]: Destruction complete after 5s
module.bucket.google_service_account.service_account[0]: Destroying... [id=projects/gcp-project-123/serviceAccounts/[email protected]]
module.bucket.google_storage_bucket.bucket[0]: Destroying... [id=fake-bucket-name-1]
module.bucket.google_storage_bucket.bucket[0]: Destruction complete after 0s
module.bucket.google_service_account.service_account[0]: Destruction complete after 0s

Destroy complete! Resources: 4 destroyed.