Skip to content

Commit

Permalink
Fix: if without_template_settings is defined, validate revision is no… (
Browse files Browse the repository at this point in the history
#574)

* Fix: if without_template_settings is defined, validate revision is not set outside of it

* fix based on PR comments

* fix integration test
  • Loading branch information
TomerHeber committed Jan 25, 2023
1 parent f349f8a commit 1f213c0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
9 changes: 5 additions & 4 deletions env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ func resourceEnvironment() *schema.Resource {
Computed: true,
},
"revision": {
Type: schema.TypeString,
Description: "the revision the environment is to be run against",
Optional: true,
Computed: true,
Type: schema.TypeString,
Description: "the revision the environment is to be run against",
Optional: true,
Computed: true,
ConflictsWith: []string{"without_template_settings"},
},
"run_plan_on_pull_requests": {
Type: schema.TypeBool,
Expand Down
57 changes: 57 additions & 0 deletions env0/resource_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,63 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) {
})
})

t.Run("Revision conflict", func(t *testing.T) {
createEnvironmentResourceConfigWithRevision := func(environment client.Environment, template client.Template, revision string) string {
return fmt.Sprintf(`
resource "%s" "%s" {
name = "%s"
revision = "%s"
project_id = "%s"
workspace = "%s"
terragrunt_working_directory = "%s"
force_destroy = true
vcs_commands_alias = "%s"
without_template_settings {
repository = "%s"
terraform_version = "%s"
type = "%s"
revision = "%s"
path = "%s"
retries_on_deploy = %d
retry_on_deploy_only_when_matches_regex = "%s"
retries_on_destroy = %d
retry_on_destroy_only_when_matches_regex = "%s"
description = "%s"
github_installation_id = %d
}
}`,
resourceType, resourceName,
environment.Name,
revision,
environment.ProjectId,
environment.WorkspaceName,
environment.TerragruntWorkingDirectory,
environment.VcsCommandsAlias,
template.Repository,
template.TerraformVersion,
template.Type,
template.Revision,
template.Path,
template.Retry.OnDeploy.Times,
template.Retry.OnDeploy.ErrorRegex,
template.Retry.OnDestroy.Times,
template.Retry.OnDestroy.ErrorRegex,
template.Description,
template.GithubInstallationId,
)
}

testCase := resource.TestCase{
Steps: []resource.TestStep{
{
Config: createEnvironmentResourceConfigWithRevision(environment, template, "environment_revision"),
ExpectError: regexp.MustCompile("conflicts with without_template_settings"),
},
},
}

runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) {})
})
}

func TestUnitEnvironmentWithoutSubEnvironment(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/012_environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ resource "env0_environment" "environment-without-template" {
name = "environment-without-template-${random_string.random.result}"
project_id = env0_project.test_project.id
approve_plan_automatically = true
revision = "master"
auto_deploy_on_path_changes_only = false

without_template_settings {
description = "Template description - GitHub"
type = "terraform"
revision = "master"
repository = data.env0_template.github_template.repository
github_installation_id = data.env0_template.github_template.github_installation_id
path = var.second_run ? "second" : "misc/null-resource"
Expand Down

0 comments on commit 1f213c0

Please sign in to comment.