2016-10-27 15:58:24 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccDataSourceAwsPrefixList(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccDataSourceAwsPrefixListConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2016-11-20 15:21:55 +01:00
|
|
|
testAccDataSourceAwsPrefixListCheck("data.aws_prefix_list.s3_by_id"),
|
|
|
|
testAccDataSourceAwsPrefixListCheck("data.aws_prefix_list.s3_by_name"),
|
2016-10-27 15:58:24 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccDataSourceAwsPrefixListCheck(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("root module has no resource called %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
attr := rs.Primary.Attributes
|
|
|
|
|
|
|
|
if attr["name"] != "com.amazonaws.us-west-2.s3" {
|
|
|
|
return fmt.Errorf("bad name %s", attr["name"])
|
|
|
|
}
|
|
|
|
if attr["id"] != "pl-68a54001" {
|
|
|
|
return fmt.Errorf("bad id %s", attr["id"])
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
cidrBlockSize int
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
if cidrBlockSize, err = strconv.Atoi(attr["cidr_blocks.#"]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if cidrBlockSize < 1 {
|
|
|
|
return fmt.Errorf("cidr_blocks seem suspiciously low: %d", cidrBlockSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccDataSourceAwsPrefixListConfig = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-west-2"
|
|
|
|
}
|
|
|
|
|
2016-11-20 15:21:55 +01:00
|
|
|
data "aws_prefix_list" "s3_by_id" {
|
2016-10-27 15:58:24 +02:00
|
|
|
prefix_list_id = "pl-68a54001"
|
|
|
|
}
|
2016-11-20 15:21:55 +01:00
|
|
|
|
|
|
|
data "aws_prefix_list" "s3_by_name" {
|
|
|
|
name = "com.amazonaws.us-west-2.s3"
|
|
|
|
}
|
2016-10-27 15:58:24 +02:00
|
|
|
`
|