-
Notifications
You must be signed in to change notification settings - Fork 142
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
Conversation
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.
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) { |
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 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) { |
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.
Just to double check: are we not able to reuse
terraform-provider-fastly/fastly/diff.go
Line 52 in 256c95d
func (h *SetDiff) Diff(oldSet, newSet *schema.Set) (*DiffResult, error) { |
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.
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"] |
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'd prefer to keep the variable initialisation near to where it is used (see the following suggested change).
name := resource["name"] |
return new(schema.Set) | ||
} | ||
|
||
odb = get(name.(string), od.(*schema.Set)) |
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.
odb = get(name.(string), od.(*schema.Set)) | |
name := resource["name"] | |
odb = get(name.(string), od.(*schema.Set)) |
Also @hrmsk66 can you run |
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'sDifference
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.