Better diagnostic message for "new ARN format" requirement

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-08-03 17:12:38 +02:00
parent 0df99075cc
commit 9ac3ce772c
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
4 changed files with 18 additions and 8 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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
}