From e79e467e16c07b57c88058d6388a2586839b4673 Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 27 Mar 2025 22:52:02 +0100 Subject: [PATCH 1/2] docs: warn about fix not working before initial sync --- docs/SETUP.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/SETUP.md b/docs/SETUP.md index b36f8ba..b4154a1 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -143,6 +143,8 @@ - [ ] Rename the `$GITHUB_ORGANIZATION_NAME.yml` in `github` to the name of the GitHub organization - [ ] Push the changes to `$GITHUB_MGMT_REPOSITORY_DEFAULT_BRANCH` +> [!WARNING] Please note that until you [synchronize GitHub Management with GitHub](#github-management-sync-flow) for the first time, the workflows that depend on Terraform state, like `Fix`, `Plan` or `Apply`, will fail. This is because the state is not yet initialized. + ## GitHub Management Sync Flow - [ ] Follow [How to synchronize GitHub Management with GitHub?](HOWTOS.md#synchronize-github-management-with-github) to commit the terraform lock and initialize terraform state From d08620e78a0ba9f9c8c27d2e823f4e2838633db3 Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 27 Mar 2025 22:52:29 +0100 Subject: [PATCH 2/2] fix: access state safely before initial synchronization --- CHANGELOG.md | 1 + terraform/locals.tf | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0497d6..ac09400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - updated upload and download artifacts actions to v4 ### Fixed +- fixed how terraform state is accessed before it the initial synchronization - links to supported resources in HOWTOs - posting PR comments when terraform plan output is very long - PR parsing in the update workflow diff --git a/terraform/locals.tf b/terraform/locals.tf index 6bb27f1..778fabf 100644 --- a/terraform/locals.tf +++ b/terraform/locals.tf @@ -136,10 +136,10 @@ locals { } } } - "state" = { + "state" = lookup({ for mode, item in { - for item in local.state.values.root_module.resources : item.mode => item... - } : mode => { + for item in try(local.state.values.root_module.resources, []) : item.mode => item... + } : mode => { for type, item in { for item in item : item.type => item... } : type => { @@ -152,7 +152,7 @@ locals { } } } - }.managed + }, "managed", {}) } resources = { "github_membership" = {