Miguel Zablah
07/28/2025, 4:07 PM!terraform.output and !terraform.state interpolations? I will like to do simple add a string at the end of the output like for secrets.
so !terraform.output/!terraform.state will get the secret ARN:
arn:aws:secretsmanager:REGION:AWS:secret:SUPER_SECRET_NAME
And I will like to append this string to get a specific secret:
:username::
so at the end the yaml will look like this:
username: 'arn:aws:secretsmanager:REGION:AWS:secret:SUPER_SECRET_NAME:username::'
Is there a way to do this? I have try many ways but I continue to use atmos.Component bc it works better for meAndriy Knysh (Cloud Posse)
07/28/2025, 4:46 PM!terraform.output and !terraform.state YAML functions.
(this will be in the docs in the next release)
## Using YQ Expressions to modify values returned from the remote state
Since the `output` parameter of the `!terraform.state` function is a [YQ](https://mikefarah.gitbook.io/yq) expression,
you can use [YQ pipes](https://mikefarah.gitbook.io/yq/operators/pipe) and
[YQ operators](https://mikefarah.gitbook.io/yq/operators) (including [YQ string concatenation functions](https://mikefarah.gitbook.io/yq/operators/add#string-concatenation)
and [YQ arithmetic functions](https://mikefarah.gitbook.io/yq/operators/add))
to modify the values returned from the remote state.
For example, suppose you have an `aurora-postgres` Atmos component which has the output `master_hostname`.
To read the output without modification, you can use the following expressions:
```yaml
postgres_url: !terraform.state aurora-postgres master_hostname
yaml
postgres_url: !terraform.state aurora-postgres .master_hostname
To prepend and append strings to the output, you can use YQ pipes and the add function (+ operator):
yaml
postgres_url: !terraform.state aurora-postgres ".master_hostname | ""jdbc:postgresql://"" + . + "":5432/events"""
:::note
The double quotes are required around the whole YQ expression, and around the strings inside the YQ expression,
hence the double-double quotes "" to escape it.
:::
After the !terraform.state function is executed, the postgres_url variable will have the final value similar to:
yaml
postgres_url: "jdbc:postgresql://aurora-postgres-cluster-writer.prod.plat.mydomain.net:5432/events"
For more details, review the following docs:
- [YQ pipe](https://mikefarah.gitbook.io/yq/operators/pipe)
- [YQ operators](https://mikefarah.gitbook.io/yq/operators)
- [YQ string concatenation](https://mikefarah.gitbook.io/yq/operators/add#string-concatenation)
- [YQ add function](https://mikefarah.gitbook.io/yq/operators/add)```Andriy Knysh (Cloud Posse)
07/28/2025, 4:48 PMoutput parameter is a YQ expression, you can use YQ pipes, string functions and other functions to transform a value returned from the remote state
(this is not the prettiest syntax, but it works. We'll think about how to simplify it and add "native" Atmos support to transform the values returned from remote state)Andriy Knysh (Cloud Posse)
07/28/2025, 4:48 PMMiguel Zablah
07/28/2025, 4:51 PM" wrap the includes the output key! perfect! Let me try it now and yeah adding this to the docs will be just perfect I was looking for this the other day there hehehe 🙂Miguel Zablah
07/28/2025, 6:08 PM```yaml
postgres_url: !terraform.state aurora-postgres ".master_hostname | . + "":5432/events"""
but the value is:
yaml
postgres_url: {
"jdbc:postgresql://aurora-postgres-cluster-writer.prod.plat.mydomain.net:5432/events": null
}
is this expected?```Miguel Zablah
07/28/2025, 7:15 PM:: is the issue is just adding one : and the other it looks like creates the map of stringsAndriy Knysh (Cloud Posse)
07/28/2025, 7:18 PMMiguel Zablah
07/28/2025, 7:19 PMAndriy Knysh (Cloud Posse)
07/28/2025, 8:44 PM: at the end, it generates an invalid YAML (: signifies a start of a map).
this is currently not supported by Atmos and i'm not sure yet how to handle it.
we'll have to review it in more details
@Miguel Zablah do yu need to have : at the end? (w/o it, the expression works OK)Miguel Zablah
07/28/2025, 8:59 PMarn:aws:secretsmanager:region:aws_account_id:secret:secret-name:json-key:version-stage:version-id
But maybe I can modify my tf to allow only 'json-key' as the last part of the secret instead of' expecting empty or value for 'version-stage' and 'version-id'Miguel Zablah
07/28/2025, 9:01 PMAndriy Knysh (Cloud Posse)
07/28/2025, 9:05 PMMiguel Zablah
07/28/2025, 9:47 PM:: if we use one of json-key , version-stage or version-id but it kinda feels wrong hahahaMiguel Zablah
07/28/2025, 9:48 PMatmos.Compose while I think about this change maybe is worth it and it might be accomplish with a regex but idk it feels wrong hahaha I wish there was a way to do this with YQ and !terraform.stateAndriy Knysh (Cloud Posse)
07/28/2025, 9:53 PM!terraform.state - return the "correct" (composed) value, but if there is : at the end, the YAML parser treats it as the start of a map.Andriy Knysh (Cloud Posse)
07/28/2025, 9:54 PMMiguel Zablah
07/28/2025, 10:06 PMshirkevich
08/05/2025, 8:41 AM: in the end, via !terraform.state it translates to a map...
will use atmos.Component meanwhile