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

Interpolation Support for URL #11

Closed
leflamm opened this issue Nov 5, 2018 · 4 comments
Closed

Interpolation Support for URL #11

leflamm opened this issue Nov 5, 2018 · 4 comments

Comments

@leflamm
Copy link

leflamm commented Nov 5, 2018

Hi,

I'm trying to use this ElasticSearch provider for Terraform.

My ElasticSearch endpoint URL is not static. There's Terraform code responsible for creating the ElasticSearch cluster (AWS ElasticSearch Service) and there's Terraform code responsible for configuring indexes.
So I have a module creating the ES cluster that outputs the cluster's endpoint (aws_elasticsearch_domain.<name>.endpoint) that I need to use to configure your ElasticSearch provider.

provider "elasticsearch" {
  url = "${module.es.endpoint}"
  version  = "0.5.0"
  insecure = true
}

It seems like the variable interpolation doesn't work here. When setting an explicit value (like https://<blabla>.eu-central-1.es.amazonaws.com) it works fine. But using a variable (module output in this case) has the same result as an empty string:

Error: Error refreshing state: 1 error(s) occurred:

* provider.elasticsearch: health check timeout: no Elasticsearch node available

[terragrunt] 2018/11/05 17:52:34 Hit multiple errors:
exit status 1

So my questions are

  1. is my interpretation correct - variable interpolation does not work for url?
  2. how could I otherwise use a previously unknown endpoint URL?

Cheers + thanks, Christian

@phillbaker
Copy link
Owner

Hi @leflamm thanks for opening an issue.

What's interesting is that at one point in terraform (I'd guess summer of 2017), this did work since I was using a similar approach. More recently, I know that it does not work, and the only workaround was to hardcode the url endpoint - definitely a bummer.

What's interesting is that the current terraform provider docs do say that this type of provider configuration is not supported: https://www.terraform.io/docs/configuration/providers.html#interpolation.

Anecdotally, I've definitely seen some issues with using outputs of modules in other resources, e.g.:

Some of the workarounds above might also work in this case.

@leflamm
Copy link
Author

leflamm commented Nov 5, 2018

Hi @phillbaker thanks for your reply.

Seems like I was on the wrong track here.

I had a look at the actual output value ${module.es.endpoint} which is taken from aws_elasticsearch_domain.<name>.endpoint and compared it with the hard-coded value that did work (https://<blabla>.eu-central-1.es.amazonaws.com). I noticed that aws_elasticsearch_domain.<name>.endpoint doesn't come with the prefix https://. So I changed the provider configuration to

provider "elasticsearch" {
  url = "https://${module.es.endpoint}"
  version = "0.5.0"
  insecure = true
}

... and this seems to work fine!

Thanks + cheers, Christian.

@phillbaker
Copy link
Owner

Pulling in from #111 for reference, this could probably be achieved by applying the underlying module first. E.g.:

terraform apply -target=my.elasticsearch.cluster.module
...
terraform apply # entire plan

@john-delivuk-rl
Copy link
Contributor

Created #119 to address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants