Просмотр исходного кода

Better diagnostic message for "new ARN format" requirement

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 5 лет назад
Родитель
Сommit
9ac3ce772c

+ 12 - 3
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
 }

+ 1 - 1
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
 	}

+ 1 - 1
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)

+ 4 - 3
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
 }