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

Strange behaviour with lists (I think?) #3201

Closed
johnhamelink opened this issue Sep 9, 2015 · 4 comments
Closed

Strange behaviour with lists (I think?) #3201

johnhamelink opened this issue Sep 9, 2015 · 4 comments

Comments

@johnhamelink
Copy link

Hey guys,

Forward

I was struggling with an issue I was having with piping a list through a module and then looping through it with the count attribute in a resource definition. I spoke to some people on #terraform-tool on freenode, and managed to find a workaround for this issue, but to me it seems like a bug that this code doesn't work the obvious way.

Objective

I was attempting to take the output of aws_route53_zone's name_servers list, and add a nameserver record for each via cloudflare.

I came up with this: https://gist.github.com/johnhamelink/b4d315e3cad437fc1865

This code would fail on the point of trying to set the records with:

Error applying plan:

4 error(s) occurred:

* cloudflare_record.new_record.0: Failed to update CloudFlare Record: API Error: You entered '<strong>${element(split(&quot;,&quot;, module.app.route53_nameservers), count.index)}</strong>' which is not a valid authoritative host name.
* cloudflare_record.new_record.1: Failed to update CloudFlare Record: API Error: You entered '<strong>${element(split(&quot;,&quot;, module.app.route53_nameservers), count.index)}</strong>' which is not a valid authoritative host name.
* cloudflare_record.new_record.3: Failed to update CloudFlare Record: API Error: You entered '<strong>${element(split(&quot;,&quot;, module.app.route53_nameservers), count.index)}</strong>' which is not a valid authoritative host name.
* cloudflare_record.new_record.2: Failed to update CloudFlare Record: API Error: You entered '<strong>${element(split(&quot;,&quot;, module.app.route53_nameservers), count.index)}</strong>' which is not a valid authoritative host name.

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.

Workaround

After playing around a bit, I found that I could make terraform work correctly simply by joining the list by hand:

output "route53_nameservers" {
  value = "${aws_route53_zone.production_api.name_servers.0},${aws_route53_zone.production_api.name_servers.1},${aws_route53_zone.production_api.name_servers.2},${aws_route53_zone.production_api.name_servers.3}"
}

terraform.tfstate

The terraform.tfstate file includes the output from the aws_zone:

                "aws_route53_zone.production_api": {
                    "type": "aws_route53_zone",
                    "primary": {
                        "id": "DUMMY",
                        "attributes": {
                            "comment": "Managed by Terraform",
                            "id": "DUMMY",
                            "name": "api.exmaple.com",
                            "name_servers.#": "4",
                            "name_servers.0": "ns-9999.awsdns-11.org",
                            "name_servers.1": "ns-9998.awsdns-11.co.uk",
                            "name_servers.2": "ns-9997.awsdns-11.com",
                            "name_servers.3": "ns-9996.awsdns-11.net",
                            "tags.#": "0",
                            "zone_id": "DUMMY"
                        }
                    }
                }

Considering the format of the terraform.tfstate file, to me it seems like a bug that the join function seemingly cannot join together the nameservers.

@radeksimko
Copy link
Member

I believe this bug has been already fixed in #2157 and merged, just not released yet.

You can either try and build from master or wait for the next release.

@johnhamelink
Copy link
Author

Thank you, I will wait for the next release.

@phinze
Copy link
Contributor

phinze commented Mar 10, 2016

Fixed and merged and released in the past! 😀

@phinze phinze closed this as completed Mar 10, 2016
bmcustodio pushed a commit to bmcustodio/terraform that referenced this issue Sep 26, 2017
* Add notes about pty and other permit-* extensions

* Update troubleshooting

* Add an example of JSON for sign

* Fix a bug about what keys to push up
@ghost
Copy link

ghost commented Apr 27, 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 27, 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

3 participants