Skip to content

Commit

Permalink
Add support for aws_ecs_service
Browse files Browse the repository at this point in the history
  • Loading branch information
kishaningithub committed Oct 1, 2024
1 parent 8f89cdd commit d0e022c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,20 @@ func computeResourceID(resource parser.TerraformResource) string {
return fmt.Sprintf("%s/%s/%s", v("service_namespace"), v("resource_id"), v("scalable_dimension"))
case "aws_appautoscaling_policy":
return fmt.Sprintf("%s/%s/%s/%s", v("service_namespace"), v("resource_id"), v("scalable_dimension"), v("name"))
case "aws_ecs_service":
return fmt.Sprintf("%s/%s", getEcsClusterNameFromARN(v("cluster")), v("name"))
default:
return v("id")
}
}

func getEcsClusterNameFromARN(arn string) string {
if parts := strings.Split(arn, "/"); len(parts) == 2 {
return parts[1]
}
return ""
}

func computeResourceIDForAWSSecurityGroupRole(resource parser.TerraformResource) string {
// Required Fields
securityGroupId := fmt.Sprint(resource.AttributeValues["security_group_id"])
Expand Down
16 changes: 16 additions & 0 deletions pkg/convertor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,22 @@ func Test_ComputeTerraformImportForResource(t *testing.T) {
SupportsImport: true,
},
},
{
name: "For aws_ecs_service",
terraformResource: parser.TerraformResource{
Address: "aws_ecs_service.test",
Type: "aws_ecs_service",
AttributeValues: map[string]any{
"name": "service_name",
"cluster": "arn:aws:ecs:us-west-2:0123456789:cluster/cluster_name",
},
},
expected: TerraformImport{
ResourceAddress: "aws_ecs_service.test",
ResourceID: "cluster_name/service_name",
SupportsImport: true,
},
},
{
name: "For everything else",
terraformResource: parser.TerraformResource{
Expand Down

0 comments on commit d0e022c

Please sign in to comment.