Skip to content

Instantly share code, notes, and snippets.

@rssnyder
Created September 17, 2024 18:58
Show Gist options
  • Save rssnyder/ca72bd0a9903c2b617991fb63ce5930a to your computer and use it in GitHub Desktop.
Save rssnyder/ca72bd0a9903c2b617991fb63ce5930a to your computer and use it in GitHub Desktop.
create a harness project based on files with a common naming scheme
  1. Defines projects via a JSON structure in files named ".project.json"
  2. Loads the list of files following that naming scheme into a local variable "projects"
  3. Creates a project for each file in the list "local.projects" where the "each.key" is the file name and "each.value" is the JSON object in that file

You can then do "each.value." to extract values for each project.

image

{
"org_id": "default",
"id": "projectA"
}
{
"org_id": "default",
"id": "projectB"
}
terraform {
required_providers {
harness = {
source = "harness/harness"
}
}
}
locals {
projects = fileset(path.module, "*.project.json")
}
resource "harness_platform_project" "test" {
for_each = { for project_file in local.projects : project_file => jsondecode(file(project_file)) }
org_id = each.value.org_id
identifier = each.value.id
name = each.value.id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment