-
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: 'endless drift' when setting template path to start with '/' #700
Conversation
pathPrefix = prefix + ".0.path" | ||
} | ||
|
||
path, pathOk := d.GetOk(pathPrefix) |
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.
save the current value
} | ||
|
||
path, pathOk := d.GetOk(pathPrefix) | ||
|
||
if err := writeResourceDataEx(prefix, &template, d); err != nil { |
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.
this updated to the new value
if err := writeResourceDataEx(prefix, &template, d); err != nil { | ||
return fmt.Errorf("schema resource data serialization failed: %v", err) | ||
} | ||
|
||
// https://github.com/env0/terraform-provider-env0/issues/699 - backend removes the "/". | ||
if pathOk && path.(string) == "/"+template.Path { |
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.
if diff is just in "/" revert to old path - this avoids a drift and keeps state intact with what the user entered.
@@ -1006,6 +1006,84 @@ func TestUnitTemplateResource(t *testing.T) { | |||
}) | |||
}) | |||
|
|||
// https://github.com/env0/terraform-provider-env0/issues/699 | |||
t.Run("path drift", func(t *testing.T) { |
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.
test fails without the fix.
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.
LGTM ty for the comments
Issue & Steps to Reproduce / Feature Request
fixes #699
Solution
Keeping the state with "/" to avoid endless drift. Ignoring the value returned by the template if only "/" was omitted.
Added an acceptance test for this use-case and updated the integration test.