mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/aws: Convert AWS Internet Gateway (test) to aws-sdk-go
This commit is contained in:
parent
89d6cdb0a6
commit
7643406735
@ -4,9 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/aws-sdk-go/aws"
|
||||||
|
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/goamz/ec2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSInternetGateway(t *testing.T) {
|
func TestAccAWSInternetGateway(t *testing.T) {
|
||||||
@ -20,8 +21,8 @@ func TestAccAWSInternetGateway(t *testing.T) {
|
|||||||
return fmt.Errorf("IG B is not attached")
|
return fmt.Errorf("IG B is not attached")
|
||||||
}
|
}
|
||||||
|
|
||||||
id1 := v.Attachments[0].VpcId
|
id1 := v.Attachments[0].VPCID
|
||||||
id2 := v2.Attachments[0].VpcId
|
id2 := v2.Attachments[0].VPCID
|
||||||
if id1 == id2 {
|
if id1 == id2 {
|
||||||
return fmt.Errorf("Both attachment IDs are the same")
|
return fmt.Errorf("Both attachment IDs are the same")
|
||||||
}
|
}
|
||||||
@ -104,8 +105,8 @@ func TestAccInternetGateway_tags(t *testing.T) {
|
|||||||
Config: testAccCheckInternetGatewayConfigTagsUpdate,
|
Config: testAccCheckInternetGatewayConfigTagsUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v),
|
testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v),
|
||||||
testAccCheckTags(&v.Tags, "foo", ""),
|
testAccCheckTagsSDK(&v.Tags, "foo", ""),
|
||||||
testAccCheckTags(&v.Tags, "bar", "baz"),
|
testAccCheckTagsSDK(&v.Tags, "bar", "baz"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -113,7 +114,7 @@ func TestAccInternetGateway_tags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
|
func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
ec2conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
if rs.Type != "aws_internet_gateway" {
|
if rs.Type != "aws_internet_gateway" {
|
||||||
@ -121,8 +122,9 @@ func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the resource
|
// Try to find the resource
|
||||||
resp, err := conn.DescribeInternetGateways(
|
resp, err := ec2conn.DescribeInternetGateways(&ec2.DescribeInternetGatewaysRequest{
|
||||||
[]string{rs.Primary.ID}, ec2.NewFilter())
|
InternetGatewayIDs: []string{rs.Primary.ID},
|
||||||
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(resp.InternetGateways) > 0 {
|
if len(resp.InternetGateways) > 0 {
|
||||||
return fmt.Errorf("still exists")
|
return fmt.Errorf("still exists")
|
||||||
@ -132,7 +134,7 @@ func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify the error is what we want
|
// Verify the error is what we want
|
||||||
ec2err, ok := err.(*ec2.Error)
|
ec2err, ok := err.(aws.APIError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -155,9 +157,10 @@ func testAccCheckInternetGatewayExists(n string, ig *ec2.InternetGateway) resour
|
|||||||
return fmt.Errorf("No ID is set")
|
return fmt.Errorf("No ID is set")
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
ec2conn := testAccProvider.Meta().(*AWSClient).awsEC2conn
|
||||||
resp, err := conn.DescribeInternetGateways(
|
resp, err := ec2conn.DescribeInternetGateways(&ec2.DescribeInternetGatewaysRequest{
|
||||||
[]string{rs.Primary.ID}, ec2.NewFilter())
|
InternetGatewayIDs: []string{rs.Primary.ID},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user