Home > Software engineering >  Concatenate declared variable with random string
Concatenate declared variable with random string

Time:05-27

It is possible, using Terratest, to declare a tfvars file with the following variable:

bar = {
  name   = "test"
  domain = "test.com"
  regions = [
    { location = "France Central", alias = "france" }
  ]
}

But include a random prefix to the bar.domain string inside the go code?

I'm using terraformOptions as follows:

terraformOptions := &terraform.Options{
        TerraformDir: sourcePath,
        VarFiles:     []string{variablesPath   "/integration.tfvars"},
}

CodePudding user response:

It is not ideal for one to make use of the tfvars file directly to take the input in case of tests. More on this here

To answer your question :

You can use something similar to this :

options := terraform.Options{
        TerraformDir: "sourcePath",
        Vars: map[string]interface{}{
                "name":  "test",
                "domain": addRandomprefix() "test.com",
                "region ":    map[string]interface{}{
                    "location" : "France Central",
                    "alias" : "france",
                },
        },
    }

Just create your own custom addRandomprefix() method. I hope this helps :)

  • Related