Terraform: implementing Using Terraform 1.4.5 and Local File Data Source for Dynamic Configuration Files
I'm prototyping a solution and I'm working on a personal project and I've been struggling with this for a few days now and could really use some help. I'm currently working with an scenario with Terraform 1.4.5 when trying to use the `local_file` data source to dynamically read configurations from a file. I have a local configuration file (`config.json`) that I want to use to set some variables in my Terraform script, but I'm getting a `Invalid argument` behavior. Hereβs what I have so far: ```hcl provider "aws" { region = "us-west-2" } data "local_file" "config_file" { filename = "config.json" } resource "aws_s3_bucket" "my_bucket" { bucket = jsondecode(data.local_file.config_file.content).bucket_name acl = jsondecode(data.local_file.config_file.content).acl } ``` The `config.json` file contains: ```json { "bucket_name": "my-awesome-bucket", "acl": "private" } ``` When I run `terraform apply`, I receive the following behavior: ``` behavior: Invalid function argument on main.tf line 7, in resource "aws_s3_bucket" "my_bucket": 7: bucket = jsondecode(data.local_file.config_file.content).bucket_name Invalid value for "json" argument: jsondecode expects a valid JSON string. ``` I've double-checked the file path, and it's correctly pointing to `config.json`. When I run `terraform validate`, it passes without issues. I also tried printing out `data.local_file.config_file.content` using the `output` block, and it returns the correct JSON string, but I still need to access the values after decoding. Any insights on what might be going wrong here? Is there a better way to read dynamic configurations from a file in this context? I've also looked at other data sources like `template_file`, but that feels overkill for this simple configuration. Thanks in advance for your help! My development environment is Windows. This is part of a larger API I'm building. I recently upgraded to Hcl 3.11. Any help would be greatly appreciated! For context: I'm using Hcl on Ubuntu 22.04.