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

Feature Request: gsub #1029

Closed
ctro opened this issue Feb 23, 2015 · 6 comments · Fixed by #1094
Closed

Feature Request: gsub #1029

ctro opened this issue Feb 23, 2015 · 6 comments · Fixed by #1094

Comments

@ctro
Copy link

ctro commented Feb 23, 2015

I've run into a couple situations where I need to format an output string from resourceA as an input to resourceB.

As an example, suppose you want to create an aws_route53_record. The name of the record needs to be built from the public_ip of the attached node.
If the public_ip is "12.34.56.78", the record's name has to be "foo-12-34-56-78".

resource "aws_route53_record" "foo" {
zone_id = "${var.some_zone_id}"
name = ???  # "foo-${gsub('.', '-', aws_eip.foo.public_ip }"
type = "A"
ttl = "300"
records = ["${aws_eip.foo.public_ip}"]
}

The only way I can think to do this now is to write a local-exec provisioner that does string manipulation, writes a json file, and shells out to awscli. Which isn't pretty.

@pmoust
Copy link
Contributor

pmoust commented Feb 23, 2015

since adccaad

name = "foo-${join("-", ${split(".",${aws_eip.foo.public_ip})})}"

But yeah, gsub would be welcomed I guess.

@mitchellh
Copy link
Contributor

@pmoust Not exactly correct, but close: name = "foo-${join("-", split(".", aws_eip.foo.public_ip))}"

And this is a decent idea.

@pmoust
Copy link
Contributor

pmoust commented Feb 23, 2015

👍

@mwitkow
Copy link

mwitkow commented Mar 2, 2015

This would be ridiculously useful in interpolation of files.

mitchellh added a commit that referenced this issue Mar 2, 2015
config: add "replace" function [GH-1029]
@mitchellh
Copy link
Contributor

Done, see PR above for docs as well.

@ghost
Copy link

ghost commented May 4, 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 May 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants