Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Org step cannot be destroyed with Terraform #1378

Open
aarturm opened this issue Feb 11, 2025 · 0 comments
Open

Org step cannot be destroyed with Terraform #1378

aarturm opened this issue Feb 11, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@aarturm
Copy link
Contributor

aarturm commented Feb 11, 2025

TL;DR

Not able to successfully run:
/bin/bash -c cft test run TestOrg --stage destroy --verbose --test-dir /workspace/terraform-example-foundation/test/integration
Either locally or in Cloud Build pipeline.

Expected behavior

"cft test run TestOrg --stage destroy" destroys all Org resources.

Observed behavior

cft test run TestOrg --stage destroy fails with error: Error: unable to make request: request failed, retries exceeded: %!s(<nil>) while destroying module.logs_export.terracurl_request.exclude_external_logs[0] resource.

Terraform configuration is to just apply and then destroy this module: https://github.com/terraform-google-modules/terraform-example-foundation/blob/main/1-org/modules/centralized-logging

Or specifically this resource.

resource "terracurl_request" "exclude_external_logs" {

Terraform Configuration

locals {
  project_id = "PROJECT_ID"
}

resource "terracurl_request" "exclude_external_logs" {

  name           = "exclude_external_logs"
  url            = "https://logging.googleapis.com/v2/projects/${local.project_id}/sinks/_Default?updateMask=exclusions"
  method         = "PUT"
  response_codes = [200]
  headers = {
    Authorization = "Bearer ${data.google_client_config.default.access_token}"
    Content-Type  = "application/json",
  }
  request_body = <<EOF
{
  "exclusions": [
    {
      "name": "exclude_external_logs",
      "filter": "-logName : \"/${local.project_id}/\""

    }
  ],
}
EOF

  lifecycle {
    ignore_changes = [
      headers,
    ]
  }
}

data "google_client_config" "default" {
}

terraform {
  required_version = ">= 1.3"

  required_providers {
    terracurl = {
      source  = "devops-rob/terracurl"
      version = "1.2.1"
    }
  }
}

Terraform Version

Terraform v1.5.7
on linux_amd64
+ provider registry.terraform.io/devops-rob/terracurl v1.2.1
+ provider registry.terraform.io/hashicorp/google v6.19.0

Terraform Provider Versions

Providers required by configuration:
.
├── provider[registry.terraform.io/devops-rob/terracurl] 1.2.1
└── provider[registry.terraform.io/hashicorp/google]

Additional information

Issue fixed by defining destroy steps to "terracurl_request" "exclude_external_logs" resource:

destroy_url    = "https://logging.googleapis.com/v2/projects/${var.logging_destination_project_id}/sinks/_Default?updateMask=exclusions"
destroy_method = "PUT"
destroy_request_body = <<EOF
{
  "exclusions": [],
}
EOF

Can create a PR for that if only I will be able to pass integration test pipeline (I'm complaining on it randomly failing in another issue).

@aarturm aarturm added the bug Something isn't working label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant