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

fix: planetscale_branch data source crash #99

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

joemiller
Copy link
Member

Given a main.tf such as:

provider "planetscale" {}

resource "planetscale_database" "mydb" {
  name         = "mydb"
  organization = "planetscale-terraform-testing"

  allow_data_branching          = false
  cluster_size                  = "PS_10"
  default_branch                = "main"
  production_branch_web_console = false
  region                        = "us-east"
}

resource "planetscale_branch" "staging" {
  name          = "staging"
  database      = planetscale_database.mydb.name
  organization  = planetscale_database.mydb.organization
  parent_branch = planetscale_database.mydb.default_branch
  production    = false
}

data "planetscale_branch" "staging" {
  database     = planetscale_database.mydb.name
  organization = planetscale_database.mydb.organization
  name         = planetscale_branch.staging.name
}

output "branch" {
  value = data.planetscale_branch.staging
}

A terraform plan will crash with:

Planning failed. Terraform encountered an error while generating this plan.


│ Error: Value Conversion Error

│ with data.planetscale_branch.staging,
│ An unexpected error was encountered trying to convert tftypes.Value into provider.branchDataSourceModel. This is always an error in the provider. Please report the following to the provider developer:

│ mismatch between struct and object: Object defines fields not found in struct: initial_restore_id.

Fix by adding the missing initial_restore_id field to the branchDataSourceModel struct and include a acceptance test to cover the planetscale_branch data source.

Given a `main.tf` such as:

```hcl
provider "planetscale" {}

resource "planetscale_database" "mydb" {
  name         = "mydb"
  organization = "planetscale-terraform-testing"

  allow_data_branching          = false
  cluster_size                  = "PS_10"
  default_branch                = "main"
  production_branch_web_console = false
  region                        = "us-east"
}

resource "planetscale_branch" "staging" {
  name          = "staging"
  database      = planetscale_database.mydb.name
  organization  = planetscale_database.mydb.organization
  parent_branch = planetscale_database.mydb.default_branch
  production    = false
}

data "planetscale_branch" "staging" {
  database     = planetscale_database.mydb.name
  organization = planetscale_database.mydb.organization
  name         = planetscale_branch.staging.name
}

output "branch" {
  value = data.planetscale_branch.staging
}
```

A `terraform plan` will crash with:

> Planning failed. Terraform encountered an error while generating this plan.
>
> ╷
> │ Error: Value Conversion Error
> │
> │   with data.planetscale_branch.staging,
> │ An unexpected error was encountered trying to convert tftypes.Value into provider.branchDataSourceModel. This is always an error in the provider. Please report the following to the provider developer:
> │
> │ mismatch between struct and object: Object defines fields not found in struct: initial_restore_id.

Fix by adding the missing `initial_restore_id` field to the `branchDataSourceModel` struct
and include a acceptance test to cover the `planetscale_branch` data source.
@joemiller joemiller requested review from a team as code owners January 16, 2025 00:25
since this is set in the makefile it will apply to local tests and github-actions
dctrwatson
dctrwatson previously approved these changes Jan 16, 2025
@joemiller joemiller merged commit 5eb7b72 into main Jan 16, 2025
15 checks passed
@joemiller joemiller deleted the joem/branch-ds-missing-init-restore-id branch January 16, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants