aiven / terraform-provider-aiven

Aiven Terraform Provider
https://registry.terraform.io/providers/aiven/aiven/latest/docs
MIT License
124 stars 68 forks source link

aiven_pg: Type error after upgrading to 4.x #1636

Closed thomas-auth0 closed 1 month ago

thomas-auth0 commented 4 months ago

What happened?

I'm trying to upgrade the Aiven provider from 3.12.1 to 4.9.3 using Terraform 1.1.7

When I update the provider to 4.x and run terraform init && terraform plan, I get the following errors with the aiven_pg resources:

│ Error: .pg_user_config[0].enable_ipv6: a bool is required
│ Error: .pg_user_config[0].pg[0].autovacuum_analyze_scale_factor: a number is required

These settings are empty in my config (they are not defined in the pg_user_config blocks, uses defaults).

In Terraform provider 3.x they defaulted to empty string, and with 4.0.0 they now should have strict types.

What did you expect to happen?

It looks like the stateUpgrader is not updating the types as it should.

What else do we need to know?

The problem disappear if I manually add enable_ipv6 = false in the config, but I shouldn't have to add all these optional settings. Am I missing something in this upgrade process?

Serpentiel commented 4 months ago

Hey, @thomas-auth0! 👋

Thank you for raising the issue! Could you please also suggest what values for those fields do you see in the state file directly (usually named as terraform.tfstate)?

thomas-auth0 commented 4 months ago

values for those fields do you see in the state file directly:

Thanks!, Here's the actual state (with 3.12.1):

            "pg_user_config": [
              {
                "enable_ipv6": "",
                "pg": [
                  {
                    "autovacuum_analyze_scale_factor": "",
Serpentiel commented 4 months ago

Hey, @thomas-auth0! 👋

Could you please update the Terraform version (not the provider's version) to the latest one and try it again?

Additionally, I recommend to check what is the schema_version in the state. In case it's value is other than 0, please change it to be so. This field serves as an indicator for the Terraform to run the "state upgrading" functions.

I tried to reproduce your issue, but I haven't been able to. Here's exactly what I did:

  1. Installed the mentioned version of the Terraform Provider (v3.12.1)
  2. Created a PostgreSQL service via it, while not setting the enable_ipv6 flag
  3. After the service was created, confirmed that the state had enable_ipv6 set to an empty string:
"...",
"schema_version": 0,
"...",
"enable_ipv6": "",
"..."
  1. Upgraded to the latest version of the Terraform Provider (v4.11.0)
  2. Changed an unrelated field (maintenance_window) in order to trigger a diff in the service's config/state, and consequentially continued with the apply operation.
  3. Confirmed that enable_ipv6 field was correctly "upgraded" in the state and the state then looked like this:
"...",
"schema_version": 1,
"...",
"enable_ipv6": false,
"..."

I looked up the error message, a <type> is required, and it looks like there were instances when this error appeared in older versions of Terraform, that were related to a bug in the Terraform itself, so I recommend to check whether upgrading your Terraform to the latest version helps to resolve the problem or not.

I will be closing this issue for the time being. If you have any additional information to share, please feel free to do that over here 🙂

thomas-auth0 commented 3 months ago

Thanks @Serpentiel I'll try with a different version.

anthonydurot commented 2 months ago

Hi ! We have the same error, any ideas from where it comes please ?

Serpentiel commented 2 months ago

Hey, @anthonydurot! 👋

I'm afraid I'm no longer actively participating in the maintenance of this repository.

I'll mention @byashimov or @rriski for additional help, though.

byashimov commented 2 months ago

Hey @anthonydurot:

  1. which version do you migrate from? (v3)
  2. which version do you migrate to? (v4) Is it the latest version?
  3. could you please share your config file without sensitive data?