Merge pull request #4550 from hashicorp/b-aws-acc-fixes
provider/aws: Update acceptance tests
This commit is contained in:
commit
3c494a4d6a
|
@ -132,11 +132,11 @@ func TestAccAWSOpsworksStackNoVpc(t *testing.T) {
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAwsOpsworksStackConfigNoVpcCreate,
|
Config: testAccAwsOpsworksStackConfigNoVpcCreate,
|
||||||
Check: testAccAwsOpsworksStackCheckResourceAttrsCreate,
|
Check: testAccAwsOpsworksStackCheckResourceAttrsCreate("us-east-1c"),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSOpsworksStackConfigNoVpcUpdate,
|
Config: testAccAWSOpsworksStackConfigNoVpcUpdate,
|
||||||
Check: testAccAwsOpsworksStackCheckResourceAttrsUpdate,
|
Check: testAccAwsOpsworksStackCheckResourceAttrsUpdate("us-east-1c"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -153,11 +153,11 @@ resource "aws_vpc" "tf-acc" {
|
||||||
resource "aws_subnet" "tf-acc" {
|
resource "aws_subnet" "tf-acc" {
|
||||||
vpc_id = "${aws_vpc.tf-acc.id}"
|
vpc_id = "${aws_vpc.tf-acc.id}"
|
||||||
cidr_block = "${aws_vpc.tf-acc.cidr_block}"
|
cidr_block = "${aws_vpc.tf-acc.cidr_block}"
|
||||||
availability_zone = "us-east-1c"
|
availability_zone = "us-west-2a"
|
||||||
}
|
}
|
||||||
resource "aws_opsworks_stack" "tf-acc" {
|
resource "aws_opsworks_stack" "tf-acc" {
|
||||||
name = "tf-opsworks-acc"
|
name = "tf-opsworks-acc"
|
||||||
region = "us-east-1"
|
region = "us-west-2"
|
||||||
vpc_id = "${aws_vpc.tf-acc.id}"
|
vpc_id = "${aws_vpc.tf-acc.id}"
|
||||||
default_subnet_id = "${aws_subnet.tf-acc.id}"
|
default_subnet_id = "${aws_subnet.tf-acc.id}"
|
||||||
service_role_arn = "${aws_iam_role.opsworks_service.arn}"
|
service_role_arn = "${aws_iam_role.opsworks_service.arn}"
|
||||||
|
@ -177,11 +177,11 @@ resource "aws_vpc" "tf-acc" {
|
||||||
resource "aws_subnet" "tf-acc" {
|
resource "aws_subnet" "tf-acc" {
|
||||||
vpc_id = "${aws_vpc.tf-acc.id}"
|
vpc_id = "${aws_vpc.tf-acc.id}"
|
||||||
cidr_block = "${aws_vpc.tf-acc.cidr_block}"
|
cidr_block = "${aws_vpc.tf-acc.cidr_block}"
|
||||||
availability_zone = "us-east-1c"
|
availability_zone = "us-west-2a"
|
||||||
}
|
}
|
||||||
resource "aws_opsworks_stack" "tf-acc" {
|
resource "aws_opsworks_stack" "tf-acc" {
|
||||||
name = "tf-opsworks-acc"
|
name = "tf-opsworks-acc"
|
||||||
region = "us-east-1"
|
region = "us-west-2"
|
||||||
vpc_id = "${aws_vpc.tf-acc.id}"
|
vpc_id = "${aws_vpc.tf-acc.id}"
|
||||||
default_subnet_id = "${aws_subnet.tf-acc.id}"
|
default_subnet_id = "${aws_subnet.tf-acc.id}"
|
||||||
service_role_arn = "${aws_iam_role.opsworks_service.arn}"
|
service_role_arn = "${aws_iam_role.opsworks_service.arn}"
|
||||||
|
@ -209,12 +209,12 @@ func TestAccAWSOpsworksStackVpc(t *testing.T) {
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAwsOpsworksStackConfigVpcCreate,
|
Config: testAccAwsOpsworksStackConfigVpcCreate,
|
||||||
Check: testAccAwsOpsworksStackCheckResourceAttrsCreate,
|
Check: testAccAwsOpsworksStackCheckResourceAttrsCreate("us-west-2a"),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSOpsworksStackConfigVpcUpdate,
|
Config: testAccAWSOpsworksStackConfigVpcUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccAwsOpsworksStackCheckResourceAttrsUpdate,
|
testAccAwsOpsworksStackCheckResourceAttrsUpdate("us-west-2a"),
|
||||||
testAccAwsOpsworksCheckVpc,
|
testAccAwsOpsworksCheckVpc,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -226,7 +226,8 @@ func TestAccAWSOpsworksStackVpc(t *testing.T) {
|
||||||
//// Checkers and Utilities
|
//// Checkers and Utilities
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckFunc(
|
func testAccAwsOpsworksStackCheckResourceAttrsCreate(zone string) resource.TestCheckFunc {
|
||||||
|
return resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_opsworks_stack.tf-acc",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"name",
|
"name",
|
||||||
|
@ -235,7 +236,7 @@ var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckF
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_opsworks_stack.tf-acc",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"default_availability_zone",
|
"default_availability_zone",
|
||||||
"us-east-1c",
|
zone,
|
||||||
),
|
),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_opsworks_stack.tf-acc",
|
"aws_opsworks_stack.tf-acc",
|
||||||
|
@ -263,8 +264,10 @@ var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckF
|
||||||
"false",
|
"false",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckFunc(
|
func testAccAwsOpsworksStackCheckResourceAttrsUpdate(zone string) resource.TestCheckFunc {
|
||||||
|
return resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_opsworks_stack.tf-acc",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"name",
|
"name",
|
||||||
|
@ -273,7 +276,7 @@ var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckF
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_opsworks_stack.tf-acc",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"default_availability_zone",
|
"default_availability_zone",
|
||||||
"us-east-1c",
|
zone,
|
||||||
),
|
),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_opsworks_stack.tf-acc",
|
"aws_opsworks_stack.tf-acc",
|
||||||
|
@ -326,6 +329,7 @@ var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckF
|
||||||
"https://github.com/aws/opsworks-example-cookbooks.git",
|
"https://github.com/aws/opsworks-example-cookbooks.git",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAwsOpsworksCheckVpc(s *terraform.State) error {
|
func testAccAwsOpsworksCheckVpc(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources["aws_opsworks_stack.tf-acc"]
|
rs, ok := s.RootModule().Resources["aws_opsworks_stack.tf-acc"]
|
||||||
|
@ -381,7 +385,6 @@ func testAccCheckAwsOpsworksStackDestroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Fall through error for OpsWorks stack test")
|
return fmt.Errorf("Fall through error for OpsWorks stack test")
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,16 +70,34 @@ func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
|
||||||
VpcPeeringConnectionIds: []*string{aws.String(rs.Primary.ID)},
|
VpcPeeringConnectionIds: []*string{aws.String(rs.Primary.ID)},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err != nil {
|
||||||
if len(describe.VpcPeeringConnections) != 0 {
|
return err
|
||||||
return fmt.Errorf("vpc peering connection still exists")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pc *ec2.VpcPeeringConnection
|
||||||
|
for _, c := range describe.VpcPeeringConnections {
|
||||||
|
if rs.Primary.ID == *c.VpcPeeringConnectionId {
|
||||||
|
pc = c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pc == nil {
|
||||||
|
// not found
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pc.Status != nil {
|
||||||
|
if *pc.Status.Code == "deleted" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("Found vpc peering connection in unexpected state: %s", pc)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Fall through error for testAccCheckAWSVpcPeeringConnectionDestroy")
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VpcPeeringConnection) resource.TestCheckFunc {
|
func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VpcPeeringConnection) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
|
Loading…
Reference in New Issue