I have a Terraform config that looks like this:
resource "random_string" "foo" {
length = 31
special = false
}
resource "aws_ssm_parameter" "bar" {
name = "baz"
type = "SecureString"
value = random_string.foo.result
lifecycle {
ignore_changes = [value]
}
}
The idea is that on the first terraform apply
the bar
resource will be stored in baz
in SSM based on the value of foo
, and then on subsequent calls to apply
I'll be able to reference aws_ssm_parameter.bar.value
, however what I see is that it works on the first run, stores the newly created random value, and then on subsequent runs aws_ssm_parameter.bar.value
is empty.
If I create a aws_ssm_parameter
data source that can pull the value correctly, but it doesn't work on the first apply
when it doesn't exist yet. How can I modify this config so I can get the value stored in baz
in SSM and work for creating the value in the same config?