From 940ba40edf17437761a2f71d8dc7418ffe9f4e43 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Mon, 7 Oct 2024 08:08:24 -0500 Subject: [PATCH 1/4] Fix: variable set assignment drifts with parent projects --- env0/resource_variable_set.go | 2 ++ env0/resource_variable_set_assignment.go | 6 ++++++ env0/resource_variable_set_assignment_test.go | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/env0/resource_variable_set.go b/env0/resource_variable_set.go index c604c607..9930784a 100644 --- a/env0/resource_variable_set.go +++ b/env0/resource_variable_set.go @@ -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 } } diff --git a/env0/resource_variable_set_assignment.go b/env0/resource_variable_set_assignment.go index 26f08ee5..7615e2c3 100644 --- a/env0/resource_variable_set_assignment.go +++ b/env0/resource_variable_set_assignment.go @@ -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 diff --git a/env0/resource_variable_set_assignment_test.go b/env0/resource_variable_set_assignment_test.go index 52263728..179c2df2 100644 --- a/env0/resource_variable_set_assignment_test.go +++ b/env0/resource_variable_set_assignment_test.go @@ -22,10 +22,17 @@ 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. @@ -33,10 +40,12 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) { { Id: "a2", AssignmentScope: scope, + CreationScopeId: scopeId, }, { Id: "a1", AssignmentScope: scope, + CreationScopeId: scopeId, }, } @@ -45,10 +54,12 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) { { Id: "a3", AssignmentScope: scope, + CreationScopeId: scopeId, }, { Id: "a1", AssignmentScope: scope, + CreationScopeId: scopeId, }, } @@ -105,10 +116,12 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) { { Id: "a1", AssignmentScope: scope, + CreationScopeId: scopeId, }, { Id: "a2", AssignmentScope: scope, + CreationScopeId: scopeId, }, } From 7495287f04fde30106f1fd07c5e9efd79e8d60e9 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Mon, 7 Oct 2024 08:13:51 -0500 Subject: [PATCH 2/4] change comment wording --- env0/resource_variable_set_assignment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/env0/resource_variable_set_assignment.go b/env0/resource_variable_set_assignment.go index 7615e2c3..b5176ee6 100644 --- a/env0/resource_variable_set_assignment.go +++ b/env0/resource_variable_set_assignment.go @@ -193,7 +193,7 @@ func resourceVariableSetAssignmentRead(ctx context.Context, d *schema.ResourceDa continue } - // Filter out inherited scopes (e.g parent project). + // Filter out inherited assignments (e.g parent project). if apiConfigurationSet.CreationScopeId != assignmentSchema.ScopeId { continue } From 7afa8ea59b6d9914096fbda9fd41a2acefd1c5c1 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Mon, 7 Oct 2024 08:20:58 -0500 Subject: [PATCH 3/4] use AssignmentScopeId instead --- client/configuration_set.go | 12 +++-- env0/resource_variable_set_assignment.go | 2 +- env0/resource_variable_set_assignment_test.go | 54 +++++++++---------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/client/configuration_set.go b/client/configuration_set.go index 9bd22ae1..ad912984 100644 --- a/client/configuration_set.go +++ b/client/configuration_set.go @@ -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 == "" { diff --git a/env0/resource_variable_set_assignment.go b/env0/resource_variable_set_assignment.go index b5176ee6..90f15814 100644 --- a/env0/resource_variable_set_assignment.go +++ b/env0/resource_variable_set_assignment.go @@ -194,7 +194,7 @@ func resourceVariableSetAssignmentRead(ctx context.Context, d *schema.ResourceDa } // Filter out inherited assignments (e.g parent project). - if apiConfigurationSet.CreationScopeId != assignmentSchema.ScopeId { + if apiConfigurationSet.AssignmentScopeId != assignmentSchema.ScopeId { continue } diff --git a/env0/resource_variable_set_assignment_test.go b/env0/resource_variable_set_assignment_test.go index 179c2df2..26fb6388 100644 --- a/env0/resource_variable_set_assignment_test.go +++ b/env0/resource_variable_set_assignment_test.go @@ -20,46 +20,46 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) { setIds := []string{"a1", "a2"} configurationSetIds := []client.ConfigurationSet{ { - Id: "a1", - AssignmentScope: scope, - CreationScopeId: scopeId, + Id: "a1", + AssignmentScope: scope, + AssignmentScopeId: scopeId, }, { - Id: "a2", - AssignmentScope: scope, - CreationScopeId: scopeId, + Id: "a2", + AssignmentScope: scope, + AssignmentScopeId: scopeId, }, { - Id: "filtered_out", - AssignmentScope: scope, - CreationScopeId: "otherCreationScopeId", + Id: "filtered_out", + AssignmentScope: scope, + AssignmentScopeId: "otherAssignmentScopeId", }, } // Validates that drifts do not occur due to ordering. flippedConfigurationSetIds := []client.ConfigurationSet{ { - Id: "a2", - AssignmentScope: scope, - CreationScopeId: scopeId, + Id: "a2", + AssignmentScope: scope, + AssignmentScopeId: scopeId, }, { - Id: "a1", - AssignmentScope: scope, - CreationScopeId: scopeId, + Id: "a1", + AssignmentScope: scope, + AssignmentScopeId: scopeId, }, } updatedSetIds := []string{"a1", "a3"} updatedConfigurationSetIds := []client.ConfigurationSet{ { - Id: "a3", - AssignmentScope: scope, - CreationScopeId: scopeId, + Id: "a3", + AssignmentScope: scope, + AssignmentScopeId: scopeId, }, { - Id: "a1", - AssignmentScope: scope, - CreationScopeId: scopeId, + Id: "a1", + AssignmentScope: scope, + AssignmentScopeId: scopeId, }, } @@ -114,14 +114,14 @@ func TestUnitVariableSetAssignmentResource(t *testing.T) { setIds := []string{"a1"} configurationSetIds := []client.ConfigurationSet{ { - Id: "a1", - AssignmentScope: scope, - CreationScopeId: scopeId, + Id: "a1", + AssignmentScope: scope, + AssignmentScopeId: scopeId, }, { - Id: "a2", - AssignmentScope: scope, - CreationScopeId: scopeId, + Id: "a2", + AssignmentScope: scope, + AssignmentScopeId: scopeId, }, } From aa9fb0d9e82b293bde089f20be2af0c4eb851eea Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Mon, 7 Oct 2024 08:53:00 -0500 Subject: [PATCH 4/4] requested to removed a filter that is not required --- env0/resource_variable_set_assignment.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/env0/resource_variable_set_assignment.go b/env0/resource_variable_set_assignment.go index 90f15814..f1785c7b 100644 --- a/env0/resource_variable_set_assignment.go +++ b/env0/resource_variable_set_assignment.go @@ -188,11 +188,6 @@ 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 assignments (e.g parent project). if apiConfigurationSet.AssignmentScopeId != assignmentSchema.ScopeId { continue