equinix / terraform-provider-metal

DEPRECATED Equinix Metal standalone TF provider. Use the unified Equinix Terraform Provider.
https://registry.terraform.io/providers/equinix/equinix/latest/docs/guides/migration_guide_equinix_metal
Mozilla Public License 2.0
14 stars 11 forks source link

metal_project payment_method_id UUID validation prevents refresh #201

Closed displague closed 2 years ago

displague commented 2 years ago

It is possible for the payment_method to not be included in the project API response, even when payment_method is included. This is due to some billing relationship or token access to billing information.

When payment info is not included in the API response, the PaymentMethod object has zero values, including the Href and ID. This results in UUID validation by Terraform.

During refresh:

invalid value for payment_method_id (must be a valid UUID)

Packngo should reflect that Project PaymentMethod can be null. (it may be omitted by the API) Terraform validation should allow this field to be empty. https://github.com/equinix/terraform-provider-metal/blob/main/metal/resource_metal_project.go#L59

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file.

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist. Note: the debug log will contain your API key, please review the log and delete sensitive secrets before submitting.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

What should have happened?

Actual Behavior

What actually happened?

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Are there anything atypical about your accounts that we should know?

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

displague commented 2 years ago

https://github.com/hashicorp/terraform-provider-aws/issues/13943 offers a validation path using validation.Any and validation.ExactlyOneOf (which does not seem to be defined)

t0mk commented 2 years ago

@displague I didn't manage to invoke the error but I think I see the problem. The PaymentMethod field is not a pointer so it's filled with empty struct on API response deserialization.

I guess we will need to do sth like

if len(proj.PaymentMethod.URL) != 0 
  d.Set("payment_method_id", path.Base(proj.PaymentMethod.URL))
}

... i.e. skip the assignment to the provider attribute unless the payment method URL is set. If it's not set, I think the format check won't trigger. I can't test it, the acceptance test doesn't seem to run the ValidateFunc if I assign empty string to the payment_method_id attribute.

displague commented 2 years ago

Fix released in v3.2.1