Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare - SRV DNS records #5732

Closed
SystemZ opened this issue Mar 19, 2016 · 13 comments
Closed

Cloudflare - SRV DNS records #5732

SystemZ opened this issue Mar 19, 2016 · 13 comments

Comments

@SystemZ
Copy link

SystemZ commented Mar 19, 2016

I'm trying to add SRV record but there is an error with cloudflare API

Error applying plan:

1 error(s) occurred:

* cloudflare_record.ts3_official: Failed to create CloudFlare Record: API Error: Invalid service value.

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Version

systemz@pc:~/Project/Infra/$ terraform -v
Terraform v0.6.13

Configuration for this SRV

resource "cloudflare_record" "ts3_official" {
    domain = "${var.cloudflare_domain}"
    name = "_ts3._udp.example.com."
    value = "0 0 9987 ts3.example.com."
    type = "SRV"
    ttl = 300
}
@stack72
Copy link
Contributor

stack72 commented Mar 27, 2016

Hi @SystemZ

I believe this is due to the 0 values in the call. Currently, Terraform has a known issue with retying to set values to 0

This is being worked on as part of #5694

When that is merged, I can have a look at this one

Paul

@SystemZ
Copy link
Author

SystemZ commented Mar 30, 2016

I tried using 5 instead of 0 but effect is still the same.

resource "cloudflare_record" "ts3_official" {
    domain = "${var.cloudflare_domain}"
    name = "_ts3._udp.example.com."
    value = "5 5 9987 ts3.example.com."
    type = "SRV"
    ttl = 300
}

I have just one record to add with SRV so it's not a big problem for me right now :) Just did it manually but maybe in future someone will need some serious number of this to configure.

@arthur-s
Copy link

i have the same issue, i cannot insert record via API (version 4)

@arthur-s
Copy link

It is possible to create a SRV record via API v4 (see the documentation, section describing a record creation, and click Defenition button)

@eatsleepandcode
Copy link

I have also an issue to create SRV records via cloudflare provider with Terraform 0.8.2.

The resource is similar to the one above, but my respponse is another:

Failed to create record: error from makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":1004,\"message\":\"DNS Validation Error\",\"error_chain\":[{\"code\":9036,\"message\":\"\"}]}],\"messages\":[],\"result\":null}"

Code 1004 means "Cannot find a valid zone", but I can't find code 9036 in the Cloudflare docu.

@eatsleepandcode
Copy link

I tried to use the CloudFlare API directly as described in their docu with required parameters, but I get the same error code 1004 (https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record).
So I clicked everything I needed for my SRV together in FireFox Browser in CloudFlare AdminUI and observed the POST request to CloudFlare with FireBug.

See below my CURL Script which works for me now:
It seems, that additional parameters are required. I think they need to be implemented for Terraform CloudFlare provider for SRV records.

curl -X POST "https://api.cloudflare.com/client/v4/zones/"$zone_id"/dns_records" \ -H "X-Auth-Email: "$auth_mail \ -H "X-Auth-Key: "$auth_key \ -H "Content-Type: application/json" \ --data '{"zone_name":"example.com","zone_id":"'$zone_id'","type":"SRV","name":"_whatyouwant._tcp.example.com.","content":"SRV 0 0 8080 foo.example.com.","data":{"priority":0,"weight":0,"port":8080,"target":"foo.example.com","service":"_whatyouwant","proto":"_tcp","name":"example.com"},"proxied":false,"proxiable":false,"ttl":300,"priority":1}'

@arthur-s
Copy link

arthur-s commented Jan 9, 2017

@eatsleepandcode so you solved your problem?

@eatsleepandcode
Copy link

@arthur-s No. I'm still not able to use the Cloudflare provider to create a Cloudflare_record of type "SRV". I perform now a local-exec with a shellscript (the CURL above) to create the SRV records.
It's a "workaround".

What I meant is, that using the Cloudflare API with curl for SRV record as described in Cloudflare docu throws the same error code as using Terraform. So I fetched the correct working curl with firebug from firefox. I think there are some missing attributes for the Terraform implementation.

@bkleef
Copy link

bkleef commented Feb 8, 2017

This is still the case with Terraform v0.8.6.

resource "cloudflare_record" "1" {
  domain = "example.com"
  name   = "_crate._tcp.example.com"
  value  = "0 0 crate1.ams1.example.com"
  type   = "SRV"
  ttl    = 120
}
* cloudflare_record.1: Failed to create record: error from makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":1004,\"message\":\"DNS Validation Error\",\"error_chain\":[{\"code\":9036,\"message\":\"\"}]}],\"messages\":[],\"result\":null}"
2017/02/08 23:28:03 [TRACE] [walkApply] Exiting eval tree: cloudflare_record.1
2017/02/08 23:28:03 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "cloudflare_record.1"
2017/02/08 23:28:03 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.count"
2017/02/08 23:28:03 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.zone"
2017/02/08 23:28:03 [ERROR] Shadow graph error: 1 error(s) occurred:

