mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
providers/aws: Update OpsWorks tests to inject the expected availability zone, based on if we are testing vpc or not
This commit is contained in:
parent
e2a7d4d98b
commit
dcce2aa479
@ -2,6 +2,7 @@ package aws
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
@ -132,11 +133,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 +154,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 +178,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 +210,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,106 +227,110 @@ func TestAccAWSOpsworksStackVpc(t *testing.T) {
|
|||||||
//// Checkers and Utilities
|
//// Checkers and Utilities
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckFunc(
|
func testAccAwsOpsworksStackCheckResourceAttrsCreate(zone string) resource.TestCheckFunc {
|
||||||
resource.TestCheckResourceAttr(
|
return resource.ComposeTestCheckFunc(
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"name",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"tf-opsworks-acc",
|
"name",
|
||||||
),
|
"tf-opsworks-acc",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"default_availability_zone",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"us-east-1c",
|
"default_availability_zone",
|
||||||
),
|
zone,
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"default_os",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"Amazon Linux 2014.09",
|
"default_os",
|
||||||
),
|
"Amazon Linux 2014.09",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"default_root_device_type",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"ebs",
|
"default_root_device_type",
|
||||||
),
|
"ebs",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"custom_json",
|
"aws_opsworks_stack.tf-acc",
|
||||||
`{"key": "value"}`,
|
"custom_json",
|
||||||
),
|
`{"key": "value"}`,
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"configuration_manager_version",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"11.10",
|
"configuration_manager_version",
|
||||||
),
|
"11.10",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"use_opsworks_security_groups",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"false",
|
"use_opsworks_security_groups",
|
||||||
),
|
"false",
|
||||||
)
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckFunc(
|
func testAccAwsOpsworksStackCheckResourceAttrsUpdate(zone string) resource.TestCheckFunc {
|
||||||
resource.TestCheckResourceAttr(
|
return resource.ComposeTestCheckFunc(
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"name",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"tf-opsworks-acc",
|
"name",
|
||||||
),
|
"tf-opsworks-acc",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"default_availability_zone",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"us-east-1c",
|
"default_availability_zone",
|
||||||
),
|
zone,
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"default_os",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"Amazon Linux 2014.09",
|
"default_os",
|
||||||
),
|
"Amazon Linux 2014.09",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"default_root_device_type",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"ebs",
|
"default_root_device_type",
|
||||||
),
|
"ebs",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"custom_json",
|
"aws_opsworks_stack.tf-acc",
|
||||||
`{"key": "value"}`,
|
"custom_json",
|
||||||
),
|
`{"key": "value"}`,
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"configuration_manager_version",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"11.10",
|
"configuration_manager_version",
|
||||||
),
|
"11.10",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"use_opsworks_security_groups",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"false",
|
"use_opsworks_security_groups",
|
||||||
),
|
"false",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"use_custom_cookbooks",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"true",
|
"use_custom_cookbooks",
|
||||||
),
|
"true",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"manage_berkshelf",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"true",
|
"manage_berkshelf",
|
||||||
),
|
"true",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"custom_cookbooks_source.0.type",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"git",
|
"custom_cookbooks_source.0.type",
|
||||||
),
|
"git",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"custom_cookbooks_source.0.revision",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"master",
|
"custom_cookbooks_source.0.revision",
|
||||||
),
|
"master",
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_opsworks_stack.tf-acc",
|
resource.TestCheckResourceAttr(
|
||||||
"custom_cookbooks_source.0.url",
|
"aws_opsworks_stack.tf-acc",
|
||||||
"https://github.com/aws/opsworks-example-cookbooks.git",
|
"custom_cookbooks_source.0.url",
|
||||||
),
|
"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"]
|
||||||
@ -371,7 +376,7 @@ func testAccCheckAwsOpsworksStackDestroy(s *terraform.State) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := opsworksconn.DescribeStacks(req)
|
r, err := opsworksconn.DescribeStacks(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if awserr, ok := err.(awserr.Error); ok {
|
if awserr, ok := err.(awserr.Error); ok {
|
||||||
if awserr.Code() == "ResourceNotFoundException" {
|
if awserr.Code() == "ResourceNotFoundException" {
|
||||||
@ -382,6 +387,10 @@ func testAccCheckAwsOpsworksStackDestroy(s *terraform.State) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r != nil {
|
||||||
|
log.Printf("\n---\nStack response: %s\n---\n", r)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Fall through error for OpsWorks stack test")
|
return fmt.Errorf("Fall through error for OpsWorks stack test")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user