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.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..f1785c7b 100644 --- a/env0/resource_variable_set_assignment.go +++ b/env0/resource_variable_set_assignment.go @@ -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 } diff --git a/env0/resource_variable_set_assignment_test.go b/env0/resource_variable_set_assignment_test.go index 52263728..26fb6388 100644 --- a/env0/resource_variable_set_assignment_test.go +++ b/env0/resource_variable_set_assignment_test.go @@ -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, }, } @@ -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, }, }