Description
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.
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).