Affected: Terraform Integration
Overview
When using the Terraform resource launchdarkly_project
, you have two options for creating multiple environments within the same project.
Solution
To create a project with multiple environments, refer to the following examples:
Option 1
provider "launchdarkly" {
version = "~> 1.0"
access_token = "YOUR_API_KEY"
}
resource "launchdarkly_project" "example" {
key = "example-project"
name = "Example project"
tags = [
"terraform",
]
}
resource "launchdarkly_environment" "staging" {
name = "Staging"
key = "staging"
color = "ff00ff"
tags = ["terraform", "staging"]
project_key = "example"
}
resource "launchdarkly_environment" "qa" {
name = "QA"
key = "qa"
color = "00ffff"
tags = ["terraform", "qa"]
project_key = "example"
}
Option 2 (more dynamic approach)
resource "launchdarkly_project" "project" {
for_each = toset(var.project_names)
key = "${each.value}-project"
name = each.value
tags = var.tags
dynamic "environments" {
for_each = toset(var.environment_names)
content {
name = environments.value
key = lower(environments.value)
color = var.env_color
tags = var.tags
}
}
}