diff --git a/.golangci.yaml b/.golangci.yaml index 25cada2c..c2815a27 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -29,3 +29,5 @@ linters-settings: errcheck: exclude-functions: - (*github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.ResourceData).Set + goconst: + ignore-tests: true diff --git a/env0/errors.go b/env0/errors.go index 07bea238..2f7c28b2 100644 --- a/env0/errors.go +++ b/env0/errors.go @@ -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() { diff --git a/env0/resource_environment.go b/env0/resource_environment.go index 0c3cf60b..ea7e6e77 100644 --- a/env0/resource_environment.go +++ b/env0/resource_environment.go @@ -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 @@ -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 @@ -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{ @@ -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 } } @@ -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 @@ -1394,6 +1390,7 @@ func resourceEnvironmentImport(ctx context.Context, d *schema.ResourceData, meta } apiClient := meta.(client.ApiClientInterface) + d.SetId(environment.Id) scope := client.ScopeEnvironment diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index 8506d8ce..5ad62f1f 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -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(` @@ -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{