1

Can we use terraform variables in Cloudwatch-agent.json config file ?

I am publishing Logs to a log group which needs to have a workspace name (TF Variable) included in its name.

Now when we are including the variable in JSON file its not pushing the logs. Below is my JSON file. and var.name is the workspace TF variable.


"logs": {
    "logs_collected": {
        "files": {
            "collect_list": [
            {
                "file_path": "c:\\ProgramData\\Amazon\\EC2-Windows\\Launch\\Log\\UserdataExecution.log",
                "log_group_name": "${var.name}-cloudwatch-agentlog",
                "log_stream_name": "{instance_id}-user-data-log",
                "timezone": "UTC",
                "timestamp_format": "%H: %M: %S%Y%b%-d"
            },

            {
                "file_path": "c:\\AgentLifeCycleHandler\\log.txt",
                "log_group_name": "${var.name}-cloudwatch-agentlog",
                "log_stream_name": "{instance_id}-AgentLifecycleHandler-log",
                "timezone": "UTC",
                "timestamp_format": "%H: %M: %S%Y%b%-d"
            }
        ]
        }
        
    }

}

1 Answers1

0

Yes, you can through templatefile. Your json file would become the template to which you pass TF variables using templatefile function.

Marcin
  • 215,873
  • 14
  • 235
  • 294