-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d65226b
commit 89e7198
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/waf" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsWafRegionalIpSet() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAWSWafRegionalIpSetRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAWSWafRegionalIpSetRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).wafregionalconn | ||
name := d.Get("name").(string) | ||
|
||
ipsets := make([]*waf.IPSetSummary, 0) | ||
// ListIPSetsInput does not have a name parameter for filtering or a paginator | ||
input := &waf.ListIPSetsInput{} | ||
for { | ||
output, err := conn.ListIPSets(input) | ||
if err != nil { | ||
return fmt.Errorf("Error reading WAF Regional IP sets: %s", err) | ||
} | ||
for _, ipset := range output.IPSets { | ||
if aws.StringValue(ipset.Name) == name { | ||
ipsets = append(ipsets, ipset) | ||
} | ||
} | ||
|
||
if output.NextMarker == nil { | ||
break | ||
} | ||
input.NextMarker = output.NextMarker | ||
} | ||
|
||
if len(ipsets) == 0 { | ||
return fmt.Errorf("WAF Regional IP Set not found for name: %s", name) | ||
} | ||
if len(ipsets) > 1 { | ||
return fmt.Errorf("Multiple WAF Regional IP Sets found for name: %s", name) | ||
} | ||
|
||
ipset := ipsets[0] | ||
d.SetId(aws.StringValue(ipset.IPSetId)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsWafRegionalIPSet_Basic(t *testing.T) { | ||
name := acctest.RandomWithPrefix("tf-acc-test") | ||
resourceName := "aws_wafregional_ipset.ipset" | ||
datasourceName := "data.aws_wafregional_ipset.ipset" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsWafRegionalIPSet_NonExistent, | ||
ExpectError: regexp.MustCompile(`WAF Regional IP Set not found`), | ||
}, | ||
{ | ||
Config: testAccDataSourceAwsWafRegionalIPSet_Name(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsWafRegionalIPSet_Name(name string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_wafregional_ipset" "ipset" { | ||
name = %[1]q | ||
} | ||
data "aws_wafregional_ipset" "ipset" { | ||
name = "${aws_wafregional_ipset.ipset.name}" | ||
} | ||
`, name) | ||
} | ||
|
||
const testAccDataSourceAwsWafRegionalIPSet_NonExistent = ` | ||
data "aws_wafregional_ipset" "ipset" { | ||
name = "tf-acc-test-does-not-exist" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_wafregional_ipset" | ||
sidebar_current: "docs-aws-datasource-wafregional-ipset" | ||
description: |- | ||
Retrieves an AWS WAF Regional IP set id. | ||
--- | ||
|
||
# Data Source: aws_wafregional_ipset | ||
|
||
`aws_wafregional_ipset` Retrieves a WAF Regional IP Set Resource Id. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_wafregional_ipset" "example" { | ||
name = "tfWAFRegionalIPSet" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the WAF Regional IP set. | ||
|
||
## Attributes Reference | ||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The ID of the WAF Regional IP set. |