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

Add Waf RateBasedRule support #1606

Merged
merged 6 commits into from
Sep 11, 2017
Merged

Conversation

bekbulatov
Copy link
Contributor

Updated version of #1285.
I had to add the required type field to the rules block under aws_waf_rule. The value could be either REGULAR or RATE_BASED regarding which type of rule you are using.
The docs are updated as well.

@bekbulatov bekbulatov mentioned this pull request Sep 7, 2017
@radeksimko radeksimko self-assigned this Sep 7, 2017
@radeksimko radeksimko self-requested a review September 7, 2017 10:02
@radeksimko radeksimko removed their assignment Sep 7, 2017
@Ninir Ninir added the enhancement Requests to existing resources that expand the functionality or scope. label Sep 7, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Hey @bekbulatov
thanks for the PR - I left you some comments/questions there.

Let me know what you think.

errors = append(errors, fmt.Errorf("%q must be only %s", k, waf.RateKeyIp))
}
return
},
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure it's wise to have the validation here for this field. It looks like Amazon may have some plans for expansion, otherwise they wouldn't be introducing a field with a single valid value.
The downside of the static validation is that once AWS introduces a new rate key, we'll have to loose the validation or remove it and folks will be waiting for a new release (unable to use the new key) merely because of tight static validation.

It's not a big deal - I'm just trying to think ahead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, anyway the value will be validated by AWS.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, I think the AWS API validation is the best choice here.

},
"data_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

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

This field seems to be required in per the API docs: http://docs.aws.amazon.com/waf/latest/APIReference/API_Predicate.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will update the schema for Rule as well

},
"rate_key": &schema.Schema{
Type: schema.TypeString,
Required: true,
Copy link
Member

Choose a reason for hiding this comment

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

It seems that this field isn't updatable (based on API reference), shouldn't it be marked as ForceNew then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rate_key could be only IP now. Why do you think it should be recreated if changed?

Copy link
Member

Choose a reason for hiding this comment

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

well, you're right that there's no way to change it, but if the user is unaware they might try and at the moment we'd just ignore the field (in Update) and support user's assumption that the field was successfully changed.

If we instead delegate the validation work to Create then it will fail and user will also realize during plan that this can't be changed.

return nil
}

func updateWafRateBasedRuleResource(id string, oldP, newP []interface{}, rateLimit *int64, conn *waf.WAF) error {
Copy link
Member

Choose a reason for hiding this comment

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

It might be more convenient to accept rateLimit int here instead and do all the pointer magic inside the function to reduce the repetition, but no biggie.

}
return
},
},
Copy link
Member

Choose a reason for hiding this comment

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

Is there any particular reason why this change should be included in this PR? How is it related to WAF Rate Based Rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mentioned this in #1285. By default, WebACL works with REGULAR rules and you will get an error if you pass rule_id of a RATE_BASED rule. This is documented in https://github.com/aws/aws-sdk-go/blob/master/service/waf/api.go#L5708-L5713

Copy link
Member

Choose a reason for hiding this comment

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

I see, but I think we can't just introduce a Required field - that would break it for users with existing configs which don't have this field there.
This applies to your other change in aws/resource_aws_waf_rule.go too.

Copy link
Member

Choose a reason for hiding this comment

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

Do you mind changing it to Optional?

Copy link
Member

Choose a reason for hiding this comment

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

btw. you might be able to avoid changing the updateWebAclResource if you also add the current default value as Default - that way it should just work the same way as before, yet allow users to specify type = "RATE_BASED" if they need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@radeksimko Thank you for the review. I believe the Required change for aws/resource_aws_waf_rule.go is fine, as we just duplicate AWS validation, it's not a breaking change.
I made type optional and default to REGULAR as recommended.

Copy link
Member

Choose a reason for hiding this comment

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

You're right - just checked the API docs - it was probably just overlooked.

Thanks.

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Sep 8, 2017
@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 11, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes. I think we're getting very close to "merge-able" state. 🙂

Just one comment left about Optional/Required.

@radeksimko radeksimko merged commit 58394e5 into hashicorp:master Sep 11, 2017
nbaztec pushed a commit to nbaztec/terraform-provider-aws that referenced this pull request Sep 26, 2017
@bekbulatov bekbulatov deleted the ratebasedrule branch September 27, 2017 10:17
@ghost
Copy link

ghost commented Apr 11, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants