github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/docs/_docs/02_testing-best-practices/namespacing.md (about)

     1  ---
     2  layout: collection-browser-doc
     3  title: Namespacing
     4  category: testing-best-practices
     5  excerpt: >-
     6    Learn how to avoid conflicts due to duplicated identifiers.
     7  tags: ["testing-best-practices", "namespace", "id", "identifiers"]
     8  order: 203
     9  nav_title: Documentation
    10  nav_title_link: /docs/
    11  ---
    12  
    13  Just about all resources your tests create (e.g., servers, load balancers, machine images) should be "namespaced" with
    14  a unique name to ensure that:
    15  
    16  1.  You don't accidentally overwrite any "production" resources in that environment (though as mentioned in the previous
    17      section, your test environment should be completely isolated from prod anyway).
    18  1.  You don't accidentally clash with other tests running in parallel.
    19  
    20  For example, when deploying AWS infrastructure with Terraform, that typically means exposing variables that allow you
    21  to configure auto scaling group names, security group names, IAM role names, and any other names that must be unique.
    22  
    23  You can use Terratest's `random.UniqueId()` function to generate identifiers that are short enough to use in resource
    24  names (just 6 characters) but random enough to make it unlikely that you'll have a conflict.
    25  
    26  ```go
    27  uniqueId := random.UniqueId()
    28  instanceName := fmt.Sprintf("terratest-http-example-%s", uniqueId)
    29  
    30  terraformOptions := &terraform.Options {
    31    TerraformDir: "../examples/terraform-http-example",
    32    Vars: map[string]interface{} {
    33      "instance_name": instanceName,
    34    },
    35  }
    36  
    37  terraform.Apply(t, terraformOptions)
    38  ```