Error: describing SSM parameter : ParameterNotFound: used the data block to retrieve the value second time

We are using Terraform scaffold with version 1.5.7

I have successfully created an AWS SSM parameter within one of our existing components subnets using the resource "aws_ssm_parameter" block.


resource "aws_ssm_parameter" "ssm_public_subnet" {
  name        = "public-subnet-irl"
  description = "public subnet"
  type        = "String"
  value       = join(",", module.vpc_core.subnet_ids)

I attempted to reference this parameter in a different component core using the data "aws_ssm_parameter" block, which worked as expected.


data "aws_ssm_parameter" "ssm_public_subnet" {
  name = "public-subnet-irl"

However, when I tried to use the same data block in same region yet another different component lambda, I encountered a describing SSM parameter (public-subnet-irl): ParameterNotFound error, despite the presence of the parameter in the AWS console. components/lambda/

data "aws_ssm_parameter" "ssm_public_subnet" {
  name = "public-subnet-irl"


│ Error: describing SSM parameter (kedm-public-subnet-irl): ParameterNotFound:
│   with data.aws_ssm_parameter.ssm_public_subnet,
│   on line 11, in data "aws_ssm_parameter" "ssm_public_subnet":
│   11: data "aws_ssm_parameter" "ssm_public_subnet" {
ERROR: Terraform plan failed

I have also tried to run terraform apply but got the same error message

Expected scenario to use the data block to retrieve the value second time in a different component

Thank you

HI @saivarun2512,

Data sources are read during when generating the plan, so if you use a data source to represent something which is not going to be created until apply, that data source is going to fail or return incorrect data. You should use the values from the aws_ssm_parameter.ssm_public_subnet managed resource throughout your configuration to avoid the problem.

Hello @jbardin,

So, I had to do this manually pass the subnet_id(subnet-1374trfg38wgf8) manually. And the update with data.aws_ssm_parameter.ssm_public_subnet.value everytime?

But I directly used the data.aws_ssm_parameter.ssm_public_subnet.value block to retrive the value in core component.

I’m not sure I understand what you’re asking.

The value in the .value attribute is coming from somewhere else in your configuration, and that value can be referenced within, and passed into whatever modules you need without the use of the data source. Using the data source can’t work, because that will attempt to read the value before the resource has created or updated it.

A data source like this is used when you do not have the corresponding resource and it’s inputs already in your configuration, and need to look those up via the remote API.