Skip to content

Commit 45c47cb

Browse files
committed
fix: always assert state type when creating resources from state
1 parent 0d91c2b commit 45c47cb

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

CHANGELOG.md

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

5151
### Fixed
52+
- always assert state type when creating resources from state
5253
- do not break long file content lines
5354
- source TF_WORKING_DIR from env helper instead of process.env in locals helper
5455
- fixed how terraform state is accessed before it the initial synchronization

scripts/src/resources/repository-branch-protection-rule.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export class RepositoryBranchProtectionRule implements Resource {
5151
) {
5252
const repositoryIndex: string = resource.index.split(':')[0]
5353
const repository = state.values.root_module.resources.find(
54-
r => resource.mode === 'managed' && r.index === repositoryIndex
54+
r =>
55+
r.mode === 'managed' &&
56+
r.type === Repository.StateType &&
57+
r.index === repositoryIndex
5558
)
5659
const required_pull_request_reviews =
5760
resource.values.required_pull_request_reviews?.at(0)

scripts/src/resources/repository-team.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export class RepositoryTeam extends String implements Resource {
4242
) {
4343
const teamIndex = resource.index.split(`:`).slice(0, -1).join(`:`)
4444
const team = state.values.root_module.resources.find(
45-
r => resource.mode === 'managed' && r.index === teamIndex
45+
r =>
46+
r.mode === 'managed' &&
47+
r.type === Team.StateType &&
48+
r.index === teamIndex
4649
)
4750
teams.push(
4851
new RepositoryTeam(

scripts/src/resources/team-member.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ export class TeamMember extends String implements Resource {
5656
) {
5757
const teamIndex = resource.index.split(`:`).slice(0, -1).join(`:`)
5858
const team = state.values.root_module.resources.find(
59-
r => resource.mode === 'managed' && r.index === teamIndex
59+
r =>
60+
r.mode === 'managed' &&
61+
r.type === Team.StateType &&
62+
r.index === teamIndex
6063
)
64+
console.log(teamIndex, team)
6165
members.push(
6266
new TeamMember(
6367
team !== undefined && team.type === Team.StateType

0 commit comments

Comments
 (0)