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

fix route table for Amazon FSx for NetApp ONTAP routes and tag #21265

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0026f9e
ignore cross account ENIs and FSx Tag
awsaxeman Oct 11, 2021
b0c1e67
Merge remote-tracking branch 'upstream/main' into f-route_table_for_f…
awsaxeman Oct 12, 2021
34460ea
Merge branch 'hashicorp:main' into f-route_table_for_fsx_ontap_routes
awsaxeman Oct 12, 2021
50c946d
ignore cross account ENIs and FSx Tag
awsaxeman Oct 12, 2021
e57cb05
added change log
awsaxeman Oct 13, 2021
5869f47
Merge branch 'hashicorp:main' into f-route_table_for_fsx_ontap_routes
awsaxeman Oct 13, 2021
5a837fe
Merge branch 'f-route_table_for_fsx_ontap_routes' of https://github.c…
awsaxeman Oct 13, 2021
970b3f2
added changelog
awsaxeman Oct 13, 2021
1abdf63
added test for FSx route update
awsaxeman Oct 16, 2021
39389cf
resolve conflict
awsaxeman Oct 16, 2021
3c8c3d3
ignore cross account ENIs and FSx Tag updated to new schema
awsaxeman Oct 17, 2021
9a1af6a
Merge branch 'hashicorp:main' into f-route_table_for_fsx_ontap_routes
awsaxeman Oct 22, 2021
441d254
update FSx tag using Ignore
awsaxeman Oct 22, 2021
1735ce5
Return NotFoundErrors from FindNetworkInterfaceByID/FindNetworkInterf…
ewbankkit Oct 26, 2021
627c4b9
Use 'FindNetworkInterfaceByID' when skipping cross-account ENIs for A…
ewbankkit Oct 26, 2021
133ff03
Remove FSx ONTAP route tests from aws_route_table. Rely on aws_fsx_on…
ewbankkit Oct 26, 2021
1d36b91
r/aws_fsx_ontap_file_system: Test aws_route_table cross-account ENI l…
ewbankkit Oct 26, 2021
c81688d
r/aws_network_interface: Alphabetize attributes.
ewbankkit Oct 26, 2021
82bfdfb
Tweak CHANGELOG entry.
ewbankkit Oct 26, 2021
54b24fe
r/aws_network_interface: Add 'arn' and 'owner_id` attributes.
ewbankkit Oct 26, 2021
cb30abe
r/aws_network_interface: Move wait functionality.
ewbankkit Oct 27, 2021
4cdfe3e
r/aws_network_interface: Retry Read for new resource.
ewbankkit Oct 27, 2021
5124341
r/aws_network_interface: Start to consolidate attach/detach code.
ewbankkit Oct 27, 2021
47f7938
r/aws_network_interface_attachment: Use consolidated attach/detach code.
ewbankkit Nov 2, 2021
8f8b316
Add constants for network interface attach/detach timeouts.
ewbankkit Nov 2, 2021
a1735a9
r/aws_network_interface_sg_attachment: Simplify.
ewbankkit Nov 2, 2021
5ab1e7e
d/aws_network_interface: Use 'FindNetworkInterface'."
ewbankkit Nov 2, 2021
acc3281
d/aws_network_interfaces: Use pagination.
ewbankkit Nov 2, 2021
daa7b8e
r/aws_network_interface: Better error messages.
ewbankkit Nov 2, 2021
3e2f231
r/aws_network_interface: Add 'ipv4_prefix', 'ipv4_prefix_count', 'ipv…
ewbankkit Nov 2, 2021
52e7b77
r/aws_network_interface: 'ipv4_prefix' -> 'ipv4_prefixes' (and the sa…
ewbankkit Nov 2, 2021
aca0e4f
r/aws_network_interface: If IPv4 or IPv6 prefixes are specified, tag …
ewbankkit Nov 2, 2021
7401346
r/aws_network_interface: Tidy up some flex.
ewbankkit Nov 2, 2021
2d84e21
Merge branch 'main' into HEAD
ewbankkit Nov 2, 2021
787bf3a
Fix terrafmt errors.
ewbankkit Nov 2, 2021
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
46 changes: 44 additions & 2 deletions aws/data_source_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func dataSourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("error setting tags: %w", err)
}

if err := d.Set("routes", dataSourceRoutesRead(rt.Routes)); err != nil {
if err := d.Set("routes", dataSourceRoutesRead(rt.Routes, meta)); err != nil {
return err
}

Expand All @@ -239,7 +239,7 @@ func dataSourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error
return nil
}

