DEV Community

Discussion on: Terraform: use a variable's value to define another variable

Collapse
 
drewmullen profile image
drewmullen

worked for for me with an ssm parameter value:

resource "aws_ssm_parameter" "foo" {
  name  = "foo"
  type  = "String"
  value = var.nickname != "" ? var.nickname : var.fullname
}

Enter fullscreen mode Exit fullscreen mode
$ tf apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_ssm_parameter.foo will be created
  + resource "aws_ssm_parameter" "foo" {
      + arn       = (known after apply)
      + data_type = (known after apply)
      + id        = (known after apply)
      + key_id    = (known after apply)
      + name      = "foo"
      + tier      = "Standard"
      + type      = "String"
      + value     = (sensitive value)
      + version   = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_ssm_parameter.foo: Creating...
aws_ssm_parameter.foo: Creation complete after 4s [id=foo]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Enter fullscreen mode Exit fullscreen mode
Collapse
 
spodalov profile image
Sergey Podalov

It woks in a resource section and in a output section but it does not work if try to set an input variable this way.

Thread Thread
 
drewmullen profile image
drewmullen

correct. this is a work around for similar functionality