-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Added WAF ACL Resource #8852
Added WAF ACL Resource #8852
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.
Hi @optimisticanshul! This looks like a good start, but there are a couple of review comments inline. In addition, we'll need to add a couple of acceptance tests and documentation prior to being able to merge this - but I notice you have it marked as a WIP so this may be in progress. Thanks for opening a pull request early in your work!
|
||
// ChangeToken | ||
var ct *waf.GetChangeTokenInput | ||
res, _ := conn.GetChangeToken(ct) |
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.
Can this fail? We should probably not be ignoring this error.
conn := meta.(*AWSClient).wafconn | ||
// ChangeToken | ||
var ct *waf.GetChangeTokenInput | ||
resp, err := conn.GetChangeToken(ct) |
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 we assign this error we should also check it.
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.
Updated.
log.Printf("[INFO] Deleting WAF ACL") | ||
_, err = conn.DeleteWebACL(req) | ||
|
||
if 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.
We should likely test here for whether the return code is a 404-equivalent and remove from state rather than erroring out if that is the case - this allows for us to track ACLs removed via the console.
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.
Updated in read func
1049e69
to
33283da
Compare
@jen20 @radeksimko Ready for the review. I will squash the commits once review is done. |
@stack72 bump |
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.
@optimisticanshul I have left a more indepth review of these now - sorry it took me so long. You can see the pattern I am following, please can you apply the same pattern to all of the resources (i only reviewed 2)
|
||
// ChangeToken | ||
var ct *waf.GetChangeTokenInput | ||
time.Sleep(10 * time.Second) // To Prevent WAFStaleDataException |
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 don't believe we should do this - what is the WAFStateDataException?
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.
@stack72 if i don't wait for sometime i get this exception because of ChangeToken: res.ChangeToken i am not sure how to handle in a better way.
WAFStaleDataException: The operation failed because you tried to create, update, or delete an object by using a change token that has already been used.
if err != nil { | ||
return err | ||
} | ||
d.SetId(*resp.IPSet.IPSetId) |
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 there a chance that resp.IPSet can be nil? I think it would be worth checking for the nil response here to prevent any potential pointer deference errors
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 don't think so it will be nil. Until/unless there is an error but in that case error is already handled
if err != nil {
return err
}
|
||
for _, IPSetDescriptor := range resp.IPSet.IPSetDescriptors { | ||
IPSet := map[string]interface{}{ | ||
"type": *IPSetDescriptor.Type, |
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.
Are we guaranteed to have both of these values each time?
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.
yes
} | ||
|
||
func updateIPSetResource(d *schema.ResourceData, meta interface{}, ChangeAction string) error { | ||
conn := meta.(*AWSClient).wafconn |
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 believe we should only do this when we detect d.HasChange("ip_set_descriptors")
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 we can't reason behind it is because this method is used for deleting as well as updating and in deletion case there will be no change in ip_set_descriptors.
|
||
// ChangeToken | ||
var ct *waf.GetChangeTokenInput | ||
time.Sleep(5 * time.Second) // To Prevent WAFStaleDataException |
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.
Again - we need to work out a better way of doing this than sleep
if err != nil { | ||
return err | ||
} | ||
d.SetId(*resp.Rule.RuleId) |
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.
Is there a chance Rule can be nil? If so, we should guard against this being a dereferencing 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.
Already handle in that in err.
} | ||
|
||
return err | ||
} |
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 think we should check for Rule being nil here before using it
} | ||
// ChangeToken | ||
var ct *waf.GetChangeTokenInput | ||
time.Sleep(5 * time.Second) // To Prevent WAFStaleDataException |
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 sleep please :)
|
||
// ChangeToken | ||
var ct *waf.GetChangeTokenInput | ||
time.Sleep(5 * time.Second) // To Prevent WAFStaleDataException |
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 Sleep please :)
return nil | ||
} | ||
|
||
func updateWafRuleResource(d *schema.ResourceData, meta interface{}, ChangeAction string) 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.
I think we need to check for change in the parameter before making a call to the API
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.
To delete a rule we need to remove related dependencies. updateWafRuleResource is used for updating the resource as well as in deleting the resource. So we can't check for change.
@optimisticanshul thanks for this work so far - I feel we need to do a little more work here :) |
@stack72 sure i will update 👍 |
ping @optimisticanshul :) |
fda2ce3
to
b1e9ebf
Compare
@stack72 I added/removed things that you asked wherever required, so now its ready for another review.
|
Hi @optimisticanshul Sorry i didn't get back to you on this sooner - i have been away. So the changes you had made look good. I think it needs 1 more thing - a test in each resource for Update. I can't see any testing of the Update funcs. Can you add something there? P. |
Sure On Wed 26 Oct, 2016, 2:30 PM Paul Stack, [email protected] wrote:
Sent From Handheld Device, Ignore Typos. |
ee62c7d
to
83adb70
Compare
@stack72 Hi ready for another review added update test cases 👍 |
@optimisticanshul this now LGTM! The tests are green :) I thank you for all the work here!
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
No description provided.