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

Feat: allow is_remote_apply on env0_environment creation #936

Merged
merged 2 commits into from
Aug 21, 2024
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
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ linters-settings:
errcheck:
exclude-functions:
- (*github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.ResourceData).Set
goconst:
ignore-tests: true
2 changes: 2 additions & 0 deletions env0/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var ErrNoChanges = errors.New("no changes")

func driftDetected(err error) bool {
var failedResponseError *http.FailedResponseError
if errors.As(err, &failedResponseError) && failedResponseError.NotFound() {
Expand Down
13 changes: 5 additions & 8 deletions env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,6 @@ func validateTemplateProjectAssignment(d *schema.ResourceData, apiClient client.
func resourceEnvironmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
apiClient := meta.(client.ApiClientInterface)

isRemoteApplyEnabled := d.Get("is_remote_apply_enabled").(bool)
if isRemoteApplyEnabled {
return diag.Errorf("is_remote_apply_enabled cannot be set when creating a new environment. Set this value after the environment is created")
}

environmentPayload, createEnvPayloadErr := getCreatePayload(d, apiClient)
if createEnvPayloadErr != nil {
return createEnvPayloadErr
Expand Down Expand Up @@ -867,6 +862,7 @@ func deploy(d *schema.ResourceData, apiClient client.ApiClientInterface) diag.Di
if err != nil {
return diag.Errorf("failed deploying environment: %v", err)
}

d.Set("deployment_id", deployResponse.Id)

return nil
Expand Down Expand Up @@ -1148,7 +1144,7 @@ func getEnvironmentConfigurationSetChanges(d *schema.ResourceData, apiClient cli
}

if assignVariableSets == nil && unassignVariableSets == nil {
return nil, nil
return nil, ErrNoChanges
}

return &client.ConfigurationSetChanges{
Expand Down Expand Up @@ -1192,7 +1188,7 @@ func getDeployPayload(d *schema.ResourceData, apiClient client.ApiClientInterfac
}

payload.ConfigurationSetChanges, err = getEnvironmentConfigurationSetChanges(d, apiClient)
if err != nil {
if err != nil && !errors.Is(err, ErrNoChanges) {
return client.DeployRequest{}, err
}
}
Expand Down Expand Up @@ -1341,7 +1337,7 @@ func getEnvironmentByName(meta interface{}, name string, projectId string, exclu
return client.Environment{}, diag.Errorf("Could not get Environment: %v", err)
}

var filteredEnvironments []client.Environment
filteredEnvironments := []client.Environment{}
for _, candidate := range environmentsByName {
if excludeArchived && candidate.IsArchived != nil && *candidate.IsArchived {
continue
Expand Down Expand Up @@ -1394,6 +1390,7 @@ func resourceEnvironmentImport(ctx context.Context, d *schema.ResourceData, meta
}

apiClient := meta.(client.ApiClientInterface)

d.SetId(environment.Id)

scope := client.ScopeEnvironment
Expand Down
17 changes: 1 addition & 16 deletions env0/resource_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ func TestUnitEnvironmentResource(t *testing.T) {
format := ""
for _, variable := range variables {
schemaFormat := ""

if variable.Schema != nil {
if variable.Schema.Enum != nil {
schemaFormat = fmt.Sprintf(`
Expand Down Expand Up @@ -1978,22 +1979,6 @@ func TestUnitEnvironmentResource(t *testing.T) {
}

testValidationFailures := func() {
t.Run("create environment with is_remote_apply_enabled set to 'true'", func(t *testing.T) {
runUnitTest(t, resource.TestCase{
Steps: []resource.TestStep{
{
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{
"name": environment.Name,
"project_id": environment.ProjectId,
"template_id": environment.LatestDeploymentLog.BlueprintId,
"is_remote_apply_enabled": true,
}),
ExpectError: regexp.MustCompile("is_remote_apply_enabled cannot be set when creating a new environment"),
},
},
}, func(mockFunc *client.MockApiClientInterface) {})
})

t.Run("Failure in validation while glob is enabled and pathChanges no", func(t *testing.T) {
autoDeployWithCustomGlobEnabled := resource.TestCase{
Steps: []resource.TestStep{
Expand Down
Loading