Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IZE-511 changed generation of tfvars file taking into account ecs apps #469

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/run.e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions internal/commands/tfenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 14 additions & 6 deletions internal/commands/tfenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ 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)",
args: []string{"gen", "tfenv"},
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()
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
`,
},
Expand Down Expand Up @@ -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"
`,
},
Expand Down Expand Up @@ -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"
`,
},
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down