func dataSourceRoutesRead(ec2Routes []*ec2.Route) []map[string]interface{} {
func dataSourceRoutesRead(ec2Routes []*ec2.Route, meta interface{}) []map[string]interface{} {
routes := make([]map[string]interface{}, 0, len(ec2Routes))
// Loop through the routes and add them to the set
for _, r := range ec2Routes {
Expand All @@ -257,6 +257,48 @@ func dataSourceRoutesRead(ec2Routes []*ec2.Route) []map[string]interface{} {
continue
}

if r.NetworkInterfaceId != nil {

conn := meta.(*AWSClient).ec2conn

describe_network_interfaces_request := &ec2.DescribeNetworkInterfacesInput{
NetworkInterfaceIds: []*string{r.NetworkInterfaceId},
}

describeResp, err := conn.DescribeNetworkInterfaces(describe_network_interfaces_request)

if err != nil {
if isAWSErr(err, "InvalidNetworkInterfaceID.NotFound", "") {
log.Printf("Network Interface %s not found", err)
} else {
log.Printf("Error occured checking network inteface for route: %s", err)
}
}

if len(describeResp.NetworkInterfaces) != 1 {
log.Printf("Unable to find ENI: %s", describeResp.NetworkInterfaces)
} else {

eni := describeResp.NetworkInterfaces[0]

if eni.Attachment != nil {

owner := aws.StringValue(eni.OwnerId)
iowner := aws.StringValue(eni.Attachment.InstanceOwnerId)

log.Printf("[DEBUG] ENI owner: %s, ENI Instane Owner %s", owner, iowner)

if iowner != "" && iowner != owner {
//Skipping cross account ENI for AWS services
log.Printf("Found Cross Account ENI: %s. Skipping", aws.StringValue(describeResp.NetworkInterfaces[0].NetworkInterfaceId))
log.Printf("[DEBUG] Cross Account ENI Details: \n %s", describeResp.NetworkInterfaces[0])
continue
}
}
}

}

m := make(map[string]interface{})

if r.DestinationCidrBlock != nil {
Expand Down
54 changes: 51 additions & 3 deletions aws/resource_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,17 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting propagating_vgws: %w", err)
}

if err := d.Set("route", flattenEc2Routes(routeTable.Routes)); err != nil {
if err := d.Set("route", flattenEc2Routes(routeTable.Routes,meta)); err != nil {
return fmt.Errorf("error setting route: %w", err)
}

tags := keyvaluetags.Ec2KeyValueTags(routeTable.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig)
//Ignore the FSx service tag
var mtag map[string]string
mtag = make(map[string]string)
mtag["AmazonFSx"] = "ManagedByAmazonFSx"
fsxtag := keyvaluetags.New(mtag)

tags := keyvaluetags.Ec2KeyValueTags(routeTable.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Ignore(fsxtag)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
Expand Down Expand Up @@ -851,7 +857,7 @@ func flattenEc2Route(apiObject *ec2.Route) map[string]interface{} {
return tfMap
}

func flattenEc2Routes(apiObjects []*ec2.Route) []interface{} {
func flattenEc2Routes(apiObjects []*ec2.Route,meta interface{}) []interface{} {
if len(apiObjects) == 0 {
return nil
}
Expand All @@ -877,6 +883,48 @@ func flattenEc2Routes(apiObjects []*ec2.Route) []interface{} {
continue
}

if apiObject.NetworkInterfaceId != nil {

conn := meta.(*AWSClient).ec2conn

describe_network_interfaces_request := &ec2.DescribeNetworkInterfacesInput{
NetworkInterfaceIds: []*string{apiObject.NetworkInterfaceId},
}

describeResp, err := conn.DescribeNetworkInterfaces(describe_network_interfaces_request)

if err != nil {
if isAWSErr(err, "InvalidNetworkInterfaceID.NotFound", "") {
log.Printf("Network Interface %s not found" , err)
} else {
log.Printf("Error occured checking network inteface for route: %s", err)
}
}

if len(describeResp.NetworkInterfaces) != 1 {
log.Printf("Unable to find ENI: %s", describeResp.NetworkInterfaces)
} else {

eni := describeResp.NetworkInterfaces[0]

if eni.Attachment != nil {

owner := aws.StringValue(eni.OwnerId)
iowner := aws.StringValue(eni.Attachment.InstanceOwnerId)

log.Printf("[DEBUG] ENI owner: %s, ENI Instane Owner %s",owner,iowner)

if iowner != "" && iowner != owner {
//Skipping cross account ENI for AWS services
log.Printf("Found Cross Account ENI: %s. Skipping",aws.StringValue(describeResp.NetworkInterfaces[0].NetworkInterfaceId))
log.Printf("[DEBUG] Cross Account ENI Details: \n %s",describeResp.NetworkInterfaces[0])
continue
}
}
}

}

tfList = append(tfList, flattenEc2Route(apiObject))
}

Expand Down