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

When destroying & creating a Spanner instance, its database isn't recreated with it #7840

Closed
quentinms opened this issue Nov 18, 2020 · 3 comments
Assignees
Labels

Comments

@quentinms
Copy link

quentinms commented Nov 18, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v0.12.18
+ provider.google v3.48.0

Affected Resource(s)

  • google_spanner_instance
  • google_spanner_database

Terraform Configuration Files

Before:

resource "google_spanner_instance" "test" {
  project      = var.project
  name         = "test"
  config       = "regional-us-east1"
  display_name = "Test"
  num_nodes    = 1
}

resource "google_spanner_database" "test" {
  project  = var.project
  instance = google_spanner_instance.test.name
  name     = "test"
}

After:

resource "google_spanner_instance" "test" {
  project      = var.project
  name         = "test"
  config       = "nam11"
  display_name = "Test"
  num_nodes    = 1
}

resource "google_spanner_database" "test" {
  project  = var.project
  instance = google_spanner_instance.test.name
  name     = "test"
}

Debug Output

https://gist.github.com/quentinms/52ad7e765738b986888025b953a0f4cf

Panic Output

Expected Behavior

In addition to recreating the google_spanner_instance it should also recreate the google_spanner_database linked to it.

Actual Behavior

It only recreates the google_spanner_instance (making a spanner instance with no database).
By planning again, it will notice the google_spanner_database is missing and will want to create it. It should all happen at the same time.

Steps to Reproduce

  1. terraform plan & terraform apply the following:
resource "google_spanner_instance" "test" {
  project      = var.project
  name         = "test"
  config       = "regional-us-east1"
  display_name = "Test"
  num_nodes    = 1
}

resource "google_spanner_database" "test" {
  project  = var.project
  instance = google_spanner_instance.test.name
  name     = "test"
}
  1. Change the google_spanner_instance config to force a destroy & create.
resource "google_spanner_instance" "test" {
  project      = var.project
  name         = "test"
  config       = "nam11" // Will force recreation
  display_name = "Test"
  num_nodes    = 1
}

resource "google_spanner_database" "test" {
  project  = var.project
  instance = google_spanner_instance.test.name
  name     = "test"
}
  1. terraform plan
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # google_spanner_instance.test must be replaced
-/+ resource "google_spanner_instance" "test" {
      ~ config       = "projects/test-project/instanceConfigs/regional-us-east1" -> "nam11" # forces replacement
        display_name = "Test"
      ~ id           = "test-project/test" -> (known after apply)
      - labels       = {} -> null
        name         = "test"
        num_nodes    = 1
        project      = "test-project"
      ~ state        = "READY" -> (known after apply)
    }

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

The plan is missing the google_spanner_database database which will also be destroyed (and should be recreated).

Important Factoids

References

@ghost ghost added the bug label Nov 18, 2020
@edwardmedia edwardmedia self-assigned this Nov 18, 2020
@edwardmedia
Copy link
Contributor

Yes, we have to apply twice to restore the database. Not sure if there is a proper way that the Terraform code can be configured to reflect the underlying relationship.

@rileykarson
Copy link
Collaborator

This is an occurrence of an upstream issue in Terraform's resource model (hashicorp/terraform-plugin-sdk#122) for which we're not aware of any solution, unfortunately. Since there's nothing we can do here, I'm closing this out.

@ghost
Copy link

ghost commented Dec 20, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 20, 2020
@github-actions github-actions bot added service/spanner forward/review In review; remove label to forward labels Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants