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

Properly handle computed fields #12

Open
vkleen opened this issue Nov 16, 2022 · 2 comments
Open

Properly handle computed fields #12

vkleen opened this issue Nov 16, 2022 · 2 comments

Comments

@vkleen
Copy link
Contributor

vkleen commented Nov 16, 2022

Computed fields in terraform come in two types. One is never settable by the user configuration and should be handled similarly to the id field hack we have right now. That is, an extra field with forced value should be set.

Others are settable by the user and should be handled similarly, but with a default value.

@vkleen vkleen added this to the Minimally viable product milestone Nov 17, 2022
@vkleen
Copy link
Contributor Author

vkleen commented Nov 25, 2022

Determining the interpolation type is possible by carefully parsing the provider schema.

A tricky issue is dealing with operations on interpolated fields. E.g. if a field foo has type a list of strings, we would like to access it as a list in Nickel. But setting foo to a default value "${foo}", so that recursive access in Nickel is possible, doesn't allow one to observe that foo should actually be a list.

@vkleen
Copy link
Contributor Author

vkleen commented Dec 19, 2022

Sometimes terraform configuration blocks need to reference themselves. HCL uses a self keyword for that. The documentation indicates that in the example below using ${aws_instance.web.public_ip} instead of ${self.public_ip} would not be accepted.

resource "aws_instance" "web" {
  # ...

  # Establishes connection to be used by all
  # generic remote provisioners (i.e. file/remote-exec)
  connection {
    type     = "ssh"
    user     = "root"
    password = var.root_password
    host     = self.public_ip
  }

  provisioner "remote-exec" {
    inline = [
      "puppet apply",
      "consul join ${aws_instance.web.private_ip}",
    ]
  }
}

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

1 participant