* cloudflare_record.1: Failed to create record: error from makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":1004,\"message\":\"DNS Validation Error\",\"error_chain\":[{\"code\":9036,\"message\":\"\"}]}],\"messages\":[],\"result\":null}"
2017/02/08 23:28:03 [DEBUG] plugin: waiting for all plugin processes to complete...
Error applying plan:

1 error(s) occurred:

2017/02/08 23:28:03 [DEBUG] plugin: terraform: cloudflare-provider (internal) 2017/02/08 23:28:03 [DEBUG] plugin: waiting for all plugin processes to complete...
* cloudflare_record.1: Failed to create record: error from makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":1004,\"message\":\"DNS Validation Error\",\"error_chain\":[{\"code\":9036,\"message\":\"\"}]}],\"messages\":[],\"result\":null}"

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

I've added a SRV record by Cloudflares webinterface and checked for the JSON structure:

curl -X GET "https://api.cloudflare.com/client/v4/zones/b4a2d605fc5f131f605de9587059a831/dns_records?type=SRV" \
     -H "X-Auth-Email: ${CLOUDFLARE_EMAIL}" \
     -H "X-Auth-Key: ${CLOUDFLARE_TOKEN}" \
     -H "Content-Type: application/json"
{
   "result":[
      {
         "id":"c7fd9d65610ee217a890d3086f040736",
         "type":"SRV",
         "name":"_crate._tcp.example.com",
         "content":"0\t4300\tcrate1.ams1.example.com",
         "proxiable":false,
         "proxied":false,
         "ttl":120,
         "locked":false,
         "zone_id":"b4a2d605fc5f131f605de9587059a831",
         "zone_name":"example.com",
         "modified_on":"2017-02-08T22:22:53.126829Z",
         "created_on":"2017-02-08T22:22:53.126829Z",
         "meta":{
            "auto_added":false
         },
         "data":{
            "service":"_crate",
            "proto":"_tcp",
            "name":"example.com",
            "priority":0,
            "weight":0,
            "port":4300,
            "target":"crate1.ams1.example.com"
         }
      }
   ],
   "result_info":{
      "page":1,
      "per_page":20,
      "total_pages":1,
      "count":1,
      "total_count":1
   },
   "success":true,
   "errors":[

   ],
   "messages":[

   ]
}

Where you can add a new record successfully like this:

curl -X POST "https://api.cloudflare.com/client/v4/zones/b4a2d605fc5f131f605de9587059a831/dns_records" \
     -H "X-Auth-Email: ${CLOUDFLARE_EMAIL}" \
     -H "X-Auth-Key: ${CLOUDFLARE_TOKEN}" \
     -H "Content-Type: application/json" \
     --data '{"type":"SRV","name":"_crate._tcp.example.com.","content":"SRV 0 0 4300 crate1.ams1.example.com.","ttl":120,"data":{"priority":0,"weight":0,"port":4300,"target":"crate1.ams1.example.com.","service":"_crate","proto":"_tcp","name":"example.com."},"proxied":false}'

@bkleef
Copy link

bkleef commented Feb 9, 2017

Anyway a fix would be great because upon deletion of resources (by reducing for example count) Terraform leaves these SRV-records (created by curl):

resource "null_resource" "crate_srv" {
  count = "${var.count}"

  provisioner "local-exec" {
    command = <<EOT
curl -X POST "https://api.cloudflare.com/client/v4/zones/b4a2d605fc5f131f605de9587059a831/dns_records" \
-H "X-Auth-Email: ${var.cloudflare_email}" \
-H "X-Auth-Key: ${var.cloudflare_token}" \
-H "Content-Type: application/json" \
--data '{"type":"SRV","name":"${module.crate.discovery_service}.${module.crate.discovery_protocol}.${var.tld}.","content":"SRV 0 0 ${module.crate.transport_port} ${element(module.docker.name, count.index)}.${var.tld}.","ttl":120,"data":{"priority":0,"weight":0,"port":${module.crate.transport_port},"target":"${element(module.docker.name, count.index)}.${var.tld}.","service":"${module.crate.discovery_service}","proto":"${module.crate.discovery_protocol}","name":"${var.tld}."},"proxied":false}'
EOT
  }
}

@eatsleepandcode
Copy link

@bkleef You did the same like me with inspecting the JSON and creating CURL script :-)

@bkleef
Copy link

bkleef commented Feb 10, 2017

@stack72 I read your initial response to @SystemZ. Any update on this?

@ghost
Copy link

ghost commented Apr 11, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants