From 7fc17a4b55b43bab5264b82fe8db011f89bc2593 Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Thu, 17 Mar 2022 14:17:53 +0300 Subject: [PATCH] Fix ecs.Cluster external name configuration Signed-off-by: Alper Rifat Ulucinar (cherry picked from commit 9079649bb43af20a2ecc471abce5616ec364771b) --- config/ecs/config.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config/ecs/config.go b/config/ecs/config.go index 0732b6c9b..32bfa53ba 100644 --- a/config/ecs/config.go +++ b/config/ecs/config.go @@ -32,6 +32,14 @@ func Configure(p *config.Provider) { p.AddResourceConfigurator("aws_ecs_cluster", func(r *config.Resource) { r.Version = common.VersionV1Alpha2 r.ExternalName = config.NameAsIdentifier + r.ExternalName.GetExternalNameFn = func(tfstate map[string]interface{}) (string, error) { + // expected id format: arn:aws:ecs:us-west-2:123456789123:cluster/example-cluster + w := strings.Split(tfstate["id"].(string), "/") + if len(w) != 2 { + return "", errors.New("terraform ID should be the ARN of the cluster") + } + return w[len(w)-1], nil + } r.References = config.References{ "capacity_providers": config.Reference{ Type: "CapacityProvider",