Skip to content

Commit 8631782

Browse files
Merge pull request #45 from sgraupmann/new_aws_resource_types
Added support for a couple resource types.
2 parents 55c63c1 + e1fe8a7 commit 8631782

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

pkg/convertor.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package tfimportgen
22

33
import (
44
"fmt"
5-
"github.com/kishaningithub/tf-import-gen/pkg/internal/parser"
65
"slices"
76
"strings"
7+
8+
"github.com/kishaningithub/tf-import-gen/pkg/internal/parser"
89
)
910

1011
func computeTerraformImportForResource(resource parser.TerraformResource) TerraformImport {
@@ -58,6 +59,8 @@ func computeResourceID(resource parser.TerraformResource) string {
5859
return fmt.Sprintf("%s/%s", v("function_name"), v("statement_id"))
5960
case "aws_security_group_rule":
6061
return computeResourceIDForAWSSecurityGroupRole(resource)
62+
case "aws_network_acl_rule":
63+
return computeResourceIdForAWSNetworkACLRule(resource)
6164
case "aws_api_gateway_resource", "aws_api_gateway_deployment":
6265
return fmt.Sprintf("%s/%s", v("rest_api_id"), v("id"))
6366
case "aws_api_gateway_stage":
@@ -76,6 +79,8 @@ func computeResourceID(resource parser.TerraformResource) string {
7679
return fmt.Sprintf("%s|%s", v("plan_id"), v("id"))
7780
case "aws_vpc_endpoint_route_table_association":
7881
return fmt.Sprintf("%s/%s", v("vpc_endpoint_id"), v("route_table_id"))
82+
case "aws_vpc_endpoint_subnet_association":
83+
return fmt.Sprintf("%s/%s", v("vpc_endpoint_id"), v("subnet_id"))
7984
case "aws_cognito_user_pool_client":
8085
return fmt.Sprintf("%s/%s", v("user_pool_id"), v("id"))
8186
case "aws_ecs_cluster":
@@ -220,6 +225,14 @@ func computeResourceIDForAWSSecurityGroupRole(resource parser.TerraformResource)
220225
return resourceID
221226
}
222227

228+
func computeResourceIdForAWSNetworkACLRule(resource parser.TerraformResource) string {
229+
networkACLId := fmt.Sprint(resource.AttributeValues["network_acl_id"])
230+
ruleNumber := fmt.Sprint(resource.AttributeValues["rule_number"])
231+
protocol := fmt.Sprint(resource.AttributeValues["protocol"])
232+
egress := fmt.Sprint(resource.AttributeValues["egress"])
233+
return fmt.Sprintf("%s:%s:%s:%s", networkACLId, ruleNumber, protocol, egress)
234+
}
235+
223236
func convertToStrings(source []any) []string {
224237
var result []string
225238
for _, element := range source {

pkg/convertor_test.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package tfimportgen
22

33
import (
4+
"testing"
5+
46
"github.com/kishaningithub/tf-import-gen/pkg/internal/parser"
57
"github.com/stretchr/testify/require"
6-
"testing"
78
)
89

910
func Test_ComputeTerraformImportForResource(t *testing.T) {
@@ -299,6 +300,40 @@ func Test_ComputeTerraformImportForResource(t *testing.T) {
299300
SupportsImport: true,
300301
},
301302
},
303+
{
304+
name: "For aws_vpc_endpoint_subnet_association",
305+
terraformResource: parser.TerraformResource{
306+
Address: "aws_vpc_endpoint_subnet_association.test",
307+
Type: "aws_vpc_endpoint_subnet_association",
308+
AttributeValues: map[string]any{
309+
"vpc_endpoint_id": "vpce-12345",
310+
"subnet_id": "subnet-67890",
311+
},
312+
},
313+
expected: TerraformImport{
314+
ResourceAddress: "aws_vpc_endpoint_subnet_association.test",
315+
ResourceID: "vpce-12345/subnet-67890",
316+
SupportsImport: true,
317+
},
318+
},
319+
{
320+
name: "For aws_network_acl_rule",
321+
terraformResource: parser.TerraformResource{
322+
Address: "aws_network_acl_rule.test",
323+
Type: "aws_network_acl_rule",
324+
AttributeValues: map[string]any{
325+
"network_acl_id": "acl-12345",
326+
"rule_number": 100,
327+
"protocol": "6",
328+
"egress": false,
329+
},
330+
},
331+
expected: TerraformImport{
332+
ResourceAddress: "aws_network_acl_rule.test",
333+
ResourceID: "acl-12345:100:6:false",
334+
SupportsImport: true,
335+
},
336+
},
302337
{
303338
name: "For aws_cognito_user_pool_client",
304339
terraformResource: parser.TerraformResource{

0 commit comments

Comments
 (0)