Repository: aws/amazon-ecs-cli-v2
Pull request #247 (2019-10-29 21:19:29)

Move DeployEnvironmentInput to the deploy pkg
1. Moved the `DeployEnvironmentInput` struct to `deploy` pkg
2. Renamed the struct to just `Environment`

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.



Patch:
diff --git a/internal/pkg/archer/env.go b/internal/pkg/archer/env.go
index f6681c7a..757c0c2d 100644
--- a/internal/pkg/archer/env.go
+++ b/internal/pkg/archer/env.go
@@ -4,9 +4,10 @@
 // Package archer contains the structs that represent archer concepts, and the associated interfaces to manipulate them.
 package archer
 
-// Environment represents the configuration of a particular Environment in a Project. It includes
-// the location of the Environment (account and region), the name of the environment, as well as the project
-// the environment belongs to.
+import "github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy"
+
+// Environment represents the configuration of a particular environment in a project. It includes
+// the environment's account and region, name, as well as the project it belongs to.
 type Environment struct {
 	Project     string `json:"project"`     // Name of the project this environment belongs to.
 	Name        string `json:"name"`        // Name of the environment, must be unique within a project.
@@ -16,15 +17,6 @@ type Environment struct {
 	RegistryURL string `json:"registryURL"` // URL For ECR Registry for this environment.
 }
 
-// DeployEnvironmentInput represents the fields required to setup and deploy an environment
-type DeployEnvironmentInput struct {
-	Project                  string // Name of the project this environment belongs to.
-	Name                     string // Name of the environment, must be unique within a project.
-	Prod                     bool   // Whether or not this environment is a production environment.
-	PublicLoadBalancer       bool   // Whether or not this environment should contain a shared public load balancer between applications.
-	ToolsAccountPrincipalARN string // The Principal ARN of the tools account.
-}
-
 // EnvironmentStore can List, Create and Get environments in an underlying project management store
 type EnvironmentStore interface {
 	EnvironmentLister
@@ -49,6 +41,6 @@ type EnvironmentCreator interface {
 
 // EnvironmentDeployer can deploy an environment
 type EnvironmentDeployer interface {
-	DeployEnvironment(env *DeployEnvironmentInput) error
-	WaitForEnvironmentCreation(env *DeployEnvironmentInput) (*Environment, error)
+	DeployEnvironment(env *deploy.CreateEnvironmentInput) error
+	WaitForEnvironmentCreation(env *deploy.CreateEnvironmentInput) (*Environment, error)
 }
diff --git a/internal/pkg/cli/app_package.go b/internal/pkg/cli/app_package.go
index 28e941c9..cd87d5c1 100644
--- a/internal/pkg/cli/app_package.go
+++ b/internal/pkg/cli/app_package.go
@@ -26,7 +26,7 @@ type PackageAppOpts struct {
 func NewPackageAppOpts() *PackageAppOpts {
 	commitID, err := exec.Command("git", "rev-parse", "--short", "HEAD").CombinedOutput()
 	if err != nil {
-		// If we can't retrieve a commit ID we default the image tag to 'latest'
+		// If we can't retrieve a commit ID we default the image tag to "latest".
 		return &PackageAppOpts{
 			Tag:    "latest",
 			prompt: prompt.New(),
diff --git a/internal/pkg/cli/env_init.go b/internal/pkg/cli/env_init.go
index 6699df01..dabdc397 100644
--- a/internal/pkg/cli/env_init.go
+++ b/internal/pkg/cli/env_init.go
@@ -10,6 +10,7 @@ import (
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/archer"
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/aws/identity"
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/aws/session"
+	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy"
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy/cloudformation"
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/store/ssm"
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/term/color"
@@ -77,7 +78,7 @@ func (opts *InitEnvOpts) Execute() error {
 		return fmt.Errorf("get identity: %w", err)
 	}
 
-	deployEnvInput := &archer.DeployEnvironmentInput{
+	deployEnvInput := &deploy.CreateEnvironmentInput{
 		Name:                     opts.EnvName,
 		Project:                  viper.GetString(projectFlag),
 		Prod:                     opts.IsProduction,
diff --git a/internal/pkg/deploy/cloudformation/cloudformation.go b/internal/pkg/deploy/cloudformation/cloudformation.go
index 0d30123d..23deea02 100644
--- a/internal/pkg/deploy/cloudformation/cloudformation.go
+++ b/internal/pkg/deploy/cloudformation/cloudformation.go
@@ -10,6 +10,7 @@ import (
 	"strings"
 
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/archer"
+	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy"
 	"github.com/aws/amazon-ecs-cli-v2/templates"
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/aws/awserr"
@@ -51,7 +52,7 @@ func New(sess *session.Session) CloudFormation {
 // If the stack already exists, returns a ErrStackAlreadyExists.
 // If the change set to create the stack cannot be executed, returns a ErrNotExecutableChangeSet.
 // Otherwise, returns a wrapped error.
-func (cf CloudFormation) DeployEnvironment(env *archer.DeployEnvironmentInput) error {
+func (cf CloudFormation) DeployEnvironment(env *deploy.CreateEnvironmentInput) error {
 	return cf.deploy(newEnvStackConfig(env, cf.box))
 }
 
@@ -83,7 +84,7 @@ func (cf CloudFormation) deploy(stackConfig stackConfiguration) error {
 // WaitForEnvironmentCreation will block until the environment's CloudFormation stack has completed or errored.
 // Once the deployment is complete, it read the stack output and create an environment with the resources from
 // the stack like ECR Repo.
-func (cf CloudFormation) WaitForEnvironmentCreation(env *archer.DeployEnvironmentInput) (*archer.Environment, error) {
+func (cf CloudFormation) WaitForEnvironmentCreation(env *deploy.CreateEnvironmentInput) (*archer.Environment, error) {
 	cfEnv := newEnvStackConfig(env, cf.box)
 	deployedStack, err := cf.waitForStackCreation(cfEnv)
 	if err != nil {
diff --git a/internal/pkg/deploy/cloudformation/env.go b/internal/pkg/deploy/cloudformation/env.go
index 53499f87..c84337f2 100644
--- a/internal/pkg/deploy/cloudformation/env.go
+++ b/internal/pkg/deploy/cloudformation/env.go
@@ -5,6 +5,7 @@ import (
 	"strconv"
 
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/archer"
+	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy"
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/aws/arn"
 	"github.com/aws/aws-sdk-go/service/cloudformation"
@@ -15,7 +16,7 @@ import (
 // envStackConfig is for providing all the values to set up an
 // environment stack and to interpret the outputs from it.
 type envStackConfig struct {
-	*archer.DeployEnvironmentInput
+	*deploy.CreateEnvironmentInput
 	box packd.Box
 }
 
@@ -37,9 +38,9 @@ const (
 
 // newEnvStackConfig sets up a struct which can provide values to CloudFormation for
 // spinning up an environment.
-func newEnvStackConfig(input *archer.DeployEnvironmentInput, box packd.Box) *envStackConfig {
+func newEnvStackConfig(input *deploy.CreateEnvironmentInput, box packd.Box) *envStackConfig {
 	return &envStackConfig{
-		DeployEnvironmentInput: input,
+		CreateEnvironmentInput: input,
 		box:                    box,
 	}
 }
diff --git a/internal/pkg/deploy/deploy.go b/internal/pkg/deploy/deploy.go
new file mode 100644
index 00000000..8dd5af20
--- /dev/null
+++ b/internal/pkg/deploy/deploy.go
@@ -0,0 +1,14 @@
+// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+// Package deploy holds the structures to deploy applications and environments.
+package deploy
+
+// CreateEnvironmentInput represents the fields required to deploy an environment.
+type CreateEnvironmentInput struct {
+	Project                  string // Name of the project this environment belongs to.
+	Name                     string // Name of the environment, must be unique within a project.
+	Prod                     bool   // Whether or not this environment is a production environment.
+	PublicLoadBalancer       bool   // Whether or not this environment should contain a shared public load balancer between applications.
+	ToolsAccountPrincipalARN string // The Principal ARN of the tools account.
+}
diff --git a/internal/pkg/manifest/pipeline.go b/internal/pkg/manifest/pipeline.go
index 20409eab..ff14cf06 100644
--- a/internal/pkg/manifest/pipeline.go
+++ b/internal/pkg/manifest/pipeline.go
@@ -86,7 +86,7 @@ type Source struct {
 }
 
 // PipelineStage represents configuration for each deployment stage
-// of a workspace. A stage consists of the Archer Environment the pipeline
+// of a workspace. A stage consists of the Archer environment the pipeline
 // is deloying to and the containerized applications that will be deployed.
 type PipelineStage struct {
 	*AssociatedEnvironment `yaml:",inline"`
@@ -94,7 +94,7 @@ type PipelineStage struct {
 }
 
 // AssociatedEnvironment defines the necessary information a pipline stage
-// needs for an Archer Environment.
+// needs for an Archer environment.
 type AssociatedEnvironment struct {
 	Project   string `yaml:"-"`    // Name of the project this environment belongs to.
 	Name      string `yaml:"name"` // Name of the environment, must be unique within a project.
diff --git a/internal/pkg/store/ssm/ssm.go b/internal/pkg/store/ssm/ssm.go
index 4a4e0d68..86b85ccd 100644
--- a/internal/pkg/store/ssm/ssm.go
+++ b/internal/pkg/store/ssm/ssm.go
@@ -2,8 +2,8 @@
 // SPDX-License-Identifier: Apache-2.0
 
 /*
-Package ssm implements CRUD operations for Package, Environment and
-Pipeline configuration. This configuration contains the archer projects
+Package ssm implements CRUD operations for project, environment, application and
+pipeline configuration. This configuration contains the archer projects
 a customer has, and the environments and pipelines associated with each
 project.
 */
@@ -47,7 +47,7 @@ type identityService interface {
 	Get() (identity.Caller, error)
 }
 
-// SSM store is in charge of fetching and creating Projects, Environment and Pipeline
+// SSM store is in charge of fetching and creating projects, environment and pipeline
 // configuration in SSM.
 type SSM struct {
 	systemManager ssmiface.SSMAPI
@@ -183,7 +183,7 @@ func (s *SSM) CreateEnvironment(environment *archer.Environment) error {
 		return fmt.Errorf("create environment %s in project %s: %w", environment.Name, environment.Project, err)
 	}
 
-	log.Printf("Created Environment with version %v", *paramOutput.Version)
+	log.Printf("Created environment with version %v", *paramOutput.Version)
 	return nil
 
 }
diff --git a/mocks/mock_env.go b/mocks/mock_env.go
index 95c31bdd..af53c1ca 100644
--- a/mocks/mock_env.go
+++ b/mocks/mock_env.go
@@ -5,9 +5,11 @@
 package mocks
 
 import (
+	reflect "reflect"
+
 	archer "github.com/aws/amazon-ecs-cli-v2/internal/pkg/archer"
+	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy"
 	gomock "github.com/golang/mock/gomock"
-	reflect "reflect"
 )
 
 // MockEnvironmentStore is a mock of EnvironmentStore interface
@@ -214,7 +216,7 @@ func (m *MockEnvironmentDeployer) EXPECT() *MockEnvironmentDeployerMockRecorder
 }
 
 // DeployEnvironment mocks base method
-func (m *MockEnvironmentDeployer) DeployEnvironment(env *archer.DeployEnvironmentInput) error {
+func (m *MockEnvironmentDeployer) DeployEnvironment(env *deploy.CreateEnvironmentInput) error {
 	m.ctrl.T.Helper()
 	ret := m.ctrl.Call(m, "DeployEnvironment", env)
 	ret0, _ := ret[0].(error)
@@ -228,7 +230,7 @@ func (mr *MockEnvironmentDeployerMockRecorder) DeployEnvironment(env interface{}
 }
 
 // WaitForEnvironmentCreation mocks base method
-func (m *MockEnvironmentDeployer) WaitForEnvironmentCreation(env *archer.DeployEnvironmentInput) (*archer.Environment, error) {
+func (m *MockEnvironmentDeployer) WaitForEnvironmentCreation(env *deploy.CreateEnvironmentInput) (*archer.Environment, error) {
 	m.ctrl.T.Helper()
 	ret := m.ctrl.Call(m, "WaitForEnvironmentCreation", env)
 	ret0, _ := ret[0].(*archer.Environment)


Test patch:
diff --git a/internal/pkg/deploy/cloudformation/cloudformation_integration_test.go b/internal/pkg/deploy/cloudformation/cloudformation_integration_test.go
index a8eac1d6..aa4cfe95 100644
--- a/internal/pkg/deploy/cloudformation/cloudformation_integration_test.go
+++ b/internal/pkg/deploy/cloudformation/cloudformation_integration_test.go
@@ -12,8 +12,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/archer"
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/aws/identity"
+	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy"
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy/cloudformation"
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/aws/session"
@@ -39,10 +39,10 @@ func Test_Environment_Deployment_Integration(t *testing.T) {
 	id, err := identity.Get()
 	require.NoError(t, err)
 
-	environmentToDeploy := archer.DeployEnvironmentInput{Name: randStringBytes(10), Project: randStringBytes(10), PublicLoadBalancer: true, ToolsAccountPrincipalARN: id.ARN}
+	environmentToDeploy := deploy.CreateEnvironmentInput{Name: randStringBytes(10), Project: randStringBytes(10), PublicLoadBalancer: true, ToolsAccountPrincipalARN: id.ARN}
 	envStackName := fmt.Sprintf("%s-%s", environmentToDeploy.Project, environmentToDeploy.Name)
 
-	t.Run("Deploys an Environment to CloudFormation", func(t *testing.T) {
+	t.Run("Deploys an environment to CloudFormation", func(t *testing.T) {
 		// Given our stack doesn't exist
 		output, err := cfClient.DescribeStacks(&awsCF.DescribeStacksInput{
 			StackName: aws.String(envStackName),
diff --git a/internal/pkg/deploy/cloudformation/cloudformation_test.go b/internal/pkg/deploy/cloudformation/cloudformation_test.go
index 100a79ce..ffea1aff 100644
--- a/internal/pkg/deploy/cloudformation/cloudformation_test.go
+++ b/internal/pkg/deploy/cloudformation/cloudformation_test.go
@@ -9,7 +9,7 @@ import (
 	"regexp"
 	"testing"
 
-	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/archer"
+	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy"
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/aws/awserr"
 	"github.com/aws/aws-sdk-go/service/cloudformation"
@@ -359,7 +359,7 @@ func TestWaitForStackCreation(t *testing.T) {
 }
 
 func TestWaitForEnvironmentCreation(t *testing.T) {
-	deploymentInput := archer.DeployEnvironmentInput{
+	deploymentInput := deploy.CreateEnvironmentInput{
 		Name:    "test",
 		Project: "project",
 	}
@@ -367,7 +367,7 @@ func TestWaitForEnvironmentCreation(t *testing.T) {
 
 	testCases := map[string]struct {
 		cf    CloudFormation
-		input archer.DeployEnvironmentInput
+		input deploy.CreateEnvironmentInput
 		want  error
 	}{
 		"error in waitForStackCreation call": {
diff --git a/internal/pkg/deploy/cloudformation/env_test.go b/internal/pkg/deploy/cloudformation/env_test.go
index d7df22a6..6e591347 100644
--- a/internal/pkg/deploy/cloudformation/env_test.go
+++ b/internal/pkg/deploy/cloudformation/env_test.go
@@ -9,6 +9,7 @@ import (
 	"testing"
 
 	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/archer"
+	"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy"
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/service/cloudformation"
 	"github.com/gobuffalo/packd"
@@ -142,8 +143,8 @@ func mockEnvironmentStack(stackArn, ecrOutput string) *cloudformation.Stack {
 	}
 }
 
-func mockDeployEnvironmentInput() *archer.DeployEnvironmentInput {
-	return &archer.DeployEnvironmentInput{
+func mockDeployEnvironmentInput() *deploy.CreateEnvironmentInput {
+	return &deploy.CreateEnvironmentInput{
 		Name:                     "env",
 		Project:                  "project",
 		Prod:                     true,