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

[Bug]: Failed apply to a snowflake_user password will still update the state of the user's password #2970

Closed
1 task
jsnb-devoted opened this issue Jul 30, 2024 · 4 comments
Labels
bug Used to mark issues with provider's incorrect behavior resource:user Issue connected to the snowflake_user resource

Comments

@jsnb-devoted
Copy link

Terraform CLI Version

1.8.1

Terraform Provider Version

0.92.0

Terraform Configuration

resource "snowflake_user" "service_account" {
  for_each          = local.service_accounts
  name              = each.key
  login_name        = each.value.login_name
  default_role      = each.value.role
  default_namespace = each.value.namespace
  default_warehouse = each.value.warehouse
  comment           = each.value.comment
  password          = try(random_password.snowflake_service_account_passwords[each.key].result, try(jsondecode(data.aws_secretsmanager_secret_version.service_account_creds[each.key].secret_string)["values"]["password"], null))
  rsa_public_key = try(
        trimspace(tls_private_key.snowflake_service_account_key[each.key].public_key_pem), null
  )
  must_change_password = false
}

Category

category:resource

Object type(s)

resource:user

Expected Behavior

I had a plan that was meant to update a password and add a public key:

  # module.account.snowflake_user.service_account["MY_USER"] will be updated in-place
~ resource "snowflake_user" "service_account" {
        id                      = "MY_USER"
        name                    = (sensitive value)
      ~ password                = (sensitive value)
      + rsa_public_key          = (known after apply)
        # (13 unchanged attributes hidden)
    }

That failed because the public key had the header and footer:

╷
│ Error: 003065 (42601): SQL execution error:
│ New public key rejected by current policy. Reason: 'Invalid public key'
│ 

I checked the query history log and found the failed ALTER USER statement as expected however the state must have indicated that the password had been updated when in fact it was still the old password:

  # module.account.snowflake_user.service_account["MY_USER"] will be updated in-place
~ resource "snowflake_user" "service_account" {
        id                      = "MY_USER"
        name                    = (sensitive value)
      ~ rsa_public_key          = <<-EOT
            -----BEGIN PUBLIC KEY-----
            ...
            -----END PUBLIC KEY-----
        EOT
        # (14 unchanged attributes hidden)
    }

Actual Behavior

If an apply for the snowflake_user resource then I would expect TF to not update the state such that it produces the same diff on the subsequent plan.

Steps to Reproduce

Update password and public key values in the snowflake user resource. Provide an invalid public key such that Snowflake will reject the ALTER statement (one option is to include the header/footer). Plan/Apply - confirm that the apply fails. Run another plan and confirm that the snowflake user does not provide a diff despite the password being difference in the state.

How much impact is this issue causing?

Low

Logs

No response

Additional Information

No response

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@jsnb-devoted jsnb-devoted added the bug Used to mark issues with provider's incorrect behavior label Jul 30, 2024
@sfc-gh-asawicki
Copy link
Collaborator

Hey @jsnb-devoted. Thanks for reaching out to us.

We are currently reworking user resource. I will check the reproduction steps in one of my PRs and let you know.

@sfc-gh-asawicki sfc-gh-asawicki added the resource:user Issue connected to the snowflake_user resource label Jul 31, 2024
sfc-gh-asawicki added a commit that referenced this issue Aug 23, 2024
sfc-gh-asawicki added a commit that referenced this issue Aug 28, 2024
Fix known user resource-connected issues:
- Change the sensitiveness of name and login_name (References: #2662
#2668)
- Handle "null" properly for the nullable bool text attributes in user
(References: #2817)
- Fix diff suppression for default_x in user resource (References:
#2836)
- Update the migration guide (References #2938 #2942)
- Fix incorrect state after failed to alter (References #2970)
- Confirm the problem with the computed disabled attribute (References
#1572)
- Confirm that the problem with the null-out password was already solved
(References #1535)
- Add TODO to handle days to expiry in user (References #1155)

The next 2 PRs will contain:
- adjusting user resource to our rework conventions (also adding
additional fields and handling #1155 and #1572)
- adjusting user datasource (will handle #2902)

User rework will not include handling new types of users (service,
legacy service); this will be done a bit later.
@sfc-gh-asawicki
Copy link
Collaborator

Hey @jsnb-devoted, the fix was included in #3013 and will be released in v0.95.0 today or tomorrow (we have to wrap up a few other PRs before making a release). Please check the migration guide and report any problems.

@sfc-gh-asawicki
Copy link
Collaborator

Hey @jsnb-devoted.
We have just released v0.95.0 of the provider. It contains a reworked snowflake_user resource. Please consult the migration guide.

@sfc-gh-asawicki
Copy link
Collaborator

Closing the issue due to inactivity. Please create a new one if the issue persists in the newest version of the provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to mark issues with provider's incorrect behavior resource:user Issue connected to the snowflake_user resource
Projects
None yet
Development

No branches or pull requests

2 participants