Why is Terraform Not Picking My Object Resource?

Advertisements I have tried many times yet Terraform can’t see my object resource. What could be wrong with my code? My bucket and bucket website resource gets created, but the object resource doesn’t. resource "aws_s3_bucket" "My_bucket" { bucket = "my-test-bucket-for-cloudfront" tags = { Name = "My bucket" } } resource "aws_s3_bucket_public_access_block" "public_bucket" { bucket =… Read More Why is Terraform Not Picking My Object Resource?

How to override the .go code of a resource argument in terraform?

Advertisements There is a 1024 character restriction set for the AWS aws_alb_listener_rule resource that is imposed here. I need to parameterise this character limit as the message body I want to send in the response is longer than 1024 characters. I am new to terraform, is it possible to make such alterations to the .go… Read More How to override the .go code of a resource argument in terraform?

Cannot use subnet ids created through the same terraform configuration with aws_route_table_association

Advertisements I am trying to use subnet IDs, created by the resource "aws_subnet" "public" {…} block, in to the resource "aws_route_table_association" "public" {…} block, but it is giving the error: Error: Invalid for_each argument on main.tf line 69, in resource "aws_route_table_association" "public": 69: for_each = toset(tolist([for subnet in aws_subnet.public : subnet.id])) ├──────────────── │ aws_subnet.public is… Read More Cannot use subnet ids created through the same terraform configuration with aws_route_table_association

Can a List of Resources be used in the depends_on Property

Advertisements Can a resource’s depends_on be used against all elements in a "resource list". For example, in the resource below, the source_ids’ property is enumerated, however, I get an error when I attempt to concat() those elements in the depends_on with other elements. The code below is valid and deploys, however, I don’t know if… Read More Can a List of Resources be used in the depends_on Property

S3 bucket resource not being found using data

Advertisements I have a main.tf that looks like this: resource "aws_s3_bucket" "s3_notifications_bucket" { bucket = local.s3_bucket_name force_destroy = true } module "s3_notification" { source = "…" s3_bucket_name = local.s3_bucket_name function_name = module.lambda.lambda_function_name lambda_function_arn = module.lambda.lambda_arn } Module s3_notification uses a reference for that bucket. The reason for that is because when I am running locally,… Read More S3 bucket resource not being found using data

How to reference an output value within an iam policy as a principal using terraform

Advertisements So I have an I am policy and i want to be able to reference my athena workgroup arn as part of the principals section in my policy. Am not sure what the correct approach is for this. So far I have the following in my outputs.tf output "workgroup_arn" { description = "arn of… Read More How to reference an output value within an iam policy as a principal using terraform

How can I re-use a configuration (local module) with my Terraform project?

Advertisements I’m quite new to Terraform, so I guess I consider Terraform modules as "functions" that I can re-use but that’s wrong. I had a scenario where I had to deploy a static web site to cloudfront and s3 bucket. At first, I configured this as raw files in my project: https://github.com/tal-rofe/tf-old/tree/main/terraform/core – you can… Read More How can I re-use a configuration (local module) with my Terraform project?

Can I use an output from a resource in a provisioner which is part of the same resource?

Advertisements I’m creating an EC2 instance and attempting to capture the public IP as an output before using it in a bash script that I’d like to execute upon successfully creating the instance: output "public_ip" { value = aws_instance.example.public_ip } resource "aws_instance" "example" { ami = "ami-0a606d8395a538502" instance_type = "t2.micro" vpc_security_group_ids = [aws_security_group.sg.id] user_data =… Read More Can I use an output from a resource in a provisioner which is part of the same resource?

Terraform: aws default_tag not supported in root_block_device?

Advertisements I am trying to use the default_tag available for the aws terraform provider. Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs#argument-reference example how to use: https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block From the doc, it says: This functionality is supported in all resources that implement tags, with the exception of the aws_autoscaling_group resource. So, for all resources I have it works very well, except for… Read More Terraform: aws default_tag not supported in root_block_device?