1
votes

i am creating rds server using terraform. I pass options group using list variable. The options groups variable in variable.tf like below

options = [
   {
    option_name = "SQLSERVER_BACKUP_RESTORE"

    option_settings=[
      {
      name  = "IAM_ROLE_ARN"
      value = "${role_arn}"
    },
  ]
},

i want replace the "${role_arn}" variable in main.tf . Can any one help with syntax ?

1

1 Answers

4
votes

I solve this kind of issue using terraform template files.

  1. Move your json to a separate file;
  2. update yout json to use Terraform template syntax;
  3. add a data resource to render and parse your template;
  4. reference your rendered template in your resource.

Let's say that you'll need something like:

resource "provider_resource" "name" {
  property = "value"
  options = [
    {
      option_name = "SQLSERVER_BACKUP_RESTORE"
      option_settings = [
        {
          name  = "IAM_ROLE_ARN"
          value = "${role_arn}"
        },
      ]
    }
  ]
}

after the change you will have something like:

data "template_file" "json_template" {
  template = file("path/to/file.json")
  vars = {
    role_arn = var.dynamic_value
  }
}

resource "provider_resource" "name" {
  property = "value"
  options = data.template_file.json_template.rendered
}