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

issue #4772 add arn to aws_waf_ipset #4784

Merged
merged 1 commit into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions aws/resource_aws_waf_ipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/waf"
"github.com/hashicorp/terraform/helper/schema"
Expand All @@ -23,6 +24,10 @@ func resourceAwsWafIPSet() *schema.Resource {
Required: true,
ForceNew: true,
},
"arn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"ip_set_descriptors": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -94,6 +99,15 @@ func resourceAwsWafIPSetRead(d *schema.ResourceData, meta interface{}) error {

d.Set("name", resp.IPSet.Name)

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Region: meta.(*AWSClient).region,
Service: "waf",
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("ipset/%s", d.Id()),
}
d.Set("arn", arn.String())

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions aws/resource_aws_waf_ipset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"reflect"
"regexp"
"testing"

"github.com/hashicorp/terraform/helper/resource"
Expand Down Expand Up @@ -33,6 +34,8 @@ func TestAccAWSWafIPSet_basic(t *testing.T) {
"aws_waf_ipset.ipset", "ip_set_descriptors.4037960608.type", "IPV4"),
resource.TestCheckResourceAttr(
"aws_waf_ipset.ipset", "ip_set_descriptors.4037960608.value", "192.0.7.0/24"),
resource.TestMatchResourceAttr("aws_waf_ipset.ipset", "arn",
regexp.MustCompile(`^arn:[\w-]+:([a-zA-Z0-9\-])+:([a-z]{2}-(gov-)?[a-z]+-\d{1})?:(\d{12})?:(.*)$`)),
Copy link
Contributor

Choose a reason for hiding this comment

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

This regex is pretty hard to read and has some issues:

  • The service name should always be waf
  • The region name should always exist
  • The account ID should always exist
  • The resource should check for ipset/.+

At some point we'll probably create a helper function for ARN testing like this, but as for this case, I will fix these items post-merge with the simpler: ^arn:[\w-]+:waf:[^:]+:\d{12}:ipset/.+$.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually double checking the AWS documentation here: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-waf

arn:aws:waf::123456789012:ipset/3f74bd8c-f046-4970-a1a7-41aa52e05480

Looks like region name should never be set. I'll adjust the ARN logic and regex here accordingly.

In the regional case, it will include the region, but that is a separate resource and test 👍

arn:aws:waf-regional:us-east-1:123456789012:ipset/3f74bd8c-f046-4970-a1a7-41aa52e05480

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, correct. Will I add arn attribute to aws_wafregional_ipset, is it useful?

Copy link
Contributor

Choose a reason for hiding this comment

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

@saravanan30erd I'm sure someone will eventually be looking for it! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bflad Its done #4816 👍

),
},
},
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/waf_ipset.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the WAF IPSet.
* `arn` - The ARN of the WAF IPSet.