Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feat_cloud_cost_credentials-#218
  • Loading branch information
samuel-br committed Mar 16, 2022
2 parents 9c331ea + badc1a2 commit 134e4b9
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 3 deletions.
2 changes: 2 additions & 0 deletions client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ type TemplateCreatePayload struct {
Revision string `json:"revision"`
OrganizationId string `json:"organizationId"`
TerraformVersion string `json:"terraformVersion"`
TerragruntVersion string `json:"terragruntVersion,omitempty"`
IsGitlabEnterprise bool `json:"isGitLabEnterprise"`
BitbucketClientKey string `json:"bitbucketClientKey,omitempty"`
}
Expand Down Expand Up @@ -275,6 +276,7 @@ type Template struct {
GitlabProjectId int `json:"gitlabProjectId,omitempty"`
UpdatedAt string `json:"updatedAt"`
TerraformVersion string `json:"terraformVersion"`
TerragruntVersion string `json:"terragruntVersion,omitempty"`
IsDeleted bool `json:"isDeleted,omitempty"`
BitbucketClientKey string `json:"bitbucketClientKey"`
}
Expand Down
12 changes: 12 additions & 0 deletions client/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ func (self *ApiClient) TemplateCreate(payload TemplateCreatePayload) (Template,
if payload.OrganizationId != "" {
return Template{}, errors.New("Must not specify organizationId")
}
if payload.Type != "terragrunt" && payload.TerragruntVersion != "" {
return Template{}, errors.New("Can't define terragrunt version for non-terragrunt blueprint")
}
if payload.Type == "terragrunt" && payload.TerragruntVersion == "" {
return Template{}, errors.New("Must supply Terragrunt version")
}
organizationId, err := self.organizationId()
if err != nil {
return Template{}, nil
Expand Down Expand Up @@ -49,6 +55,12 @@ func (self *ApiClient) TemplateUpdate(id string, payload TemplateCreatePayload)
if payload.OrganizationId != "" {
return Template{}, errors.New("Must not specify organizationId")
}
if payload.Type != "terragrunt" && payload.TerragruntVersion != "" {
return Template{}, errors.New("Can't define terragrunt version for non-terragrunt blueprint")
}
if payload.Type == "terragrunt" && payload.TerragruntVersion == "" {
return Template{}, errors.New("Must supply Terragrunt version")
}
organizationId, err := self.organizationId()
if err != nil {
return Template{}, err
Expand Down
53 changes: 53 additions & 0 deletions client/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,57 @@ var _ = Describe("Templates Client", func() {
httpCall.Times(1)
})
})

Describe("Terragrunt version errors", func() {
var err error

Describe("type is tg and no tg version supplied", func() {
It("Should fail on create", func() {
createTemplatePayload := TemplateCreatePayload{}
copier.Copy(&createTemplatePayload, &mockTemplate)

createTemplatePayload.Type = "terragrunt"

_, err = apiClient.TemplateCreate(createTemplatePayload)

Expect(err).To(Not(BeNil()))
})

It("Should fail on update", func() {
createTemplatePayload := TemplateCreatePayload{}
copier.Copy(&createTemplatePayload, &mockTemplate)

createTemplatePayload.Type = "terragrunt"

_, err = apiClient.TemplateUpdate(mockTemplate.Id, createTemplatePayload)

Expect(err).To(Not(BeNil()))
})
})

Describe("type is NOT tg and tg version IS supplied", func() {
It("Should fail on create", func() {
createTemplatePayload := TemplateCreatePayload{}
copier.Copy(&createTemplatePayload, &mockTemplate)

createTemplatePayload.Type = "terraform"
createTemplatePayload.TerragruntVersion = "0.29.0"

_, err = apiClient.TemplateCreate(createTemplatePayload)

Expect(err).To(Not(BeNil()))
})

It("Should fail on update", func() {
createTemplatePayload := TemplateCreatePayload{}
copier.Copy(&createTemplatePayload, &mockTemplate)

createTemplatePayload.Type = "terragrunt"

_, err = apiClient.TemplateUpdate(mockTemplate.Id, createTemplatePayload)

Expect(err).To(Not(BeNil()))
})
})
})
})
1 change: 1 addition & 0 deletions docs/data-sources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data "env0_template" "example" {
- **id** (String) id of the template
- **is_gitlab_enterprise** (Boolean) Does this template use gitlab enterprise repository?
- **name** (String) the name of the template
- **terragrunt_version** (String) terragrunt version to use
- **token_id** (String) The token id used for private git repos or for integration with GitLab

### Read-Only
Expand Down
1 change: 1 addition & 0 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ resource "env0_template_project_assignment" "assignment" {
- **revision** (String) source code revision (branch / tag) to use
- **ssh_keys** (List of Map of String) an array of references to 'data_ssh_key' to use when accessing git over ssh
- **terraform_version** (String) Terraform version to use
- **terragrunt_version** (String) Terragrunt version to use
- **token_id** (String) The token id used for private git repos or for integration with GitLab, you can get this value by using a data resource of an existing Gitlab template or contact our support team
- **type** (String) 'terraform' or 'terragrunt'

Expand Down
9 changes: 9 additions & 0 deletions env0/data_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func dataTemplate() *schema.Resource {
Description: "terraform version to use",
Computed: true,
},
"terragrunt_version": {
Type: schema.TypeString,
Description: "terragrunt version to use",
Computed: true,
Optional: true,
},
"is_gitlab_enterprise": {
Type: schema.TypeBool,
Description: "Does this template use gitlab enterprise repository?",
Expand Down Expand Up @@ -128,6 +134,9 @@ func dataTemplateRead(ctx context.Context, d *schema.ResourceData, meta interfac
d.Set("type", template.Type)
d.Set("project_ids", template.ProjectIds)
d.Set("terraform_version", template.TerraformVersion)
if template.TerragruntVersion != "" {
d.Set("terragrunt_version", template.TerragruntVersion)
}
if template.Retry.OnDeploy != nil {
d.Set("retries_on_deploy", template.Retry.OnDeploy.Times)
d.Set("retry_on_deploy_only_when_matches_regex", template.Retry.OnDeploy.ErrorRegex)
Expand Down
12 changes: 11 additions & 1 deletion env0/resource_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func resourceTemplate() *schema.Resource {
Optional: true,
Default: "0.15.1",
},
"terragrunt_version": {
Type: schema.TypeString,
Description: "Terragrunt version to use",
Optional: true,
},
"is_gitlab_enterprise": {
Type: schema.TypeBool,
Description: "Does this template use gitlab enterprise repository?",
Expand Down Expand Up @@ -220,11 +225,16 @@ func templateCreatePayloadFromParameters(d *schema.ResourceData) (client.Templat
if terraformVersion, ok := d.GetOk("terraform_version"); ok {
result.TerraformVersion = terraformVersion.(string)
}

if terragruntVersion, ok := d.GetOk("terragrunt_version"); ok {
result.TerragruntVersion = terragruntVersion.(string)
}
if bitbucketClientKey, ok := d.GetOk("bitbucket_client_key"); ok {
result.BitbucketClientKey = bitbucketClientKey.(string)
}

if terragruntVersion, ok := d.GetOk("terragrunt_version"); ok {
result.TerragruntVersion = terragruntVersion.(string)
}
return result, nil
}

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/004_template/expected_outputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"tested2_template_name": "tested1-",
"tested2_template_repository": "https://github.com/env0/templates",
"tested1_template_repository": "https://gitlab.com/env0/gitlab-vcs-integration-tests.git",
"tested2_template_path": "second"
"tested2_template_path": "second",
"tg_tg_version" : "0.35.0"
}
18 changes: 18 additions & 0 deletions tests/integration/004_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ resource "env0_template" "tested2" {
terraform_version = "0.15.1"
}

resource "env0_template" "template_tg" {
name = "Template for environment resource - tg"
type = "terragrunt"
repository = "https://github.com/env0/templates"
path = "terragrunt/misc/null-resource"
terraform_version = "0.15.1"
terragrunt_version = "0.35.0"
}

resource "env0_configuration_variable" "in_a_template" {
name = "fake_key"
value = "fake value"
Expand All @@ -68,6 +77,12 @@ data "env0_template" "tested1" {
env0_template.tested2]
name = "GitLab Test-${random_string.random.result}"
}
data "env0_template" "template_tg" {
depends_on = [
env0_template.template_tg]
name = "Template for environment resource - tg"
}

output "tested2_template_id" {
value = data.env0_template.tested2.id
}
Expand All @@ -86,6 +101,9 @@ output "tested1_template_repository" {
output "tested2_template_path" {
value = data.env0_template.tested2.path
}
output "tg_tg_version" {
value = data.env0_template.template_tg.terragrunt_version
}

data "env0_template" "tested3" {
id = env0_template.tested1.id
Expand Down
1 change: 0 additions & 1 deletion tests/integration/012_environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ output "revision" {
value = data.env0_environment.test.revision
}


0 comments on commit 134e4b9

Please sign in to comment.