mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Changed things around as suggested by @catsby
This commit is contained in:
parent
89d01b49ab
commit
d77df312a3
@ -5,7 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
awsGo "github.com/awslabs/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/awslabs/aws-sdk-go/gen/ec2"
|
"github.com/awslabs/aws-sdk-go/gen/ec2"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
@ -65,14 +65,13 @@ func resourceAwsVpc() *schema.Resource {
|
|||||||
|
|
||||||
func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).awsEc2conn
|
ec2conn := meta.(*AWSClient).awsEc2conn
|
||||||
cidr := d.Get("cidr_block").(string)
|
|
||||||
instance_tenancy := "default"
|
instance_tenancy := "default"
|
||||||
if v, ok := d.GetOk("instance_tenancy"); ok {
|
if v, ok := d.GetOk("instance_tenancy"); ok {
|
||||||
instance_tenancy = v.(string)
|
instance_tenancy = v.(string)
|
||||||
}
|
}
|
||||||
// Create the VPC
|
// Create the VPC
|
||||||
createOpts := &ec2.CreateVPCRequest{
|
createOpts := &ec2.CreateVPCRequest{
|
||||||
CIDRBlock: &cidr,
|
CIDRBlock: aws.String(d.Get("cidr_block").(string)),
|
||||||
InstanceTenancy: &instance_tenancy,
|
InstanceTenancy: &instance_tenancy,
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] VPC create config: %#v", *createOpts)
|
log.Printf("[DEBUG] VPC create config: %#v", *createOpts)
|
||||||
@ -156,11 +155,11 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
|
|||||||
// Get the main routing table for this VPC
|
// Get the main routing table for this VPC
|
||||||
// Really Ugly need to make this better - rmenn
|
// Really Ugly need to make this better - rmenn
|
||||||
filter1 := &ec2.Filter{
|
filter1 := &ec2.Filter{
|
||||||
Name: awsGo.String("association.main"),
|
Name: aws.String("association.main"),
|
||||||
Values: []string{("true")},
|
Values: []string{("true")},
|
||||||
}
|
}
|
||||||
filter2 := &ec2.Filter{
|
filter2 := &ec2.Filter{
|
||||||
Name: awsGo.String("vpc-id"),
|
Name: aws.String("vpc-id"),
|
||||||
Values: []string{(d.Id())},
|
Values: []string{(d.Id())},
|
||||||
}
|
}
|
||||||
DescribeRouteOpts := &ec2.DescribeRouteTablesRequest{
|
DescribeRouteOpts := &ec2.DescribeRouteTablesRequest{
|
||||||
@ -239,7 +238,7 @@ func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error {
|
|||||||
}
|
}
|
||||||
log.Printf("[INFO] Deleting VPC: %s", d.Id())
|
log.Printf("[INFO] Deleting VPC: %s", d.Id())
|
||||||
if err := ec2conn.DeleteVPC(DeleteVpcOpts); err != nil {
|
if err := ec2conn.DeleteVPC(DeleteVpcOpts); err != nil {
|
||||||
ec2err, ok := err.(*awsGo.APIError)
|
ec2err, ok := err.(*aws.APIError)
|
||||||
if ok && ec2err.Code == "InvalidVpcID.NotFound" {
|
if ok && ec2err.Code == "InvalidVpcID.NotFound" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -259,7 +258,7 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
|||||||
}
|
}
|
||||||
resp, err := conn.DescribeVPCs(DescribeVpcOpts)
|
resp, err := conn.DescribeVPCs(DescribeVpcOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ec2err, ok := err.(*awsGo.APIError); ok && ec2err.Code == "InvalidVpcID.NotFound" {
|
if ec2err, ok := err.(*aws.APIError); ok && ec2err.Code == "InvalidVpcID.NotFound" {
|
||||||
resp = nil
|
resp = nil
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Error on VPCStateRefresh: %s", err)
|
log.Printf("Error on VPCStateRefresh: %s", err)
|
||||||
@ -280,11 +279,11 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
|
|||||||
|
|
||||||
func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) error {
|
func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) error {
|
||||||
filter1 := &ec2.Filter{
|
filter1 := &ec2.Filter{
|
||||||
Name: awsGo.String("default"),
|
Name: aws.String("default"),
|
||||||
Values: []string{("true")},
|
Values: []string{("true")},
|
||||||
}
|
}
|
||||||
filter2 := &ec2.Filter{
|
filter2 := &ec2.Filter{
|
||||||
Name: awsGo.String("vpc-id"),
|
Name: aws.String("vpc-id"),
|
||||||
Values: []string{(d.Id())},
|
Values: []string{(d.Id())},
|
||||||
}
|
}
|
||||||
DescribeNetworkACLOpts := &ec2.DescribeNetworkACLsRequest{
|
DescribeNetworkACLOpts := &ec2.DescribeNetworkACLsRequest{
|
||||||
@ -304,11 +303,11 @@ func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) e
|
|||||||
|
|
||||||
func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData) error {
|
func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData) error {
|
||||||
filter1 := &ec2.Filter{
|
filter1 := &ec2.Filter{
|
||||||
Name: awsGo.String("group-name"),
|
Name: aws.String("group-name"),
|
||||||
Values: []string{("default")},
|
Values: []string{("default")},
|
||||||
}
|
}
|
||||||
filter2 := &ec2.Filter{
|
filter2 := &ec2.Filter{
|
||||||
Name: awsGo.String("vpc-id"),
|
Name: aws.String("vpc-id"),
|
||||||
Values: []string{(d.Id())},
|
Values: []string{(d.Id())},
|
||||||
}
|
}
|
||||||
DescribeSgOpts := &ec2.DescribeSecurityGroupsRequest{
|
DescribeSgOpts := &ec2.DescribeSecurityGroupsRequest{
|
||||||
|
@ -2,7 +2,7 @@ package aws
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
awsGo "github.com/awslabs/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
"github.com/awslabs/aws-sdk-go/gen/ec2"
|
"github.com/awslabs/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"
|
||||||
@ -132,7 +132,7 @@ func testAccCheckVpcDestroy(s *terraform.State) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify the error is what we want
|
// Verify the error is what we want
|
||||||
ec2err, ok := err.(*awsGo.APIError)
|
ec2err, ok := err.(*aws.APIError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user