Last active
October 25, 2020 12:30
-
-
Save WhatsARanjit/33ef22b33c9f3409b34c8841a0df06fb to your computer and use it in GitHub Desktop.
consul-terraform-sync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "services" { | |
description = "Consul Terraform Sync creates this variable" | |
} | |
resource "local_file" "tags" { | |
content = <<EOT | |
%{ for node in var.services ~} | |
${node.address}: | |
%{ for tag in node.tags ~} | |
- ${tag} | |
%{ endfor ~} | |
%{ endfor ~} | |
EOT | |
filename = "/tmp/tags.txt" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ consul agent -dev > /dev/null 2>&1 & | |
[1] 30788 | |
$ consul services register -name ranjit -tag=one | |
Registered service: ranjit | |
$ consul-terraform-sync -config-file tags.hcl & | |
[2] 30794 | |
$ cat /tmp/tags.txt | |
127.0.0.1: | |
- one | |
$ consul services register -name ranjit -tag=one -tag=two -tag=three | |
Registered service: ranjit | |
$ cat /tmp/tags.txt | |
127.0.0.1: | |
- one | |
- three | |
- two | |
$ kill %2 | |
$ | |
[2] + 30794 done consul-terraform-sync -config-file tags.hcl | |
$ kill %1 | |
$ | |
[1] + 30788 exit 1 consul agent -dev > /dev/null 2>&1 | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment