Retrieve S3 bucket name from terraform module

Viewed 1218

I am using the following module to create cloudfront with s3 bucket:

module "cloudfront" {
              source = /modules/cloudfront-w-s3/aws
        ......
        }

Now my questions is. How I can retrieve the s3 bucket or arn from this module and use it as output?

1 Answers

What does the child module (the one you are calling) look like in its main.tf?

If you are using this link for the S3 resource then in your child module create an outputs.tf file. Create an output with whatever name you want, s3_arn as an example, with a value of aws_s3_bucket.<RESOURCE_NAME>.arn.

In your root module create an outputs.tf and use the same code above but for the value use module.<MODULE_NAME>.s3_arn. In your main.tf for the parent module you should be able to access that output using the syntax of module.<MODULE_NAME>.s3_arn.

Related