namecheap / terraform-provider-namecheap

Terraform provider for Namecheap
Apache License 2.0
147 stars 30 forks source link

Failed to create namecheap Record: Invalid record type #32

Closed cyberbutler closed 3 years ago

cyberbutler commented 4 years ago

Terraform Version

Terraform v0.12.25
+ provider.http v1.2.0
+ provider.namecheap (unversioned)

Namecheap provider version

Both built from source and Release v1.5.0

Affected Resource(s)

Terraform Configuration Files

variable nc_username {
    type = string
    default = ""
}
variable nc_token {
    type = string
    default = ""
}
data http "myip" {
    url = "https://ipinfo.io/ip"
}

provider namecheap {
    use_sandbox = false
    username = var.nc_username
    api_user = var.nc_username
    token = var.nc_token
    ip = data.http.myip.body
}

resource namecheap_record "record" {
    type = "A"
    name = "test"
    domain = "example.com"
        address = "127.0.0.1"
}

Debug Output

https://gist.github.com/cyberbutler/39753094328b7a623a5ebc5004e507ac

Expected Behavior

What should have happened? Valid Record Type A should have been passed to the Namecheap Go API Successfully

Actual Behavior

What actually happened?

Error: Failed to create namecheap Record: Invalid record type, allowed types="A, AAAA, ALIAS, CAA, CNAME, MX, MXE, TXT, URL, URL301, FRAME"

  on namecheap.tf line 1, in resource "namecheap_record" "record":
   1: resource namecheap_record "record" {

Steps to Reproduce

  1. Configure the above terraform resources
  2. terraform apply

Important Factoids

Attempted to run from MacOS and Debian systems, both results in the same error. I've also run with both the released provider and built the provider from the master branch here. Same results.

I tracked down the provided error here. I also added some janky fmt.Printf "debug" code into the local build of the provider to see what was held in RecordType before it was passed to the namecheap.client but it didn't seem to be wrong in anyway. Perhaps there is a user error here somewhere?

cyberbutler commented 4 years ago

Just to be more concise the RecordType does not pass the CheckRecordType validation in the namecheap module. I cannot figure out why, I've also replicated the validation code with no issues:

package main

import (
    "fmt"
    "strings"
)
var (
    allowedRecordTypes = []string{
        "A", "AAAA", "ALIAS", "CAA", "CNAME", "MX", "MXE", "TXT", "URL", "URL301", "FRAME",
    }
)
func main() {
    if !CheckRecordType("A") {
        fmt.Printf("Invalid record type, allowed types=%s", strings.Join(allowedRecordTypes, ", "))
    } else {
        fmt.Println("We are all good here")
    }
}
func CheckRecordType(recordType string) bool {
    for _, legalRecordType := range allowedRecordTypes {
        if recordType == legalRecordType {
            return true
        }
    }
    return false
}