hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.34k stars 1.75k forks source link

data.google_spanner_database_iam_policy and data.google_bigquery_table_iam_policy should fail when there is no such database/table #16612

Closed oprudkyi closed 11 months ago

oprudkyi commented 11 months ago

Community Note

Terraform Version

Terraform v1.6.4 on linux_amd64

Affected Resource(s)

Terraform Configuration Files

data "google_spanner_database_iam_policy" "spanner_database_data" {
  project  = "exist project"
  instance = "exist instance"
  database = "not-exists-db"
}

Debug Output

Panic Output

Expected Behavior

error - database not found

Actual Behavior

everything fine like db is exists

Steps to Reproduce

  1. terraform plan

Important Factoids

since this is xy problem in reality I want to add permissions to different entities via google_spanner_database_iam_member current behavior - plan is successful but apply fails since resource not found I want to check if the resource exists on plan stage alternative solution can be dummy data.google_spanner_database just to validate existence

References

oprudkyi commented 11 months ago

found workaround via postcondition , seems it distinguishes db without permissions and non exists db

data "google_spanner_database_iam_policy" "spanner_database_data" {
  database = var.database
  project  = var.project
  instance = var.instance

  lifecycle {
    postcondition {
      condition     = self.etag != null
      error_message = "Spanner database not found. Database : projects/${var.project}/instances/${var.instance}/databases/${var.database}, member : ${var.member}"
    }
  }
}
github-actions[bot] commented 10 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.