From 9ac3ce772cbeb9ec572785629d048bbdef2cf179 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 3 Aug 2020 17:12:38 +0200 Subject: [PATCH] Better diagnostic message for "new ARN format" requirement Signed-off-by: Nicolas De Loof --- ecs/pkg/amazon/backend/context.go | 15 ++++++++++++--- ecs/pkg/amazon/backend/up.go | 2 +- ecs/pkg/amazon/sdk/api.go | 2 +- ecs/pkg/amazon/sdk/sdk.go | 7 ++++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ecs/pkg/amazon/backend/context.go b/ecs/pkg/amazon/backend/context.go index f6f79f4e1..c1865117d 100644 --- a/ecs/pkg/amazon/backend/context.go +++ b/ecs/pkg/amazon/backend/context.go @@ -2,6 +2,7 @@ package backend import ( "context" + "fmt" "github.com/docker/ecs-plugin/pkg/docker" ) @@ -12,13 +13,21 @@ const ( ) func (b *Backend) CreateContextData(ctx context.Context, params map[string]string) (contextData interface{}, description string, err error) { - err = b.api.CheckRequirements(ctx) + region, ok := params[ContextParamRegion] + if !ok { + return nil, "", fmt.Errorf("%q parameter is required", ContextParamRegion) + } + profile, ok := params[ContextParamProfile] + if !ok { + return nil, "", fmt.Errorf("%q parameter is required", ContextParamProfile) + } + err = b.api.CheckRequirements(ctx, region) if err != nil { return "", "", err } return docker.AwsContext{ - Profile: params[ContextParamProfile], - Region: params[ContextParamRegion], + Profile: profile, + Region: region, }, "Amazon ECS context", nil } diff --git a/ecs/pkg/amazon/backend/up.go b/ecs/pkg/amazon/backend/up.go index d72794164..6593f07b1 100644 --- a/ecs/pkg/amazon/backend/up.go +++ b/ecs/pkg/amazon/backend/up.go @@ -19,7 +19,7 @@ func (b *Backend) Up(ctx context.Context, options cli.ProjectOptions) error { return err } - err = b.api.CheckRequirements(ctx) + err = b.api.CheckRequirements(ctx, b.Region) if err != nil { return err } diff --git a/ecs/pkg/amazon/sdk/api.go b/ecs/pkg/amazon/sdk/api.go index c56df268d..af6dfed45 100644 --- a/ecs/pkg/amazon/sdk/api.go +++ b/ecs/pkg/amazon/sdk/api.go @@ -9,7 +9,7 @@ import ( ) type API interface { - CheckRequirements(ctx context.Context) error + CheckRequirements(ctx context.Context, region string) error GetDefaultVPC(ctx context.Context) (string, error) VpcExists(ctx context.Context, vpcID string) (bool, error) diff --git a/ecs/pkg/amazon/sdk/sdk.go b/ecs/pkg/amazon/sdk/sdk.go index 2dcd2ca86..da40fa524 100644 --- a/ecs/pkg/amazon/sdk/sdk.go +++ b/ecs/pkg/amazon/sdk/sdk.go @@ -2,7 +2,6 @@ package sdk import ( "context" - "errors" "fmt" "strings" "time" @@ -56,7 +55,7 @@ func NewAPI(sess *session.Session) API { } } -func (s sdk) CheckRequirements(ctx context.Context) error { +func (s sdk) CheckRequirements(ctx context.Context, region string) error { settings, err := s.ECS.ListAccountSettingsWithContext(ctx, &ecs.ListAccountSettingsInput{ EffectiveSettings: aws.Bool(true), Name: aws.String("serviceLongArnFormat"), @@ -66,7 +65,9 @@ func (s sdk) CheckRequirements(ctx context.Context) error { } serviceLongArnFormat := settings.Settings[0].Value if *serviceLongArnFormat != "enabled" { - return errors.New("this tool requires the \"new ARN resource ID format\"") + return fmt.Errorf("this tool requires the \"new ARN resource ID format\".\n"+ + "Check https://%s.console.aws.amazon.com/ecs/home#/settings\n"+ + "Learn more: https://aws.amazon.com/blogs/compute/migrating-your-amazon-ecs-deployment-to-the-new-arn-and-resource-id-format-2", region) } return nil }