diff --git a/.github/workflows/run.e2e-tests.yml b/.github/workflows/run.e2e-tests.yml index d1eae919..5deaaf13 100644 --- a/.github/workflows/run.e2e-tests.yml +++ b/.github/workflows/run.e2e-tests.yml @@ -181,7 +181,7 @@ jobs: runs-on: ${{ matrix.os }} env: - IZE_EXAMPLES_PATH: ${{ github.workspace }}/examples/ecs-apps-monorepo + IZE_EXAMPLES_PATH: ${{ github.workspace }}/examples/sls-apps-monorepo steps: - name: Configure Environment Variables run: | @@ -225,8 +225,3 @@ jobs: - name: Run Tests run: | go test -v --timeout 0 --tags="e2e terraform" ./test-e2e - - - name: Cleanup Infra - run: | - cd "${{ env.IZE_EXAMPLES_PATH }}" - ize down --auto-approve diff --git a/examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml b/examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml index 5fb99df8..36b684dd 100644 --- a/examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml +++ b/examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml @@ -27,7 +27,7 @@ terraform_version = "1.2.6" # (optional) Terraform version can be se root_domain_name = "examples.ize.sh" # (optional) Root domain name can be set here. This is the main domain that will be passed to the terraform. Generally if your app lives at 'api.dev.nutcorp.net' the root domain is `nutcorp.net` [ecs.squibby] -# timeout = "" # (optional) ECS deployment timeout can be specified here. +timeout = 0 # (optional) ECS deployment timeout can be specified here. # docker_registry = "" # (optional) Docker registry can be set here. By default it uses ECR repo with the name of the service. # skip_deploy = false # skip deploy app # path = "" # (optional) Path to ecs app folder can be specified here. By default it's derived from apps path and app name. @@ -38,7 +38,7 @@ root_domain_name = "examples.ize.sh" # (optional) Root domain name can be set [ecs.goblin] -# timeout = "" # (optional) ECS deployment timeout can be specified here. +timeout = 0 # (optional) ECS deployment timeout can be specified here. # docker_registry = "" # (optional) Docker registry can be set here. By default it uses ECR repo with the name of the service. # skip_deploy = false # skip deploy app # path = "" # (optional) Path to ecs app folder can be specified here. By default it's derived from apps path and app name. diff --git a/internal/commands/down.go b/internal/commands/down.go index f96b5648..3ac8ef4d 100644 --- a/internal/commands/down.go +++ b/internal/commands/down.go @@ -123,7 +123,7 @@ func (o *DownOptions) Complete(cmd *cobra.Command, args []string) error { } if len(o.Config.Terraform["infra"].AwsRegion) == 0 { - o.Config.Terraform["infra"].AwsProfile = o.Config.AwsRegion + o.Config.Terraform["infra"].AwsRegion = o.Config.AwsRegion } if len(o.Config.Terraform["infra"].Version) == 0 { diff --git a/internal/commands/tfenv.go b/internal/commands/tfenv.go index dc56e518..23737dae 100644 --- a/internal/commands/tfenv.go +++ b/internal/commands/tfenv.go @@ -160,12 +160,15 @@ func GenerateTerraformFiles(project *config.Project, terraformStateBucketName st AWS_REGION: project.AwsRegion, EC2_KEY_PAIR_NAME: fmt.Sprintf("%v-%v", project.Env, project.Namespace), ROOT_DOMAIN_NAME: tf.RootDomainName, - TAG: project.Tag, SSH_PUBLIC_KEY: string(key)[:len(string(key))-1], - DOCKER_REGISTRY: project.DockerRegistry, NAMESPACE: project.Namespace, } + if len(project.Ecs) != 0 { + varsOpts.TAG = project.Tag + varsOpts.DOCKER_REGISTRY = project.DockerRegistry + } + logrus.Debugf("backend opts: %s", varsOpts) logrus.Debugf("ENV dir path: %s", envDir) diff --git a/internal/commands/tfenv_test.go b/internal/commands/tfenv_test.go index aabcc790..0bd98443 100644 --- a/internal/commands/tfenv_test.go +++ b/internal/commands/tfenv_test.go @@ -36,6 +36,7 @@ func TestTfenv(t *testing.T) { env map[string]string mockS3Client func(m *mocks.MockS3API) mockSTSClient func(m *mocks.MockSTSAPI) + withECS bool }{ { name: "success (only config file)", @@ -43,6 +44,7 @@ func TestTfenv(t *testing.T) { env: map[string]string{"ENV": "test", "AWS_PROFILE": "test"}, withConfigFile: true, wantErr: false, + withECS: true, mockS3Client: func(m *mocks.MockS3API) { m.EXPECT().HeadBucket(gomock.Any()).Return(nil, nil).AnyTimes() }, @@ -90,6 +92,7 @@ root_domain_name = "examples.ize.sh" m.EXPECT().HeadBucket(gomock.Any()).Return(nil, nil).AnyTimes() }, mockSTSClient: func(m *mocks.MockSTSAPI) {}, + withECS: true, wantBackend: `provider "aws" { profile = var.aws_profile region = var.aws_region @@ -132,6 +135,7 @@ root_domain_name = "examples.ize.sh" mockS3Client: func(m *mocks.MockS3API) { m.EXPECT().HeadBucket(gomock.Any()).Return(nil, nil).AnyTimes() }, + withECS: true, mockSTSClient: func(m *mocks.MockSTSAPI) {}, wantBackend: `provider "aws" { profile = var.aws_profile @@ -205,9 +209,7 @@ terraform { aws_profile = "test" aws_region = "us-east-1" ec2_key_pair_name = "test-testnut" -docker_image_tag = "test" ssh_public_key = -docker_registry = "0.dkr.ecr.us-east-1.amazonaws.com" namespace = "testnut" `, }, @@ -243,9 +245,7 @@ terraform { aws_profile = "test" aws_region = "us-east-1" ec2_key_pair_name = "test-testnut" -docker_image_tag = "test" ssh_public_key = -docker_registry = "0.dkr.ecr.us-east-1.amazonaws.com" namespace = "testnut" `, }, @@ -288,9 +288,7 @@ terraform { aws_profile = "test" aws_region = "us-west-2" ec2_key_pair_name = "test-testnut" -docker_image_tag = "test" ssh_public_key = -docker_registry = "0.dkr.ecr.us-west-2.amazonaws.com" namespace = "testnut" `, }, @@ -323,6 +321,16 @@ namespace = "testnut" if tt.withConfigFile { setConfigFile(filepath.Join(temp, "ize.toml"), tfenvToml, t) + if tt.withECS { + f, err := os.OpenFile(filepath.Join(temp, "ize.toml"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + panic(err) + } + defer f.Close() + if _, err = f.WriteString("\n\n[ecs.squibby]\ntimeout = 0"); err != nil { + panic(err) + } + } } t.Setenv("HOME", temp) diff --git a/internal/template/template.go b/internal/template/template.go index 23f49178..7ef18614 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -31,9 +31,13 @@ func GenerateVarsTf(opts VarsOpts, path string) error { rootBody.SetAttributeValue("aws_profile", cty.StringVal(opts.AWS_PROFILE)) rootBody.SetAttributeValue("aws_region", cty.StringVal(opts.AWS_REGION)) rootBody.SetAttributeValue("ec2_key_pair_name", cty.StringVal(opts.EC2_KEY_PAIR_NAME)) - rootBody.SetAttributeValue("docker_image_tag", cty.StringVal(opts.TAG)) + if len(opts.TAG) != 0 { + rootBody.SetAttributeValue("docker_image_tag", cty.StringVal(opts.TAG)) + } rootBody.SetAttributeValue("ssh_public_key", cty.StringVal(opts.SSH_PUBLIC_KEY)) - rootBody.SetAttributeValue("docker_registry", cty.StringVal(opts.DOCKER_REGISTRY)) + if len(opts.DOCKER_REGISTRY) != 0 { + rootBody.SetAttributeValue("docker_registry", cty.StringVal(opts.DOCKER_REGISTRY)) + } rootBody.SetAttributeValue("namespace", cty.StringVal(opts.NAMESPACE)) if len(opts.ROOT_DOMAIN_NAME) > 0 { rootBody.SetAttributeValue("root_domain_name", cty.StringVal(opts.ROOT_DOMAIN_NAME))