News for hackers. Stuff that matters.
Re:Terraform best practices for reliability at any scale by robertlagrant on Friday August 04, 2023 @06:11PM (#37006539)
Makes sense, but how do you connect the two so e.g. credentials from one are surfaced in the other?
Re:Terraform best practices for reliability at any scale by dharmab on Friday August 04, 2023 @06:19PM (#37006635)
Use Data Sources to reference resources in a different state: https://developer.hashicorp.com/terraform/language/data-sour...
Re:Terraform best practices for reliability at any scale by robertlagrant on Saturday August 05, 2023 @03:49AM (#37009928)
Ah - I didn't think about that. Wrapping a remote call with a data source. Thanks.
Re:Terraform best practices for reliability at any scale by paulddraper on Friday August 04, 2023 @06:20PM (#37006654)
terraform_remote_state

The root module can have outputs just like any other module. These outputs can be accessed from other stacks from the backend.

And if you use CDKTF the references are handled transparently.

Re:Terraform best practices for reliability at any scale by robertlagrant on Saturday August 05, 2023 @03:50AM (#37009934)
Thanks - another good option! I seem to get slight shivers down my spine when I read terraform_remote_state, but I never actually used it, so I might be half-remembering an old opinionated blog post.
Re:Terraform best practices for reliability at any scale by no_circuit on Saturday August 05, 2023 @08:57AM (#37011572)
IMO you shouldn't be storing credentials in shared state, as suggested by the other comments, since that means that the principals able to read the state to deploy their service can also read the credentials for other services bundled in that state file. This could be the case if one had broken down the root modules into scopes/services like the linked page suggests.

It is reasonable to assume if you are using Terraform to manage your infra, than your infra likely has access to a secrets manager from your infra vendor, e.g., AWS. Instead I'd recommend using a Terraform data resource to pull a credential from the secret manager by name -- and the name doesn't even necessarily have to be communicated through Terraform state. Then the credentials could directly be fed into where it is needed, e.g., a resource like a Kubernetes Secret. One can even skip this whole thing if the service can use the secret manager api itself. Finally access to the credentials itself would be locked down with IAM/RBAC.