Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Resource] aws_default_internet_gateway #37899

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
somewhat working
  • Loading branch information
PeterSzegedi committed Jun 9, 2024
commit e03ed26dcbe67baf9413edf16c9a4a5d537bd572
8 changes: 8 additions & 0 deletions internal/service/ec2/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 33 additions & 20 deletions internal/service/ec2/vpc_default_internet_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"log"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go/aws"

"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -82,41 +83,53 @@ func resourceDefaultInternetGatewayCreate(ctx context.Context, d *schema.Resourc
},
),
}
_, err := findVPCV2(ctx, ec2Client, input)

vpc, err := findVPCV2(ctx, ec2Client, input)
if err == nil {

// Check if there is an IGW assigned to the default VPC
input := &ec2.DescribeInternetGatewaysInput{}
input.Filters = newAttributeFilterList(map[string]string{
"attachment.vpc-id": d.Get(names.AttrVPCID).(string),
"attachment.vpc-id": *vpc.VpcId,
})

conn := meta.(*conns.AWSClient).EC2Conn(ctx)

_, err := FindInternetGateway(ctx, conn, input)

// Attached IGW not found, so we create one
if err != nil {
igw, err := FindInternetGateway(ctx, conn, input)
log.Printf("found igw with ID: %s", igw)

input := &ec2.CreateInternetGatewayInput{
TagSpecifications: getTagSpecificationsIn(ctx, ec2.ResourceTypeInternetGateway),
}
if err == nil {
d.SetId(aws.ToString(igw.InternetGatewayId))
d.Set("existing_default_internet_gateway", true)

log.Printf("[DEBUG] Creating EC2 Internet Gateway: %s", input)
output, err := conn.CreateInternetGatewayWithContext(ctx, input)
} else if tfresource.NotFound(err) {
log.Printf("not implemented yet")
} else {
log.Printf("some error")

}
/*
// Attached IGW not found, so we create one
if err != nil {
return sdkdiag.AppendErrorf(diags, "creating EC2 Internet Gateway: %s", err)
}
log.Print("creating default igw")
input := &ec2.CreateInternetGatewayInput{
TagSpecifications: getTagSpecificationsIn(ctx, ec2.ResourceTypeInternetGateway),
}

d.SetId(aws.StringValue(output.InternetGateway.InternetGatewayId))
//log.Printf("[DEBUG] Creating EC2 Internet Gateway: %s", input)
//output, err := conn.CreateInternetGatewayWithContext(ctx, input)

if v, ok := d.GetOk(names.AttrVPCID); ok {
if err := attachInternetGateway(ctx, conn, d.Id(), v.(string), d.Timeout(schema.TimeoutCreate)); err != nil {
if err != nil {
return sdkdiag.AppendErrorf(diags, "creating EC2 Internet Gateway: %s", err)
}
}
}

//d.SetId(aws.StringValue(output.InternetGateway.InternetGatewayId))

if v, ok := d.GetOk(names.AttrVPCID); ok {
if err := attachInternetGateway(ctx, conn, d.Id(), v.(string), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "creating EC2 Internet Gateway: %s", err)
}
}
}*/
}
return append(diags, resourceInternetGatewayRead(ctx, d, meta)...)
}
Expand Down