Skip to content

Commit

Permalink
re work merging data structures together
Browse files Browse the repository at this point in the history
  • Loading branch information
jabez007 committed Jul 28, 2024
1 parent 35100d8 commit c497aee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/update-repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
pages: read

steps:
- name: Checkout Repository
Expand Down
26 changes: 26 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
locals {
environments = ["Development", "UAT", "Production"]

####
# create a list of objects
# [
# {
# repository: "repo1",
# environment: "Development"
# },
# {
# repository: "repo1",
# environment: "UAT"
# },
# {
# repository: "repo1",
# environment: "Production"
# }
# ]
####
repo_environments = flatten([
for repo in data.github_repositories.my_topics.names : [
for env in local.environments : {
repository = repo
environment = env
}
]
])
}
14 changes: 6 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ data "github_repositories" "my_topics" {
}

resource "github_repository_environment" "environments" {
for_each = {
for repo in data.github_repositories.my_topics : repo.name => [
for env in local.environments : {
repository = repo.name
environment = env
}
]
}
# local.repo_environments is a list of objects
# so we must project that into a map
# where each key is unique
for_each = toMap({
for env in local.repo_environments : "${env.repository} - ${env.environment}" => env
})

repository = each.value.repository
environment = each.value.environment
Expand Down

0 comments on commit c497aee

Please sign in to comment.