-
Notifications
You must be signed in to change notification settings - Fork 13
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: drift issues with variable sets #889
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,7 +357,7 @@ func resourceEnvironment() *schema.Resource { | |
}, | ||
"variable_sets": { | ||
Type: schema.TypeList, | ||
Description: "a list of variable set to assign to this environment", | ||
Description: "a list of variable set to assign to this environment. Note: must not be used with 'env0_variable_set_assignment'", | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
|
@@ -433,7 +433,7 @@ func setEnvironmentSchema(ctx context.Context, d *schema.ResourceData, environme | |
|
||
setEnvironmentConfigurationSchema(ctx, d, configurationVariables) | ||
|
||
if d.Get("variable_sets") != nil { | ||
if variableSets, ok := d.GetOk("variable_sets"); variableSets != nil && ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as "configuration" - if this field isn't used - ignore any use-cases related to it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if it's a basic question but I'm pretty new to go and terraform provider so I would like to make sure 😅 Let's say we have an environment and we assign a variable set to it (by FE or API) will we see the drift there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to apologize (: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, I talked about it with @GiliFaroEnv0 and it looked weird that we won't show DD but if that's how we do it for configuration it might be the way 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can't hide drifts! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are not hiding drifts... It just tests which one is used... if a resource assignments are used, it ignores anything inline in the environment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we just don't understand the code... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's simple (but not perfect): if "variables-set" is set in the state, it means we use the "variables-set" inline use-case. |
||
if err := d.Set("variable_sets", variableSetsIds); err != nil { | ||
return fmt.Errorf("failed to set variable_sets value: %w", err) | ||
} | ||
|
@@ -630,7 +630,9 @@ func getEnvironmentVariableSetIdsFromApi(d *schema.ResourceData, apiClient clien | |
|
||
var environmentVariableSetIds []string | ||
for _, variableSet := range environmentVariableSets { | ||
environmentVariableSetIds = append(environmentVariableSetIds, variableSet.Id) | ||
if variableSet.AssignmentScope == "ENVIRONMENT" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filter is required here... to avoid getting upper scopes variables (E.g. project or org). |
||
environmentVariableSetIds = append(environmentVariableSetIds, variableSet.Id) | ||
} | ||
} | ||
|
||
return environmentVariableSetIds, nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ func resourceVariableSetAssignment() *schema.Resource { | |
ReadContext: resourceVariableSetAssignmentRead, | ||
DeleteContext: resourceVariableSetAssignmentDelete, | ||
|
||
Description: "note: avoid assigning to environments using 'variable_sets' (see environment schema).", | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"scope": { | ||
Type: schema.TypeString, | ||
|
@@ -87,6 +89,10 @@ func resourceVariableSetAssignmentUpdate(ctx context.Context, d *schema.Resource | |
|
||
// In API but not in Schema - delete. | ||
for _, apiConfigurationSet := range apiConfigurationSets { | ||
if apiConfigurationSet.AssignmentScope != assignmentSchema.Scope { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filter to avoid getting implicit variable sets... (from other scopes) |
||
continue | ||
} | ||
|
||
found := false | ||
|
||
apiSetId := apiConfigurationSet.Id | ||
|
@@ -181,6 +187,10 @@ func resourceVariableSetAssignmentRead(ctx context.Context, d *schema.ResourceDa | |
} | ||
|
||
for _, apiConfigurationSet := range apiConfigurationSets { | ||
if apiConfigurationSet.AssignmentScope != assignmentSchema.Scope { | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filter to avoid getting implicit variable sets... (from other scopes) |
||
} | ||
|
||
apiSetId := apiConfigurationSet.Id | ||
found := false | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added assignment scope to be able to filter implicit assignments.