Skip to content
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

Make it possible to remove backend from director #547

Merged
merged 2 commits into from
Feb 21, 2022

Conversation

hrmsk66
Copy link
Contributor

@hrmsk66 hrmsk66 commented Feb 19, 2022

Fixes #545
Fixes #546

Make it possible to remove backends from a director.

This is a proposed fix for #545
If the backend in a director block changes, get the changes from *schema.ResourceData and compute backends to be removed/added using Set's Difference method.

Removing a director backend can result in a 404 error if the backend is removed from the service. I'm just ignoring the error in this fix since they don't mean anything useful to users.

I've also fixed an unrelated issue (#546) with the comment field in the director block which was causing the acceptance tests to fail.

Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments but otherwise LGTM.

// and in the next Terraform run the first director is updated while
// the second director is unchanged and a third director is added.
// In the final test, the first director is removed while the second
// director is unchanged and one backend for the third director is removed.
func TestAccFastlyServiceVCL_directors_basic(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

I always appreciate when people take the time to provide a 'summary' of a test.

@@ -301,3 +318,31 @@ func flattenDirectors(directorList []*gofastly.Director, directorBackendList []*
}
return dl
}

func getDirectorBackendChange(d *schema.ResourceData, resource map[string]interface{}) (odb *schema.Set, ndb *schema.Set) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check: are we not able to reuse

func (h *SetDiff) Diff(oldSet, newSet *schema.Set) (*DiffResult, error) {
?

Copy link
Contributor Author

@hrmsk66 hrmsk66 Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Diff method cannot replace getDirectorBackendChange(). To my understanding, Diff is handling a different issue:

  • The Diff method takes two Set objects and converts them into a DiffResult object containing the Added, Modified, Deleted, and Unmodified lists.
  • getDirectorBackendChange() gets Director Set objects from *schema.ResourceData, iterate over them to find the changed Director, then extract Director Backend Set objects from the Director Set and return them. (Basically, it returns child Set objects extracted from parent Set objects)

@@ -301,3 +318,31 @@ func flattenDirectors(directorList []*gofastly.Director, directorBackendList []*
}
return dl
}

func getDirectorBackendChange(d *schema.ResourceData, resource map[string]interface{}) (odb *schema.Set, ndb *schema.Set) {
name := resource["name"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep the variable initialisation near to where it is used (see the following suggested change).

Suggested change
name := resource["name"]

return new(schema.Set)
}

odb = get(name.(string), od.(*schema.Set))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
odb = get(name.(string), od.(*schema.Set))
name := resource["name"]
odb = get(name.(string), od.(*schema.Set))

@Integralist
Copy link
Collaborator

Also @hrmsk66 can you run make generate-docs

@Integralist Integralist merged commit 250358e into fastly:main Feb 21, 2022
@hrmsk66 hrmsk66 deleted the kake-director-fix branch February 21, 2022 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

null in the comment field causes configuration drift Unable to remove backends from director
2 participants