diff --git a/helper_test.go b/helper_test.go index 84f7b48..f380028 100644 --- a/helper_test.go +++ b/helper_test.go @@ -168,10 +168,11 @@ func createVariable(t *testing.T, client *Client, ws *Workspace) (*Variable, fun ctx := context.Background() v, err := client.Variables.Create(ctx, VariableCreateOptions{ - Key: String(randomString(t)), - Value: String(randomString(t)), - Category: Category(CategoryTerraform), - Workspace: ws, + Key: String(randomString(t)), + Value: String(randomString(t)), + Category: Category(CategoryTerraform), + Description: String("Create by go-scalr test helper."), + Workspace: ws, }) if err != nil { t.Fatal(err) diff --git a/variable.go b/variable.go index 6081b7b..9ad52b0 100644 --- a/variable.go +++ b/variable.go @@ -50,13 +50,14 @@ type VariableList struct { // Variable represents a Scalr variable. type Variable struct { - ID string `jsonapi:"primary,vars"` - Key string `jsonapi:"attr,key"` - Value string `jsonapi:"attr,value"` - Category CategoryType `jsonapi:"attr,category"` - HCL bool `jsonapi:"attr,hcl"` - Sensitive bool `jsonapi:"attr,sensitive"` - Final bool `jsonapi:"attr,final"` + ID string `jsonapi:"primary,vars"` + Key string `jsonapi:"attr,key"` + Value string `jsonapi:"attr,value"` + Category CategoryType `jsonapi:"attr,category"` + Description string `jsonapi:"attr,description"` + HCL bool `jsonapi:"attr,hcl"` + Sensitive bool `jsonapi:"attr,sensitive"` + Final bool `jsonapi:"attr,final"` // Relations Workspace *Workspace `jsonapi:"relation,workspace"` @@ -82,6 +83,9 @@ type VariableCreateOptions struct { // Whether this is a Terraform or environment variable. Category *CategoryType `jsonapi:"attr,category"` + // Variable description. + Description *string `jsonapi:"attr,description"` + // Whether to evaluate the value of the variable as a string of HCL code. HCL *bool `jsonapi:"attr,hcl,omitempty"` @@ -177,6 +181,9 @@ type VariableUpdateOptions struct { // The value of the variable. Value *string `jsonapi:"attr,value,omitempty"` + // The description of the variable. + Description *string `jsonapi:"attr,description,omitempty"` + // Whether to evaluate the value of the variable as a string of HCL code. HCL *bool `jsonapi:"attr,hcl,omitempty"` diff --git a/variable_test.go b/variable_test.go index d98770d..a61841a 100644 --- a/variable_test.go +++ b/variable_test.go @@ -20,10 +20,11 @@ func TestVariablesCreate(t *testing.T) { t.Run("when options has an empty string value", func(t *testing.T) { options := VariableCreateOptions{ - Key: String(randomVariableKey(t)), - Value: String(""), - Category: Category(CategoryShell), - Workspace: wsTest, + Key: String(randomVariableKey(t)), + Value: String(""), + Category: Category(CategoryShell), + Description: String("random variable test"), + Workspace: wsTest, } v, err := client.Variables.Create(ctx, options) @@ -33,6 +34,7 @@ func TestVariablesCreate(t *testing.T) { assert.Equal(t, *options.Key, v.Key) assert.Equal(t, *options.Value, v.Value) assert.Equal(t, *options.Category, v.Category) + assert.Equal(t, *options.Description, v.Description) }) t.Run("when options is missing value", func(t *testing.T) { @@ -156,6 +158,7 @@ func TestVariablesRead(t *testing.T) { require.NoError(t, err) assert.Equal(t, vTest.ID, v.ID) assert.Equal(t, vTest.Category, v.Category) + assert.Equal(t, vTest.Description, v.Description) assert.Equal(t, vTest.HCL, v.HCL) assert.Equal(t, vTest.Key, v.Key) assert.Equal(t, vTest.Sensitive, v.Sensitive) @@ -191,9 +194,10 @@ func TestVariablesUpdate(t *testing.T) { t.Run("with valid options", func(t *testing.T) { options := VariableUpdateOptions{ - Key: String("newname"), - Value: String("newvalue"), - HCL: Bool(true), + Key: String("newname"), + Value: String("newvalue"), + Description: String("newdescription"), + HCL: Bool(true), } v, err := client.Variables.Update(ctx, vTest.ID, options) @@ -202,6 +206,7 @@ func TestVariablesUpdate(t *testing.T) { assert.Equal(t, *options.Key, v.Key) assert.Equal(t, *options.HCL, v.HCL) assert.Equal(t, *options.Value, v.Value) + assert.Equal(t, *options.Description, v.Description) }) t.Run("when updating a subset of values", func(t *testing.T) {