Terraform 1.4.3: implementing Interpolating Outputs from Child Module for S3 Bucket Configuration
I'm dealing with I'm deploying to production and I'm currently working with an scenario with interpolating outputs from a child module back into my main module for an S3 bucket configuration..... The child module creates an S3 bucket and outputs its ARN, but when I try to reference this output in my main module, I receive an behavior about unknown variables. Hereβs a simplified version of my setup: In my child module (`s3_bucket_module.tf`): ```hcl resource "aws_s3_bucket" "my_bucket" { bucket = var.bucket_name } output "bucket_arn" { value = aws_s3_bucket.my_bucket.arn } ``` And in my main module where I instantiate the child module: ```hcl module "s3_bucket" { source = "./s3_bucket_module" bucket_name = "my-unique-bucket-name" } resource "aws_s3_bucket_policy" "bucket_policy" { bucket = module.s3_bucket.bucket_arn policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = "*" Action = "s3:GetObject" Resource = "${module.s3_bucket.bucket_arn}/*" }] }) } ``` When I run `terraform apply`, I get the following behavior: ``` behavior: Reference to undeclared input variable on main.tf line 10, in resource "aws_s3_bucket_policy" "bucket_policy": 10: bucket = module.s3_bucket.bucket_arn This object does not have an attribute named "bucket_arn". ``` I've verified that the output is defined correctly in the child module, and I can see it when I run `terraform output` in that module. I've also tried explicitly declaring `output` variables in the main module to capture the outputs from the child module. Does anyone know why this reference to `module.s3_bucket.bucket_arn` isn't resolving correctly? Is there something I might be missing in the way Iβm trying to use the output? How would you solve this? For reference, this is a production service. Has anyone dealt with something similar? Any advice would be much appreciated.