Skip to content

Commit

Permalink
Fix: variable set assignment drifts with parent projects
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Oct 7, 2024
1 parent 3bd6be6 commit 940ba40
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions env0/resource_variable_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,13 @@ func mergeVariables(schema []client.ConfigurationVariable, api []client.Configur
for _, avariable := range api {
if svariable.Name == avariable.Name && *svariable.Type == *avariable.Type {
found = true

if avariable.IsSensitive != nil && *avariable.IsSensitive {
// Sensitive - to avoid drift use the value from the schema
avariable.Value = svariable.Value
}
res.currentVariables = append(res.currentVariables, avariable)

break
}
}
Expand Down
6 changes: 6 additions & 0 deletions env0/resource_variable_set_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,16 @@ func resourceVariableSetAssignmentRead(ctx context.Context, d *schema.ResourceDa
}

for _, apiConfigurationSet := range apiConfigurationSets {
// Filter out irrelevant scopes.
if !strings.EqualFold(apiConfigurationSet.AssignmentScope, assignmentSchema.Scope) {
continue
}

// Filter out inherited scopes (e.g parent project).
if apiConfigurationSet.CreationScopeId != assignmentSchema.ScopeId {
continue
}

apiSetId := apiConfigurationSet.Id
found := false

Expand Down
13 changes: 13 additions & 0 deletions env0/resource_variable_set_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,30 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) {
{
Id: "a1",
AssignmentScope: scope,
CreationScopeId: scopeId,
},
{
Id: "a2",
AssignmentScope: scope,
CreationScopeId: scopeId,
},
{
Id: "filtered_out",
AssignmentScope: scope,
CreationScopeId: "otherCreationScopeId",
},
}
// Validates that drifts do not occur due to ordering.
flippedConfigurationSetIds := []client.ConfigurationSet{
{
Id: "a2",
AssignmentScope: scope,
CreationScopeId: scopeId,
},
{
Id: "a1",
AssignmentScope: scope,
CreationScopeId: scopeId,
},
}

Expand All @@ -45,10 +54,12 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) {
{
Id: "a3",
AssignmentScope: scope,
CreationScopeId: scopeId,
},
{
Id: "a1",
AssignmentScope: scope,
CreationScopeId: scopeId,
},
}

Expand Down Expand Up @@ -105,10 +116,12 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) {
{
Id: "a1",
AssignmentScope: scope,
CreationScopeId: scopeId,
},
{
Id: "a2",
AssignmentScope: scope,
CreationScopeId: scopeId,
},
}

Expand Down

0 comments on commit 940ba40

Please sign in to comment.