Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Using a string in JSON format in Terraform variables

$
0
0

I am creating some resources using the for_each method on Terraform version 0.14.15. The resource has an attirbute, input_parameters that takes a string in JSON format as its value. I am defining this value in a map variable utilizing separate objects. The value I am specifying as a string in JSON format, and I am getting an error upon execution that I need to declare a string. Any insight on fixing this error would be helpful. Below is how I have my resource and variable declared.

Resource

resource "aws_config_config_rule" "managed_rules" {  for_each         = var.managed_rules  name             = each.value.name  description      = each.value.description  input_parameters = each.value.input_parameters  source {    owner             = each.value.owner    source_identifier = each.value.source_identifier  }  depends_on = [aws_config_configuration_recorder.config_recorder]}

Variable

variable "managed_rules" {  type = map(object({    name              = string    description       = string    owner             = string    source_identifier = string# Is there a variable for strings in JSON format?    input_parameters  = string  }))  default = {"1" = {      name              = "alb-http-to-https-redirection-check"      description       = "Checks whether HTTP to HTTPS redirection is configured on all HTTP listeners of Application Load Balancers. The rule is NON_COMPLIANT if one or more HTTP listeners of Application Load Balancer do not have HTTP to HTTPS redirection configured."      owner             = "AWS"      source_identifier = "ALB_HTTP_TO_HTTPS_REDIRECTION_CHECK"      input_parameters = {"MaximumExecutionFrequency" : "TwentyFour_Hours",      }  }

Error

This default value is not compatible with the variable's type constraint:element "2": attribute "input_parameters": string required.

After updating code with jsonencode function and changing input_parameters to any, this is the error:

    This default value is not compatible with the variable's type constraint:collection elements cannot be unified.

Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>