wykydtronik
wykydtronik

Reputation: 108

terraform replace() - Invalid value for "str" parameter: string required

When attempting to upgrade to Terraform 0.12 I get the following error:

Error: Invalid function argument

  on ../../../../../modules/aws/mybox/main.tf line 85, in resource "aws_route53_record" "this":
  85:   name = "ip-${replace(module.this_mybox.private_ip[0], ".", "-")}"
    |----------------
    | module.this_mybox.private_ip[0] is tuple with 1 element

Invalid value for "str" parameter: string required.

Looking at the custom module below, I can't seem to use the replace() function in the string...

resource "aws_route53_record" "this" {
  name = "ip-${replace(module.this_mybox.private_ip[0], ".", "-")}"
  type = "A"
  zone_id = "${var.dns_zone_id}"
  records = "${module.this_mybox.private_ip[0]}"
  ttl = "600"
}

The goal of the module is to spin up an EC2 based on custom parameters. Along with that, there's a few moving parts including adding a private dns record. I've named it based off of this_mybox.private_ip[0]. In Terraform 0.11.14 it worked fine; but I am roadblocked on the upgrade due to this.

Is there another approach for using replace() in the aws_route53_record name?

Upvotes: 1

Views: 8339

Answers (1)

nicoring
nicoring

Reputation: 683

The error message says that module.this_mybox.private_ip[0] is a tuple and that is why replace fails. This value is also used here records = "${module.this_mybox.private_ip[0]}", which requires a list. We cannot see the value of module.this_mybox.private_ip[0] in your question, but based on the error message I would suggest to access the IP address within the tuple with module.this_mybox.private_ip[0][0].

Upvotes: 4

Related Questions