terraformfusionauth

How to append string and variable in terraform


How can I concatenate string and a variable in terraform. I am using terraform version 1.7

Name = "Test (Environment_Name)" where environment_name will be test,stage and prod.

    resource "fusionauth_tenant" "tanant" {
  name = "Test (Environment_name)"
  email_configuration {
    default_from_name                 = "FusionAuth [Environment_name]"
    verification_email_template_id    = fusionauth_email.verification_template.id
  }

Solution

  • Examples of how to append a string and a variable.

    settings.tf:

    locals {
      bucket_prefix = "test-bucket"
    }
    

    And then you want to create three S3 buckets.

    s3.tf:

    resource "aws_s3_bucket" "a" {
      bucket = "${local.bucket_prefix}-app"
    }
    //name = test-bucket-app
    
    
    resource "aws_s3_bucket" "b" {
      bucket = local.bucket_prefix
    }
    //name = test-bucket
    
    
    resource "aws_s3_bucket" "c" {
      bucket = "my-bucket"
    }
    //name = my-bucket
    

    If you want to append a variable from var or get a name from a resource, it will follow the same pattern. It will always be:

    "${var.name.value}-my-string"