Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: variable set assignment drifts with parent projects #961

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions client/configuration_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ type UpdateConfigurationSetPayload struct {
}

type ConfigurationSet struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
AssignmentScope string `json:"assignmentScope"`
CreationScopeId string `json:"creationScopeId"`
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
AssignmentScope string `json:"assignmentScope"`
CreationScopeId string `json:"creationScopeId"`
AssignmentScopeId string `json:"assignmentScopeId"`
}

func (client *ApiClient) ConfigurationSetCreate(payload *CreateConfigurationSetPayload) (*ConfigurationSet, error) {
var result ConfigurationSet

var err error

if payload.Scope == "organization" && payload.ScopeId == "" {
Expand Down
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
3 changes: 2 additions & 1 deletion env0/resource_variable_set_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ func resourceVariableSetAssignmentRead(ctx context.Context, d *schema.ResourceDa
}

for _, apiConfigurationSet := range apiConfigurationSets {
if !strings.EqualFold(apiConfigurationSet.AssignmentScope, assignmentSchema.Scope) {
// Filter out inherited assignments (e.g parent project).
if apiConfigurationSet.AssignmentScopeId != assignmentSchema.ScopeId {
continue
}

Expand Down
45 changes: 29 additions & 16 deletions env0/resource_variable_set_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,46 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) {
setIds := []string{"a1", "a2"}
configurationSetIds := []client.ConfigurationSet{
{
Id: "a1",
AssignmentScope: scope,
Id: "a1",
AssignmentScope: scope,
AssignmentScopeId: scopeId,
},
{
Id: "a2",
AssignmentScope: scope,
Id: "a2",
AssignmentScope: scope,
AssignmentScopeId: scopeId,
},
{
Id: "filtered_out",
AssignmentScope: scope,
AssignmentScopeId: "otherAssignmentScopeId",
},
}
// Validates that drifts do not occur due to ordering.
flippedConfigurationSetIds := []client.ConfigurationSet{
{
Id: "a2",
AssignmentScope: scope,
Id: "a2",
AssignmentScope: scope,
AssignmentScopeId: scopeId,
},
{
Id: "a1",
AssignmentScope: scope,
Id: "a1",
AssignmentScope: scope,
AssignmentScopeId: scopeId,
},
}

updatedSetIds := []string{"a1", "a3"}
updatedConfigurationSetIds := []client.ConfigurationSet{
{
Id: "a3",
AssignmentScope: scope,
Id: "a3",
AssignmentScope: scope,
AssignmentScopeId: scopeId,
},
{
Id: "a1",
AssignmentScope: scope,
Id: "a1",
AssignmentScope: scope,
AssignmentScopeId: scopeId,
},
}

Expand Down Expand Up @@ -103,12 +114,14 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) {
setIds := []string{"a1"}
configurationSetIds := []client.ConfigurationSet{
{
Id: "a1",
AssignmentScope: scope,
Id: "a1",
AssignmentScope: scope,
AssignmentScopeId: scopeId,
},
{
Id: "a2",
AssignmentScope: scope,
Id: "a2",
AssignmentScope: scope,
AssignmentScopeId: scopeId,
},
}

Expand Down
Loading