equinix/terraform-provider-metal

metal_project payment_method_id UUID validation prevents refresh

displague opened this issue · 3 comments

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:

  • #1234

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

t0mk commented

@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.

Fix released in v3.2.1