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

config: Add joinf function? #1812

Closed
radeksimko opened this issue May 5, 2015 · 2 comments
Closed

config: Add joinf function? #1812

radeksimko opened this issue May 5, 2015 · 2 comments

Comments

@radeksimko
Copy link
Member

I caught myself writing the following code I don't like at all:

resource "aws_instance" "worker" {
  ami = "${lookup(var.aws_coreos_ami, var.aws_region)}"
  instance_type = "m3.medium"
  availability_zone = "${var.aws_az_name}"

  user_data = <<USER_DATA
#cloud-config
coreos:
  flannel:
    etcd_endpoints: http://${aws_instance.etcd.0.private_ip}:4001,http://${aws_instance.etcd.1.private_ip}:4001,http://${aws_instance.etcd.2.private_ip}:4001
USER_DATA
}

See the list of etcd endpoints which is not scalable at all, just because I have to provide a list of IPs with protocol + port number.

So I was thinking this could be much easier and scalable with hypothetical function joinf (name coming from join + format):

resource "aws_instance" "worker" {
  ami = "${lookup(var.aws_coreos_ami, var.aws_region)}"
  instance_type = "m3.medium"
  availability_zone = "${var.aws_az_name}"

  user_data = <<USER_DATA
#cloud-config
coreos:
  flannel:
    etcd_endpoints: ${joinf(",", "http://%s:4001", aws_instance.etcd.*.private_ip)}
USER_DATA
}

Any ideas for better name / reservations? I may send a PR at some point, but it would be nice to have a few 👍 or 👎 (+ reasons ideally).

@radeksimko
Copy link
Member Author

This can be now done using a new function formatlist:

${join(",", formatlist("http://%s:4001", aws_instance.etcd.*.private_ip))}

I'm gonna close this as the above approach feels a bit cleaner than having one function that does two things (join + formatlist).

Thanks @josharian for making it happen! 😺

@ghost
Copy link

ghost commented May 2, 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 2, 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

1 participant