diff --git a/client/api_client.go b/client/api_client.go index 42adf227..79ef1075 100644 --- a/client/api_client.go +++ b/client/api_client.go @@ -13,8 +13,8 @@ type ApiClient struct { type ApiClientInterface interface { ConfigurationVariables(scope Scope, scopeId string) ([]ConfigurationVariable, error) - ConfigurationVariableCreate(name string, value string, isSensitive bool, scope Scope, scopeId string, type_ ConfigurationVariableType, enumValues []string, description string) (ConfigurationVariable, error) - ConfigurationVariableUpdate(id string, name string, value string, isSensitive bool, scope Scope, scopeId string, type_ ConfigurationVariableType, enumValues []string, description string) (ConfigurationVariable, error) + ConfigurationVariableCreate(params ConfigurationVariableCreateParams) (ConfigurationVariable, error) + ConfigurationVariableUpdate(params ConfigurationVariableUpdateParams) (ConfigurationVariable, error) ConfigurationVariableDelete(id string) error Organization() (Organization, error) organizationId() (string, error) diff --git a/client/api_client_mock.go b/client/api_client_mock.go index b765bd4f..2dbe5a1c 100644 --- a/client/api_client_mock.go +++ b/client/api_client_mock.go @@ -138,18 +138,18 @@ func (mr *MockApiClientInterfaceMockRecorder) CloudCredentialIdsInProject(arg0 i } // ConfigurationVariableCreate mocks base method. -func (m *MockApiClientInterface) ConfigurationVariableCreate(arg0, arg1 string, arg2 bool, arg3 Scope, arg4 string, arg5 ConfigurationVariableType, arg6 []string, arg7 string) (ConfigurationVariable, error) { +func (m *MockApiClientInterface) ConfigurationVariableCreate(arg0 ConfigurationVariableCreateParams) (ConfigurationVariable, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConfigurationVariableCreate", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) + ret := m.ctrl.Call(m, "ConfigurationVariableCreate", arg0) ret0, _ := ret[0].(ConfigurationVariable) ret1, _ := ret[1].(error) return ret0, ret1 } // ConfigurationVariableCreate indicates an expected call of ConfigurationVariableCreate. -func (mr *MockApiClientInterfaceMockRecorder) ConfigurationVariableCreate(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call { +func (mr *MockApiClientInterfaceMockRecorder) ConfigurationVariableCreate(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigurationVariableCreate", reflect.TypeOf((*MockApiClientInterface)(nil).ConfigurationVariableCreate), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigurationVariableCreate", reflect.TypeOf((*MockApiClientInterface)(nil).ConfigurationVariableCreate), arg0) } // ConfigurationVariableDelete mocks base method. @@ -167,18 +167,18 @@ func (mr *MockApiClientInterfaceMockRecorder) ConfigurationVariableDelete(arg0 i } // ConfigurationVariableUpdate mocks base method. -func (m *MockApiClientInterface) ConfigurationVariableUpdate(arg0, arg1, arg2 string, arg3 bool, arg4 Scope, arg5 string, arg6 ConfigurationVariableType, arg7 []string, arg8 string) (ConfigurationVariable, error) { +func (m *MockApiClientInterface) ConfigurationVariableUpdate(arg0 ConfigurationVariableUpdateParams) (ConfigurationVariable, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConfigurationVariableUpdate", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + ret := m.ctrl.Call(m, "ConfigurationVariableUpdate", arg0) ret0, _ := ret[0].(ConfigurationVariable) ret1, _ := ret[1].(error) return ret0, ret1 } // ConfigurationVariableUpdate indicates an expected call of ConfigurationVariableUpdate. -func (mr *MockApiClientInterfaceMockRecorder) ConfigurationVariableUpdate(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 interface{}) *gomock.Call { +func (mr *MockApiClientInterfaceMockRecorder) ConfigurationVariableUpdate(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigurationVariableUpdate", reflect.TypeOf((*MockApiClientInterface)(nil).ConfigurationVariableUpdate), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigurationVariableUpdate", reflect.TypeOf((*MockApiClientInterface)(nil).ConfigurationVariableUpdate), arg0) } // ConfigurationVariables mocks base method. diff --git a/client/configuration_variable.go b/client/configuration_variable.go index 0eb82766..b8561971 100644 --- a/client/configuration_variable.go +++ b/client/configuration_variable.go @@ -31,8 +31,8 @@ func (self *ApiClient) ConfigurationVariables(scope Scope, scopeId string) ([]Co return result, nil } -func (self *ApiClient) ConfigurationVariableCreate(name string, value string, isSensitive bool, scope Scope, scopeId string, type_ ConfigurationVariableType, enumValues []string, description string) (ConfigurationVariable, error) { - if scope == ScopeDeploymentLog || scope == ScopeDeployment { +func (self *ApiClient) ConfigurationVariableCreate(params ConfigurationVariableCreateParams) (ConfigurationVariable, error) { + if params.Scope == ScopeDeploymentLog || params.Scope == ScopeDeployment { return ConfigurationVariable{}, errors.New("Must not create variable on scope deployment / deploymentLog") } organizationId, err := self.organizationId() @@ -41,23 +41,20 @@ func (self *ApiClient) ConfigurationVariableCreate(name string, value string, is } var result []ConfigurationVariable request := map[string]interface{}{ - "name": name, - "description": description, - "value": value, - "isSensitive": isSensitive, - "scope": scope, - "type": type_, + "name": params.Name, + "description": params.Description, + "value": params.Value, + "isSensitive": params.IsSensitive, + "scope": params.Scope, + "type": params.Type, "organizationId": organizationId, } - if scope != ScopeGlobal { - request["scopeId"] = scopeId - } - if enumValues != nil { - request["schema"] = map[string]interface{}{ - "type": "string", - "enum": enumValues, - } + if params.Scope != ScopeGlobal { + request["scopeId"] = params.ScopeId } + + request["schema"] = getSchema(params) + requestInArray := []map[string]interface{}{request} err = self.http.Post("configuration", requestInArray, &result) if err != nil { @@ -66,12 +63,26 @@ func (self *ApiClient) ConfigurationVariableCreate(name string, value string, is return result[0], nil } +func getSchema(params ConfigurationVariableCreateParams) map[string]interface{} { + schema := map[string]interface{}{ + "type": "string", + } + if params.EnumValues != nil { + schema["enum"] = params.EnumValues + } + if params.Format != Text { + schema["format"] = params.Format + } + return schema +} + func (self *ApiClient) ConfigurationVariableDelete(id string) error { return self.http.Delete("configuration/" + id) } -func (self *ApiClient) ConfigurationVariableUpdate(id string, name string, value string, isSensitive bool, scope Scope, scopeId string, type_ ConfigurationVariableType, enumValues []string, description string) (ConfigurationVariable, error) { - if scope == ScopeDeploymentLog || scope == ScopeDeployment { +func (self *ApiClient) ConfigurationVariableUpdate(updateParams ConfigurationVariableUpdateParams) (ConfigurationVariable, error) { + commonParams := updateParams.CommonParams + if commonParams.Scope == ScopeDeploymentLog || commonParams.Scope == ScopeDeployment { return ConfigurationVariable{}, errors.New("Must not create variable on scope deployment / deploymentLog") } organizationId, err := self.organizationId() @@ -80,24 +91,21 @@ func (self *ApiClient) ConfigurationVariableUpdate(id string, name string, value } var result []ConfigurationVariable request := map[string]interface{}{ - "id": id, - "name": name, - "description": description, - "value": value, - "isSensitive": isSensitive, - "scope": scope, - "type": type_, + "id": updateParams.Id, + "name": commonParams.Name, + "description": commonParams.Description, + "value": commonParams.Value, + "isSensitive": commonParams.IsSensitive, + "scope": commonParams.Scope, + "type": commonParams.Type, "organizationId": organizationId, } - if scope != ScopeGlobal { - request["scopeId"] = scopeId - } - if enumValues != nil { - request["schema"] = map[string]interface{}{ - "type": "string", - "enum": enumValues, - } + if commonParams.Scope != ScopeGlobal { + request["scopeId"] = commonParams.ScopeId } + + request["schema"] = getSchema(updateParams.CommonParams) + requestInArray := []map[string]interface{}{request} err = self.http.Post("/configuration", requestInArray, &result) if err != nil { diff --git a/client/configuration_variable_test.go b/client/configuration_variable_test.go index fff97eef..d8e25c78 100644 --- a/client/configuration_variable_test.go +++ b/client/configuration_variable_test.go @@ -11,6 +11,10 @@ import ( var _ = Describe("Configuration Variable", func() { isSensitive := true varType := ConfigurationVariableTypeEnvironment + schema := ConfigurationVariableSchema{ + Type: "string", + Format: HCL, + } mockConfigurationVariable := ConfigurationVariable{ Id: "config-var-id-789", Name: "configName", @@ -22,6 +26,7 @@ var _ = Describe("Configuration Variable", func() { Type: &varType, ScopeId: "project-123", UserId: "user|123", + Schema: &schema, } Describe("ConfigurationVariableCreate", func() { @@ -39,6 +44,10 @@ var _ = Describe("Configuration Variable", func() { "scopeId": mockConfigurationVariable.ScopeId, "scope": mockConfigurationVariable.Scope, "type": *mockConfigurationVariable.Type, + "schema": map[string]interface{}{ + "type": mockConfigurationVariable.Schema.Type, + "format": mockConfigurationVariable.Schema.Format, + }, }} httpCall = mockHttpClient.EXPECT(). @@ -48,14 +57,17 @@ var _ = Describe("Configuration Variable", func() { }) createdConfigurationVariable, _ = apiClient.ConfigurationVariableCreate( - mockConfigurationVariable.Name, - mockConfigurationVariable.Value, - *mockConfigurationVariable.IsSensitive, - mockConfigurationVariable.Scope, - mockConfigurationVariable.ScopeId, - *mockConfigurationVariable.Type, - nil, - mockConfigurationVariable.Description, + ConfigurationVariableCreateParams{ + Name: mockConfigurationVariable.Name, + Value: mockConfigurationVariable.Value, + Description: mockConfigurationVariable.Description, + IsSensitive: *mockConfigurationVariable.IsSensitive, + Scope: mockConfigurationVariable.Scope, + ScopeId: mockConfigurationVariable.ScopeId, + Type: *mockConfigurationVariable.Type, + EnumValues: nil, + Format: mockConfigurationVariable.Schema.Format, + }, ) }) @@ -103,6 +115,9 @@ var _ = Describe("Configuration Variable", func() { "scopeId": mockConfigurationVariable.ScopeId, "scope": mockConfigurationVariable.Scope, "type": *mockConfigurationVariable.Type, + "schema": map[string]interface{}{ + "type": mockConfigurationVariable.Schema.Type, + }, }} httpCall = mockHttpClient.EXPECT(). @@ -112,15 +127,19 @@ var _ = Describe("Configuration Variable", func() { }) updatedConfigurationVariable, _ = apiClient.ConfigurationVariableUpdate( - mockConfigurationVariable.Id, - newName, - newValue, - *mockConfigurationVariable.IsSensitive, - mockConfigurationVariable.Scope, - mockConfigurationVariable.ScopeId, - *mockConfigurationVariable.Type, - nil, - newDescription, + ConfigurationVariableUpdateParams{ + Id: mockConfigurationVariable.Id, + CommonParams: ConfigurationVariableCreateParams{ + Name: newName, + Value: newValue, + Description: newDescription, + IsSensitive: *mockConfigurationVariable.IsSensitive, + Scope: mockConfigurationVariable.Scope, + ScopeId: mockConfigurationVariable.ScopeId, + Type: *mockConfigurationVariable.Type, + EnumValues: nil, + }, + }, ) }) diff --git a/client/model.go b/client/model.go index 37d7dcad..5be6af51 100644 --- a/client/model.go +++ b/client/model.go @@ -98,8 +98,9 @@ type EnvironmentDeployResponse struct { } type ConfigurationVariableSchema struct { - Type string `json:"type"` - Enum []string `json:"enum"` + Type string `json:"type"` + Enum []string `json:"enum"` + Format Format `json:"format,omitempty"` } type ConfigurationVariable struct { @@ -117,6 +118,30 @@ type ConfigurationVariable struct { ToDelete *bool `json:"toDelete,omitempty"` } +type ConfigurationVariableCreateParams struct { + Name string + Value string + IsSensitive bool + Scope Scope + ScopeId string + Type ConfigurationVariableType + EnumValues []string + Description string + Format Format +} + +type ConfigurationVariableUpdateParams struct { + CommonParams ConfigurationVariableCreateParams + Id string +} + +type Format string + +const ( + Text Format = "" + HCL Format = "HCL" +) + type Scope string const ( diff --git a/env0/data_configuration_variable.go b/env0/data_configuration_variable.go index d07d8f2e..eb80b890 100644 --- a/env0/data_configuration_variable.go +++ b/env0/data_configuration_variable.go @@ -92,6 +92,11 @@ func dataConfigurationVariable() *schema.Resource { Description: "the configuration variable option", }, }, + "format": { + Type: schema.TypeString, + Description: "specifies the format of the configuration value (for example: HCL)", + Computed: true, + }, }, } } @@ -127,6 +132,9 @@ func dataConfigurationVariableRead(ctx context.Context, d *schema.ResourceData, d.Set("is_sensitive", variable.IsSensitive) d.Set("scope", variable.Scope) d.Set("enum", variable.Schema.Enum) + if variable.Schema.Format != client.Text { + d.Set("format", string(variable.Schema.Format)) + } if *variable.Type == client.ConfigurationVariableTypeEnvironment { d.Set("type", "environment") } else if *variable.Type == client.ConfigurationVariableTypeTerraform { diff --git a/env0/data_configuration_variable_test.go b/env0/data_configuration_variable_test.go index a5f13648..db331d4c 100644 --- a/env0/data_configuration_variable_test.go +++ b/env0/data_configuration_variable_test.go @@ -27,7 +27,7 @@ func TestUnitConfigurationVariableData(t *testing.T) { IsSensitive: &isSensitive, Scope: client.ScopeEnvironment, Type: &variableType, - Schema: &client.ConfigurationVariableSchema{Type: "string"}, + Schema: &client.ConfigurationVariableSchema{Type: "string", Format: client.HCL}, } checkResources := resource.ComposeAggregateTestCheckFunc( @@ -38,6 +38,7 @@ func TestUnitConfigurationVariableData(t *testing.T) { resource.TestCheckResourceAttr(accessor, "value", configurationVariable.Value), resource.TestCheckResourceAttr(accessor, "scope", string(configurationVariable.Scope)), resource.TestCheckResourceAttr(accessor, "is_sensitive", strconv.FormatBool(*configurationVariable.IsSensitive)), + resource.TestCheckResourceAttr(accessor, "format", string(configurationVariable.Schema.Format)), ) t.Run("ScopeGlobal", func(t *testing.T) { diff --git a/env0/resource_configuration_variable.go b/env0/resource_configuration_variable.go index d17d53b2..c134a554 100644 --- a/env0/resource_configuration_variable.go +++ b/env0/resource_configuration_variable.go @@ -78,6 +78,19 @@ func resourceConfigurationVariable() *schema.Resource { Description: "name to give the configuration variable", }, }, + "format": { + Type: schema.TypeString, + Description: "specifies the format of the configuration value (for example: HCL)", + Default: "", + Optional: true, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + value := val.(string) + if value != string(client.HCL) && value != string(client.Text) { + errs = append(errs, fmt.Errorf("%q can be either \"HCL\" or empty, got: %q", key, value)) + } + return + }, + }, }, } } @@ -107,13 +120,13 @@ func whichScope(d *schema.ResourceData) (client.Scope, string) { func resourceConfigurationVariableCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { apiClient := meta.(client.ApiClientInterface) - scope, scopeId := whichScope(d) name := d.Get("name").(string) description := d.Get("description").(string) value := d.Get("value").(string) isSensitive := d.Get("is_sensitive").(bool) typeAsString := d.Get("type").(string) + format := client.Format(d.Get("format").(string)) var type_ client.ConfigurationVariableType switch typeAsString { case "environment": @@ -128,7 +141,17 @@ func resourceConfigurationVariableCreate(ctx context.Context, d *schema.Resource return getEnumErr } - configurationVariable, err := apiClient.ConfigurationVariableCreate(name, value, isSensitive, scope, scopeId, type_, actualEnumValues, description) + configurationVariable, err := apiClient.ConfigurationVariableCreate(client.ConfigurationVariableCreateParams{ + Name: name, + Value: value, + IsSensitive: isSensitive, + Scope: scope, + ScopeId: scopeId, + Type: type_, + EnumValues: actualEnumValues, + Description: description, + Format: format, + }) if err != nil { return diag.Errorf("could not create configurationVariable: %v", err) } @@ -177,9 +200,16 @@ func resourceConfigurationVariableRead(ctx context.Context, d *schema.ResourceDa } else { d.Set("type", "environment") } - if variable.Schema != nil && len(variable.Schema.Enum) > 0 { - d.Set("enum", variable.Schema.Enum) + if variable.Schema != nil { + if len(variable.Schema.Enum) > 0 { + d.Set("enum", variable.Schema.Enum) + } + + if variable.Schema.Format == client.HCL { + d.Set("format", string(client.HCL)) + } } + return nil } } @@ -196,6 +226,8 @@ func resourceConfigurationVariableUpdate(ctx context.Context, d *schema.Resource value := d.Get("value").(string) isSensitive := d.Get("is_sensitive").(bool) typeAsString := d.Get("type").(string) + format := client.Format(d.Get("format").(string)) + var type_ client.ConfigurationVariableType switch typeAsString { case "environment": @@ -209,7 +241,17 @@ func resourceConfigurationVariableUpdate(ctx context.Context, d *schema.Resource if getEnumErr != nil { return getEnumErr } - _, err := apiClient.ConfigurationVariableUpdate(id, name, value, isSensitive, scope, scopeId, type_, actualEnumValues, description) + _, err := apiClient.ConfigurationVariableUpdate(client.ConfigurationVariableUpdateParams{Id: id, CommonParams: client.ConfigurationVariableCreateParams{ + Name: name, + Value: value, + IsSensitive: isSensitive, + Scope: scope, + ScopeId: scopeId, + Type: type_, + EnumValues: actualEnumValues, + Description: description, + Format: format, + }}) if err != nil { return diag.Errorf("could not update configurationVariable: %v", err) } diff --git a/env0/resource_configuration_variable_test.go b/env0/resource_configuration_variable_test.go index ac50408b..4cb0b1ae 100644 --- a/env0/resource_configuration_variable_test.go +++ b/env0/resource_configuration_variable_test.go @@ -26,6 +26,17 @@ func TestUnitConfigurationVariableResource(t *testing.T) { "value": configVar.Value, }) + configurationVariableCreateParams := client.ConfigurationVariableCreateParams{ + Name: configVar.Name, + Value: configVar.Value, + IsSensitive: false, + Scope: client.ScopeGlobal, + ScopeId: "", + Type: client.ConfigurationVariableTypeEnvironment, + EnumValues: nil, + Description: configVar.Description, + Format: client.Text, + } t.Run("Create", func(t *testing.T) { createTestCase := resource.TestCase{ @@ -43,12 +54,12 @@ func TestUnitConfigurationVariableResource(t *testing.T) { } runUnitTest(t, createTestCase, func(mock *client.MockApiClientInterface) { - mock.EXPECT().ConfigurationVariableCreate(configVar.Name, configVar.Value, false, client.ScopeGlobal, "", client.ConfigurationVariableTypeEnvironment, - nil, configVar.Description).Times(1).Return(configVar, nil) + mock.EXPECT().ConfigurationVariableCreate(configurationVariableCreateParams).Times(1).Return(configVar, nil) mock.EXPECT().ConfigurationVariables(client.ScopeGlobal, "").Times(1).Return([]client.ConfigurationVariable{configVar}, nil) mock.EXPECT().ConfigurationVariableDelete(configVar.Id).Times(1).Return(nil) }) }) + t.Run("Create Enum", func(t *testing.T) { schema := client.ConfigurationVariableSchema{ Type: "string", @@ -86,12 +97,95 @@ func TestUnitConfigurationVariableResource(t *testing.T) { } runUnitTest(t, createTestCase, func(mock *client.MockApiClientInterface) { - mock.EXPECT().ConfigurationVariableCreate(configVar.Name, configVar.Value, false, client.ScopeGlobal, "", client.ConfigurationVariableTypeEnvironment, - configVar.Schema.Enum, configVar.Description).Times(1).Return(configVar, nil) + mock.EXPECT().ConfigurationVariableCreate( + client.ConfigurationVariableCreateParams{ + Name: configVar.Name, + Value: configVar.Value, + IsSensitive: false, + Scope: client.ScopeGlobal, + ScopeId: "", + Type: client.ConfigurationVariableTypeEnvironment, + EnumValues: configVar.Schema.Enum, + Description: configVar.Description, + Format: client.Text, + }).Times(1).Return(configVar, nil) mock.EXPECT().ConfigurationVariables(client.ScopeGlobal, "").Times(1).Return([]client.ConfigurationVariable{configVar}, nil) mock.EXPECT().ConfigurationVariableDelete(configVar.Id).Times(1).Return(nil) }) }) + + t.Run("Create HCL Variable", func(t *testing.T) { + + expectedVariable := `{ +A = "A" +B = "B" +C = "C" +} +` + + schema := client.ConfigurationVariableSchema{ + Type: "string", + Format: client.HCL, + } + configVar := client.ConfigurationVariable{ + Id: "id0", + Name: "name0", + Description: "desc0", + Value: expectedVariable, + Schema: &schema, + } + terraformDirective := `< 0 { + enumOfAny := variable["schema_enum"].([]interface{}) enum := make([]string, len(enumOfAny)) for i := range enum { enum[i] = enumOfAny[i].(string) } - schema := client.ConfigurationVariableSchema{ - Type: variable["schema_type"].(string), - Enum: enum, - } - configurationVariable.Schema = &schema + configurationSchema.Type = variable["schema_type"].(string) + configurationSchema.Enum = enum } + configurationVariable.Schema = &configurationSchema return configurationVariable } diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index 78403219..131a87ae 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -125,8 +125,9 @@ func TestUnitEnvironmentResource(t *testing.T) { varType := client.ConfigurationVariableTypeEnvironment varSchema := client.ConfigurationVariableSchema{ - Type: "string", - Enum: []string{"a", "b"}, + Type: "string", + Enum: []string{"a", "b"}, + Format: client.HCL, } configurationVariables := client.ConfigurationVariable{ Value: varSchema.Enum[0], @@ -135,21 +136,31 @@ func TestUnitEnvironmentResource(t *testing.T) { Schema: &varSchema, } formatVariables := func(variables []client.ConfigurationVariable) string { - foramt := "" + format := "" for _, variable := range variables { schemaFormat := "" if variable.Schema != nil { - schemaFormat = fmt.Sprintf(` + if variable.Schema.Enum != nil { + schemaFormat = fmt.Sprintf(` schema_type = "%s" schema_enum = ["%s"] + schema_format = "%s" `, variable.Schema.Type, - strings.Join(variable.Schema.Enum, "\",\"")) + strings.Join(variable.Schema.Enum, "\",\""), variable.Schema.Format) + } else { + schemaFormat = fmt.Sprintf(` + schema_type = "%s" + schema_format = "%s" + `, variable.Schema.Type, + variable.Schema.Format) + } + } varType := "environment" if *variable.Type == client.ConfigurationVariableTypeTerraform { varType = "terraform" } - foramt += fmt.Sprintf(`configuration{ + format += fmt.Sprintf(`configuration{ name = "%s" value = "%s" type = "%s" @@ -160,7 +171,7 @@ func TestUnitEnvironmentResource(t *testing.T) { variable.Value, varType, schemaFormat) } - return foramt + return format } formatResourceWithConfiguration := func(env client.Environment, variables []client.ConfigurationVariable) string { return fmt.Sprintf(` @@ -184,6 +195,10 @@ func TestUnitEnvironmentResource(t *testing.T) { Value: "configurationVariables.Value", Name: configurationVariables.Name, Type: &newVarType, + Schema: &client.ConfigurationVariableSchema{ + Type: "string", + Format: client.Text, + }, }} updatedEnvironmentResource := formatResourceWithConfiguration(updatedEnvironment, redeployConfigurationVariables) testCase := resource.TestCase{ @@ -199,6 +214,7 @@ func TestUnitEnvironmentResource(t *testing.T) { resource.TestCheckResourceAttr(accessor, "configuration.0.name", configurationVariables.Name), resource.TestCheckResourceAttr(accessor, "configuration.0.value", configurationVariables.Schema.Enum[0]), resource.TestCheckResourceAttr(accessor, "configuration.0.schema_type", configurationVariables.Schema.Type), + resource.TestCheckResourceAttr(accessor, "configuration.0.schema_format", string(configurationVariables.Schema.Format)), resource.TestCheckResourceAttr(accessor, "configuration.0.schema_enum.0", configurationVariables.Schema.Enum[0]), resource.TestCheckResourceAttr(accessor, "configuration.0.schema_enum.1", configurationVariables.Schema.Enum[1]), ), @@ -213,6 +229,7 @@ func TestUnitEnvironmentResource(t *testing.T) { resource.TestCheckResourceAttr(accessor, "revision", updatedEnvironment.LatestDeploymentLog.BlueprintRevision), resource.TestCheckResourceAttr(accessor, "configuration.0.name", configurationVariables.Name), resource.TestCheckResourceAttr(accessor, "configuration.0.value", "configurationVariables.Value"), + resource.TestCheckResourceAttr(accessor, "configuration.0.schema_format", string(client.Text)), ), }, }, @@ -245,11 +262,14 @@ func TestUnitEnvironmentResource(t *testing.T) { ) redeployConfigurationVariables[0].Scope = client.ScopeDeployment redeployConfigurationVariables[0].IsSensitive = &isSensitive - mock.EXPECT().EnvironmentDeploy(environment.Id, client.DeployRequest{ + + deployRequest := client.DeployRequest{ BlueprintId: environment.LatestDeploymentLog.BlueprintId, BlueprintRevision: updatedEnvironment.LatestDeploymentLog.BlueprintRevision, ConfigurationChanges: &client.ConfigurationChanges{redeployConfigurationVariables[0], configurationVariables}, - }).Times(1).Return(client.EnvironmentDeployResponse{ + } + + mock.EXPECT().EnvironmentDeploy(environment.Id, deployRequest).Times(1).Return(client.EnvironmentDeployResponse{ Id: environment.Id, }, nil) @@ -286,8 +306,9 @@ func TestUnitEnvironmentResource(t *testing.T) { varType := client.ConfigurationVariableTypeEnvironment varSchema := client.ConfigurationVariableSchema{ - Type: "string", - Enum: []string{"a", "b"}, + Type: "string", + Enum: []string{"a", "b"}, + Format: client.Text, } configurationVariables := client.ConfigurationVariable{ Value: "my env var value", diff --git a/examples/data-sources/env0_environment/data-source.tf b/examples/data-sources/env0_environment/data-source.tf index 44f22144..a36e3329 100644 --- a/examples/data-sources/env0_environment/data-source.tf +++ b/examples/data-sources/env0_environment/data-source.tf @@ -1,5 +1,5 @@ data "env0_environment" "by_name" { - name = "best-env" + name = "best-env" } output "environment_project_id" { @@ -7,7 +7,7 @@ output "environment_project_id" { } data "env0_environment" "by_id" { - id = "some_id" + id = "some_id" } output "environment_name" {