Skip to content

Commit 647b086

Browse files
authored
fix: access state safely before initial synchronization (#161)
* docs: warn about fix not working before initial sync * fix: access state safely before initial synchronization
1 parent cc75523 commit 647b086

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4646
- updated upload and download artifacts actions to v4
4747

4848
### Fixed
49+
- fixed how terraform state is accessed before it the initial synchronization
4950
- links to supported resources in HOWTOs
5051
- posting PR comments when terraform plan output is very long
5152
- PR parsing in the update workflow

docs/SETUP.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@
143143
- [ ] Rename the `$GITHUB_ORGANIZATION_NAME.yml` in `github` to the name of the GitHub organization
144144
- [ ] Push the changes to `$GITHUB_MGMT_REPOSITORY_DEFAULT_BRANCH`
145145
146+
> [!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.
147+
146148
## GitHub Management Sync Flow
147149
148150
- [ ] Follow [How to synchronize GitHub Management with GitHub?](HOWTOS.md#synchronize-github-management-with-github) to commit the terraform lock and initialize terraform state

terraform/locals.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ locals {
136136
}
137137
}
138138
}
139-
"state" = {
139+
"state" = lookup({
140140
for mode, item in {
141-
for item in local.state.values.root_module.resources : item.mode => item...
142-
} : mode => {
141+
for item in try(local.state.values.root_module.resources, []) : item.mode => item...
142+
} : mode => {
143143
for type, item in {
144144
for item in item : item.type => item...
145145
} : type => {
@@ -152,7 +152,7 @@ locals {
152152
}
153153
}
154154
}
155-
}.managed
155+
}, "managed", {})
156156
}
157157
resources = {
158158
"github_membership" = {

0 commit comments

Comments
 (0)