citrix / terraform-provider-citrixadc

Part of NetScaler Automation Toolkit | https://github.com/netscaler/automation-toolkit
https://registry.terraform.io/providers/citrix/citrixadc
Apache License 2.0
119 stars 59 forks source link

[BUG] Terraform provider can't create dns A record #953

Closed vintury closed 1 year ago

vintury commented 2 years ago

Contact us

For any immediate issues or help , reach out to us at appmodernization@citrix.com !

Bug Report

Describe the bug Terraform provider can't create dns A record

To Reproduce Steps to reproduce the behaviour:

  1. My terraform files are

    
    terraform {
    backend "pg" {}
    
    required_providers {
    citrixadc = {
      source = "citrix/citrixadc"
      version = "1.25.0"
    }
    }
    }

resource "citrixadc_dnsaddrec" "dnsaddrec" { hostname = "a.root-servers.net" ipaddress = "65.200.211.129" ttl = 3600 }

2. which terraform command I am getting the error
```terraform apply -auto-approve```
3. Terraform output logs

Error: [ERROR] nitro-go: Failed to create resource of type dnsaddrec, name=hohoho.net, err=failed: 400 Bad Request ({ "errorcode": 1074, "message": "Invalid value [set command not present for this resource]", "severity": "ERROR" }) │ │ with module.test_dns.citrixadc_dnsaddrec.dnsaddrec, │ on modules/dns/main.tf line 9, in resource "citrixadc_dnsaddrec" "dnsaddrec": │ 9: resource "citrixadc_dnsaddrec" "dnsaddrec" { │ ╵


5. Error I am facing on the console

**Expected behaviour**
I expect to dns record "a.root-servers.net" will be created.

**Screenshots**
<img width="1179" alt="image" src="https://user-images.githubusercontent.com/4948177/201302813-52f8209c-0e5b-42ee-af2f-fb49acd16e60.png">

**Environment (please complete the following information):**
 - OS: Linux/Ubuntu 22.04
 - `terraform version` v1.3.4 on linux_amd64
 - `go version` output
 - ADC Version: NetScaler NS13.0: Build 87.9.nc, Date: Jul 29 2022, 10:59:37   (64-bit)

**Additional context**
Add any other context about the problem here.
rohit-myali commented 2 years ago

Hello @vintury , It looks like there is an instance of dnsaddrec with the same name that you have specified in the above configuration file please check your ADC using CLI.

Thanks, Rohit

vintury commented 2 years ago

Hello @rohit-myali Thank you. You are right. I tried to create another DNS record, but have this issue:

$ terraform apply -auto-approve
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
Terraform will perform the following actions:
  # module.test_dns.citrixadc_dnsaddrec.dnsaddrec will be created
  + resource "citrixadc_dnsaddrec" "dnsaddrec" {
      + hostname  = "hohoho.net"
      + id        = (known after apply)
      + ipaddress = "10.200.211.129"
      + ttl       = 3600
    }
Plan: 1 to add, 0 to change, 0 to destroy.
module.test_dns.citrixadc_dnsaddrec.dnsaddrec: Creating...
╷
│ Error: [ERROR] nitro-go: Failed to create resource of type dnsaddrec, name=hohoho.net, err=failed: 400 Bad Request ({ "errorcode": 1074, "message": "Invalid value [set command not present for this resource]", "severity": "ERROR" })
│ 
│   with module.test_dns.citrixadc_dnsaddrec.dnsaddrec,
│   on modules/dns/main.tf line 1, in resource "citrixadc_dnsaddrec" "dnsaddrec":
│    1: resource "citrixadc_dnsaddrec" "dnsaddrec" {
│ 
╵
Cleaning up file based variables
ERROR: Job failed: exit code 1

My resource.tf file is:

terraform {
  backend "pg" {}

  required_providers {
    citrixadc = {
      source = "citrix/citrixadc"
      version = "1.25.0"
    }
  }
}

resource "citrixadc_dnsaddrec" "dnsaddrec" {
  hostname  = "hohoho.net"
  ipaddress = "10.200.211.129"
  ttl       = 3600
}
vintury commented 2 years ago

I tried to change hostname to another root domain, and all is ok. @rohit-myali do you know limitations for creating domains?

$ terraform apply -auto-approve
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
Terraform will perform the following actions:
  # module.test_dns.citrixadc_dnsaddrec.dnsaddrec will be created
  + resource "citrixadc_dnsaddrec" "dnsaddrec" {
      + hostname  = "hohoho.uz"
      + id        = (known after apply)
      + ipaddress = "10.200.211.129"
      + ttl       = 3600
    }
Plan: 1 to add, 0 to change, 0 to destroy.
module.test_dns.citrixadc_dnsaddrec.dnsaddrec: Creating...
module.test_dns.citrixadc_dnsaddrec.dnsaddrec: Creation complete after 0s [id=hohoho.uz]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

I think terraform provider can't create fake record if same record registered on root zone. But citrix adc has not same problems, and You can add fake record manually.

> add dns addRec hohoho.net 11.1.1.1
 Done
BAu0002 commented 2 years ago

I have the same issue with real data. I ran it to generate 73 records and it fail 39 times with the same 1074 error code I ran it again and it generate 20 and fail 19 times with the same 1074 error code I ran it again and it generate 10 and fail 9 times with the same 1074 error code etc.

We have two netscaler for resilience. What is interesting is that I ran it on the inactive netscaler and I saw no issues. The netscaler that is causing the issue is the active netscaler.

What is also interesting is that when I look at the A Records in the active netsclaer, I briefly saw an A Record (which failed) with type=proxy, when I look again it was gone.

slauger commented 2 years ago

What is also interesting is that when I look at the A Records in the active netsclaer, I briefly saw an A Record (which failed) with type=proxy, when I look again it was gone.

I also had this issue once. The problem is that you cannot create a a record for a record which is already in the cache (proxy) (e.g. because you did a dig/ping on the shell or a VPN client requested a lookup for the domain).

My workaround is the following - i flush the cache on and create the record manually.

flush proxyRecords
add dns addRec mdm.example.com 192.168.8.50 -ttl 60

And then i imported the records in terraform instead of creating them with terraform.

terraform import citrixadc_dnsaddrec.dnsaddrec.mdm_record mdm.example.com

Maybe the terraform provider could check for existing proxy records first before creating the real record. But in my opinion this is a general problem in the Nitro API design.

BAu0002 commented 2 years ago

I'm using terragrunt and thinking of putting a catch on the error and retry. That might work around it, if try it enough time but not great.

rohit-myali commented 2 years ago

Hello Everyone, We have fixed this issue and it is currently being reviewed. It will be updated in our next release. I will update the same here.

Thanks, Rohit

rohit-myali commented 1 year ago

Hello Everyone, We have fixed this issue and it is been released in Terraform registry, version 1.27.0. Please find the link to the documentation of citrixadc_dnsaddrec here