3 ms·
Makes sense, but how do you connect the two so e.g. credentials from one are surfaced in the other?
by robertlagrant 3y ago
Makes sense, but how do you connect the two so e.g. credentials from one are surfaced in the other?
- dharmab 3y agoUse Data Sources to reference resources in a different state: https://developer.hashicorp.com/terraform/language/data-sources https://developer.hashicorp.com/terraform/language/data-sour...
- robertlagrant 3y agoAh - I didn't think about that. Wrapping a remote call with a data source. Thanks.
- deleted 3y ago[deleted]
- paulddraper 3y agoterraform_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.
- robertlagrant 3y agoThanks - 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.
- no_circuit 3y agoIMO 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.