Skip to content

Commit

Permalink
Add description to configuration variable (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
roni-frantchi committed Oct 21, 2021
1 parent f1e32fb commit 048f3be
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 44 deletions.
4 changes: 2 additions & 2 deletions client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) (ConfigurationVariable, error)
ConfigurationVariableUpdate(id string, name string, value string, isSensitive bool, scope Scope, scopeId string, type_ ConfigurationVariableType, enumValues []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)
ConfigurationVariableDelete(id string) error
Organization() (Organization, error)
organizationId() (string, error)
Expand Down
16 changes: 8 additions & 8 deletions client/api_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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) (ConfigurationVariable, error) {
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 {
return ConfigurationVariable{}, errors.New("Must not create variable on scope deployment / deploymentLog")
}
Expand All @@ -42,6 +42,7 @@ 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,
Expand Down Expand Up @@ -69,7 +70,7 @@ 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) (ConfigurationVariable, error) {
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 {
return ConfigurationVariable{}, errors.New("Must not create variable on scope deployment / deploymentLog")
}
Expand All @@ -81,6 +82,7 @@ func (self *ApiClient) ConfigurationVariableUpdate(id string, name string, value
request := map[string]interface{}{
"id": id,
"name": name,
"description": description,
"value": value,
"isSensitive": isSensitive,
"scope": scope,
Expand Down
6 changes: 6 additions & 0 deletions client/configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var _ = Describe("Configuration Variable", func() {
mockConfigurationVariable := ConfigurationVariable{
Id: "config-var-id-789",
Name: "configName",
Description: "configDescription",
Value: "configValue",
OrganizationId: organizationId,
IsSensitive: true,
Expand All @@ -29,6 +30,7 @@ var _ = Describe("Configuration Variable", func() {

expectedCreateRequest := []map[string]interface{}{{
"name": mockConfigurationVariable.Name,
"description": mockConfigurationVariable.Description,
"isSensitive": mockConfigurationVariable.IsSensitive,
"value": mockConfigurationVariable.Value,
"organizationId": organizationId,
Expand All @@ -51,6 +53,7 @@ var _ = Describe("Configuration Variable", func() {
mockConfigurationVariable.ScopeId,
mockConfigurationVariable.Type,
nil,
mockConfigurationVariable.Description,
)
})

Expand Down Expand Up @@ -85,10 +88,12 @@ var _ = Describe("Configuration Variable", func() {
mockOrganizationIdCall(organizationId)

newName := "new-" + mockConfigurationVariable.Name
newDescription := "new-" + mockConfigurationVariable.Description
newValue := "new-" + mockConfigurationVariable.Value

expectedUpdateRequest := []map[string]interface{}{{
"name": newName,
"description": newDescription,
"value": newValue,
"id": mockConfigurationVariable.Id,
"isSensitive": mockConfigurationVariable.IsSensitive,
Expand All @@ -113,6 +118,7 @@ var _ = Describe("Configuration Variable", func() {
mockConfigurationVariable.ScopeId,
mockConfigurationVariable.Type,
nil,
newDescription,
)
})

Expand Down
1 change: 1 addition & 0 deletions client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ConfigurationVariable struct {
Scope Scope `json:"scope"`
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Type ConfigurationVariableType `json:"type"`
Schema ConfigurationVariableSchema `json:"schema"`
}
Expand Down
6 changes: 6 additions & 0 deletions env0/data_configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func dataConfigurationVariable() *schema.Resource {
Optional: true,
ExactlyOneOf: []string{"name", "id"},
},
"description": {
Type: schema.TypeString,
Description: "a description of the variable",
Optional: true,
},
"type": {
Type: schema.TypeString,
Description: "'terraform' or 'environment'. If specified as an argument, limits searching by variable name only to variables of this type.",
Expand Down Expand Up @@ -116,6 +121,7 @@ func dataConfigurationVariableRead(ctx context.Context, d *schema.ResourceData,

d.SetId(variable.Id)
d.Set("name", variable.Name)
d.Set("description", variable.Description)
d.Set("value", variable.Value)
d.Set("is_sensitive", variable.IsSensitive)
d.Set("scope", variable.Scope)
Expand Down
2 changes: 2 additions & 0 deletions env0/data_configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestUnitConfigurationVariableData(t *testing.T) {
configurationVariable := client.ConfigurationVariable{
Id: "id0",
Name: "name0",
Description: "desc0",
ScopeId: "scope0",
Value: "value0",
OrganizationId: "organization0",
Expand All @@ -30,6 +31,7 @@ func TestUnitConfigurationVariableData(t *testing.T) {
checkResources := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(accessor, "id", configurationVariable.Id),
resource.TestCheckResourceAttr(accessor, "name", configurationVariable.Name),
resource.TestCheckResourceAttr(accessor, "description", configurationVariable.Description),
resource.TestCheckResourceAttr(accessor, "type", "environment"),
resource.TestCheckResourceAttr(accessor, "value", configurationVariable.Value),
resource.TestCheckResourceAttr(accessor, "scope", string(configurationVariable.Scope)),
Expand Down
12 changes: 10 additions & 2 deletions env0/resource_configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func resourceConfigurationVariable() *schema.Resource {
Description: "name to give the configuration variable",
Required: true,
},
"description": {
Type: schema.TypeString,
Description: "a description of the variables",
Optional: true,
},
"value": {
Type: schema.TypeString,
Description: "value for the configuration variable",
Expand Down Expand Up @@ -104,6 +109,7 @@ func resourceConfigurationVariableCreate(ctx context.Context, d *schema.Resource

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)
Expand All @@ -121,7 +127,7 @@ func resourceConfigurationVariableCreate(ctx context.Context, d *schema.Resource
return getEnumErr
}

configurationVariable, err := apiClient.ConfigurationVariableCreate(name, value, isSensitive, scope, scopeId, type_, actualEnumValues)
configurationVariable, err := apiClient.ConfigurationVariableCreate(name, value, isSensitive, scope, scopeId, type_, actualEnumValues, description)
if err != nil {
return diag.Errorf("could not create configurationVariable: %v", err)
}
Expand Down Expand Up @@ -162,6 +168,7 @@ func resourceConfigurationVariableRead(ctx context.Context, d *schema.ResourceDa
for _, variable := range variables {
if variable.Id == id {
d.Set("name", variable.Name)
d.Set("description", variable.Description)
d.Set("value", variable.Value)
d.Set("is_sensitive", variable.IsSensitive)
if variable.Type == client.ConfigurationVariableTypeTerraform {
Expand All @@ -184,6 +191,7 @@ func resourceConfigurationVariableUpdate(ctx context.Context, d *schema.Resource
id := d.Id()
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)
Expand All @@ -200,7 +208,7 @@ func resourceConfigurationVariableUpdate(ctx context.Context, d *schema.Resource
if getEnumErr != nil {
return getEnumErr
}
_, err := apiClient.ConfigurationVariableUpdate(id, name, value, isSensitive, scope, scopeId, type_, actualEnumValues)
_, err := apiClient.ConfigurationVariableUpdate(id, name, value, isSensitive, scope, scopeId, type_, actualEnumValues, description)
if err != nil {
return diag.Errorf("could not update configurationVariable: %v", err)
}
Expand Down
Loading

0 comments on commit 048f3be

Please sign in to comment.