diff --git a/client/configuration_variable.go b/client/configuration_variable.go index 7ff57d70..82db2f17 100644 --- a/client/configuration_variable.go +++ b/client/configuration_variable.go @@ -100,6 +100,7 @@ func (client *ApiClient) ConfigurationVariablesByScope(scope Scope, scopeId stri if err != nil { return []ConfigurationVariable{}, err } + return result, nil } diff --git a/env0/resource_environment.go b/env0/resource_environment.go index 59912a3d..97810d6f 100644 --- a/env0/resource_environment.go +++ b/env0/resource_environment.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "regexp" - "time" "github.com/env0/terraform-provider-env0/client" "github.com/google/uuid" @@ -14,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -const deploymentStatusWaitPollInterval = 10 // In seconds +//const deploymentStatusWaitPollInterval = 10 // In seconds func resourceEnvironment() *schema.Resource { return &schema.Resource{ @@ -299,6 +298,7 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta i if err != nil { return diag.Errorf("could not get environment configuration variables: %v", err) } + environmentConfigurationVariables = filterOutGlobalScope(environmentConfigurationVariables) setEnvironmentSchema(d, environment, environmentConfigurationVariables) return nil @@ -555,6 +555,7 @@ func getUpdateConfigurationVariables(configurationChanges client.ConfigurationCh if err != nil { diag.Errorf("could not get environment configuration variables: %v", err) } + existVariables = filterOutGlobalScope(existVariables) configurationChanges = linkToExistConfigurationVariables(configurationChanges, existVariables) configurationChanges = deleteUnusedConfigurationVariables(configurationChanges, existVariables) return configurationChanges @@ -704,6 +705,7 @@ func resourceEnvironmentImport(ctx context.Context, d *schema.ResourceData, meta if err != nil { return nil, fmt.Errorf("could not get environment configuration variables: %v", err) } + environmentConfigurationVariables = filterOutGlobalScope(environmentConfigurationVariables) d.Set("deployment_id", environment.LatestDeploymentLogId) setEnvironmentSchema(d, environment, environmentConfigurationVariables) @@ -730,7 +732,7 @@ func waitForDeployment(deploymentLogId string, apiClient client.ApiClientInterfa "QUEUED", "WAITING_FOR_USER": log.Println("[INFO] Deployment not yet done deploying. Got status ", deployment.Status) - time.Sleep(deploymentStatusWaitPollInterval * time.Second) + //time.Sleep(deploymentStatusWaitPollInterval * time.Second) case "SUCCESS", "SKIPPED": log.Println("[INFO] Deployment done deploying! Got status ", deployment.Status) @@ -740,3 +742,13 @@ func waitForDeployment(deploymentLogId string, apiClient client.ApiClientInterfa } } } + +func filterOutGlobalScope(variables []client.ConfigurationVariable) []client.ConfigurationVariable { + filteredVariables := []client.ConfigurationVariable{} + for _, variable := range variables { + if variable.Scope != client.ScopeGlobal { + filteredVariables = append(filteredVariables, variable) + } + } + return filteredVariables +} diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index ead16c6c..dd1295f6 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -146,10 +146,14 @@ func TestUnitEnvironmentResource(t *testing.T) { Name: "my env var", Type: &varType, Schema: &varSchema, + Scope: client.ScopeEnvironment, } formatVariables := func(variables []client.ConfigurationVariable) string { format := "" for _, variable := range variables { + if variable.Scope == client.ScopeGlobal { + continue + } schemaFormat := "" if variable.Schema != nil { if variable.Schema.Enum != nil { @@ -203,6 +207,13 @@ func TestUnitEnvironmentResource(t *testing.T) { environmentResource := formatResourceWithConfiguration(environment, client.ConfigurationChanges{configurationVariables}) newVarType := client.ConfigurationVariableTypeTerraform + globalConfigurationVariables := client.ConfigurationVariable{ + Value: "1111", + Name: "2222", + Type: &varType, + Schema: &varSchema, + Scope: client.ScopeGlobal, + } redeployConfigurationVariables := client.ConfigurationChanges{client.ConfigurationVariable{ Value: "configurationVariables.Value", Name: configurationVariables.Name, @@ -211,7 +222,9 @@ func TestUnitEnvironmentResource(t *testing.T) { Type: "string", Format: client.Text, }, - }} + Scope: client.ScopeEnvironment, + }, globalConfigurationVariables} + updatedEnvironmentResource := formatResourceWithConfiguration(updatedEnvironment, redeployConfigurationVariables) testCase := resource.TestCase{ Steps: []resource.TestStep{ @@ -269,8 +282,8 @@ func TestUnitEnvironmentResource(t *testing.T) { varTrue := true configurationVariables.ToDelete = &varTrue gomock.InOrder( - mock.EXPECT().ConfigurationVariablesByScope(client.ScopeEnvironment, updatedEnvironment.Id).Times(3).Return(client.ConfigurationChanges{configurationVariables}, nil), // read after create -> on update - mock.EXPECT().ConfigurationVariablesByScope(client.ScopeEnvironment, updatedEnvironment.Id).Times(1).Return(redeployConfigurationVariables, nil), // read after create -> on update -> read after update + mock.EXPECT().ConfigurationVariablesByScope(client.ScopeEnvironment, updatedEnvironment.Id).Times(3).Return(client.ConfigurationChanges{configurationVariables, globalConfigurationVariables}, nil), // read after create -> on update + mock.EXPECT().ConfigurationVariablesByScope(client.ScopeEnvironment, updatedEnvironment.Id).Times(1).Return(redeployConfigurationVariables, nil), // read after create -> on update -> read after update ) redeployConfigurationVariables[0].Scope = client.ScopeDeployment redeployConfigurationVariables[0].IsSensitive = &isSensitive