github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/import_aws_network_acl.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 6 "github.com/aws/aws-sdk-go/aws" 7 "github.com/aws/aws-sdk-go/service/ec2" 8 "github.com/hashicorp/terraform/helper/schema" 9 ) 10 11 // Network ACLs import their rules and associations 12 func resourceAwsNetworkAclImportState( 13 d *schema.ResourceData, 14 meta interface{}) ([]*schema.ResourceData, error) { 15 conn := meta.(*AWSClient).ec2conn 16 17 // First query the resource itself 18 resp, err := conn.DescribeNetworkAcls(&ec2.DescribeNetworkAclsInput{ 19 NetworkAclIds: []*string{aws.String(d.Id())}, 20 }) 21 if err != nil { 22 return nil, err 23 } 24 if resp == nil || len(resp.NetworkAcls) < 1 || resp.NetworkAcls[0] == nil { 25 return nil, fmt.Errorf("network ACL %s is not found", d.Id()) 26 } 27 acl := resp.NetworkAcls[0] 28 29 // Start building our results 30 results := make([]*schema.ResourceData, 1, 31 2+len(acl.Associations)+len(acl.Entries)) 32 results[0] = d 33 34 /* 35 { 36 // Construct the entries 37 subResource := resourceAwsNetworkAclRule() 38 for _, entry := range acl.Entries { 39 // Minimal data for route 40 d := subResource.Data(nil) 41 d.SetType("aws_network_acl_rule") 42 d.Set("network_acl_id", acl.NetworkAclId) 43 d.Set("rule_number", entry.RuleNumber) 44 d.Set("egress", entry.Egress) 45 d.Set("protocol", entry.Protocol) 46 d.SetId(networkAclIdRuleNumberEgressHash( 47 d.Get("network_acl_id").(string), 48 d.Get("rule_number").(int), 49 d.Get("egress").(bool), 50 d.Get("protocol").(string))) 51 results = append(results, d) 52 } 53 } 54 55 { 56 // Construct the associations 57 subResource := resourceAwsRouteTableAssociation() 58 for _, assoc := range table.Associations { 59 if *assoc.Main { 60 // Ignore 61 continue 62 } 63 64 // Minimal data for route 65 d := subResource.Data(nil) 66 d.SetType("aws_route_table_association") 67 d.Set("route_table_id", assoc.RouteTableId) 68 d.SetId(*assoc.RouteTableAssociationId) 69 results = append(results, d) 70 } 71 } 72 73 { 74 // Construct the main associations. We could do this above but 75 // I keep this as a separate section since it is a separate resource. 76 subResource := resourceAwsMainRouteTableAssociation() 77 for _, assoc := range table.Associations { 78 if !*assoc.Main { 79 // Ignore 80 continue 81 } 82 83 // Minimal data for route 84 d := subResource.Data(nil) 85 d.SetType("aws_main_route_table_association") 86 d.Set("route_table_id", id) 87 d.Set("vpc_id", table.VpcId) 88 d.SetId(*assoc.RouteTableAssociationId) 89 results = append(results, d) 90 } 91 } 92 */ 93 94 return results, nil 95 }