dnsimple / terraform-provider-dnsimple

Terraform DNSimple provider.
https://www.terraform.io/docs/providers/dnsimple/
Mozilla Public License 2.0
21 stars 20 forks source link

Provider error when creating a TXT record for SPF #196

Closed cprice-ping closed 8 months ago

cprice-ping commented 9 months ago

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

% terraform -version
Terraform v1.7.4 on darwin_amd64

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "dnsimple_zone_record" "spf_records" {

  zone_name = var.dns_domain
  type      = data.pingone_trusted_email_domain_spf.email_domain_spf.type
  ttl       = 3600
  name      = data.pingone_trusted_email_domain_spf.email_domain_spf.key
  value     = data.pingone_trusted_email_domain_spf.email_domain_spf.value
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://gist.github.com/cprice-ping/2befedf9d16191fa280e50af51c46f79

Panic Output

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

Expected Behavior

TXT record creation shouldn't have generated an error

Actual Behavior

Proper TXT record is created, but the Provider errors.

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? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?

References

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

weppos commented 9 months ago

Thanks for the report @cprice-ping. In the report, you mention the creation of a TXT, whereas the code references an SPF. Just to clarify, are you referring to the creation of the alternate TXT record that we generate when you create an SPF? Or something else?

cprice-ping commented 9 months ago

Hmmm -- I'm letting my SaaS provider tell me what type of record, and I suspect they're telling me TXT instead of SPF for the CreateRecord resource:

type = data.pingone_trusted_email_domain_spf.email_domain_spf.type

Can I just say type = "SPF" and create the proper record that you will then reflect in a TXT?

cprice-ping commented 9 months ago

I've switched the HCL to type = "SPF" and I see this in the plan

 # dnsimple_zone_record.spf_records will be created
  + resource "dnsimple_zone_record" "spf_records" {
      + id               = (known after apply)
      + name             = "@"
      + priority         = (known after apply)
      + qualified_name   = (known after apply)
      + ttl              = 3600
      + type             = "SPF"
      + value            = "v=spf1 include:amazonses.com ~all"
      + value_normalized = (known after apply)
      + zone_id          = (known after apply)
      + zone_name        = "prettierbaby.org"
    }

The SPF record is successfully created, and I see you generate the corresponding TXT record, but the error persists:

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to dnsimple_zone_record.spf_records, provider "provider[\"registry.terraform.io/dnsimple/dnsimple\"]" produced an unexpected new value:
│ .name: was cty.StringVal("@"), but now cty.StringVal("").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
cprice-ping commented 9 months ago

I think I see what's going on -- it's this line in the UI for creating a record:

"Leave this blank to create a record for prettierbaby.org. You may also use the wildcard (*) here."

When I send in the "@" for the SPF record name - the service rejects it and replaces it with "" -- that's the inconsistent error that the provider is emitting

DXTimer commented 8 months ago

Thank you, @cprice-ping, for your collaboration in identifying the root cause of this issue. I've successfully replicated the error by configuring the record name as "@". It appears this occurs because the API accepts and then normalizes this value. To align with the API's behaviour, we will need to update the provider accordingly.