-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
Id string `json:"id"` | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
AssignmentScope string `json:"assignmentScope"` |
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.
env0/resource_environment.go
Outdated
@@ -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 comment
The 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.
this will avoid possible conflicts with explicit assignment resource.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
No need to apologize (:
Correct - without this check we will see a drift.
(We are doing the same check for "configuration").
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.
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 🤔
I will raise it with the team and update you 😄
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.
we can't hide drifts!
the set assignment might be from the FE and not from the other resource
so this is really a drift
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.
we are not hiding drifts...
you can either use the assignment resource or set the sets inline in the environment.
You cannot use both. Otherwise, you will have constant drifts/conflicts. (Same with configuration).
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 comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we just don't understand the code...
how are you checking if another resource is used?
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.
It's simple (but not perfect):
if "variables-set" is set in the state, it means we use the "variables-set" inline use-case.
Otherwise, it's ignored.
@@ -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 comment
The 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).
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
filter to avoid getting implicit variable sets... (from other scopes)
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
filter to avoid getting implicit variable sets... (from other scopes)
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.
Regarding the general solution here, I think we can avoid code changes and just keep the docs like we do for regular variables. In the current solution, if a user uses the API or FE to assign variable sets we will ignore it and won’t show the drift
@Yossi-kerner - that's not going to be enough. Fixes are required here... |
But IIUC the fixes only hide the issue no? If there will be a drift detection we will miss that no? |
Not really... |
Issue & Steps to Reproduce / Feature Request
fixes #888
fixes #894
fixes #895
Solution