Skip to content

Commit ee9072e

Browse files
Refactor Project_variable to use project variable from new library
1 parent a900c3c commit ee9072e

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

gitlab/resource_gitlab_project_variable.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,21 @@ func resourceGitlabProjectVariable() *schema.Resource {
4343

4444
func resourceGitlabProjectVariableCreate(d *schema.ResourceData, meta interface{}) error {
4545
client := meta.(*gitlab.Client)
46+
4647
project := d.Get("project").(string)
4748
key := d.Get("key").(string)
48-
options := &gitlab.CreateBuildVariableOptions{
49-
Key: gitlab.String(key),
50-
Value: gitlab.String(d.Get("value").(string)),
51-
Protected: gitlab.Bool(d.Get("protected").(bool)),
49+
value := d.Get("value").(string)
50+
protected := d.Get("protected").(bool)
51+
52+
options := gitlab.CreateVariableOptions{
53+
Key: &key,
54+
Value: &value,
55+
Protected: &protected,
56+
EnvironmentScope: nil,
5257
}
5358
log.Printf("[DEBUG] create gitlab project variable %s/%s", project, key)
5459

55-
v, _, err := client.BuildVariables.CreateBuildVariable(project, options)
60+
v, _, err := client.ProjectVariables.CreateVariable(project, &options)
5661
if err != nil {
5762
return err
5863
}
@@ -72,7 +77,7 @@ func resourceGitlabProjectVariableRead(d *schema.ResourceData, meta interface{})
7277

7378
log.Printf("[DEBUG] read gitlab project variable %s/%s", project, key)
7479

75-
v, _, err := client.BuildVariables.GetBuildVariable(project, key)
80+
v, _, err := client.ProjectVariables.GetVariable(project, key)
7681
if err != nil {
7782
return err
7883
}
@@ -88,16 +93,21 @@ func resourceGitlabProjectVariableRead(d *schema.ResourceData, meta interface{})
8893

8994
func resourceGitlabProjectVariableUpdate(d *schema.ResourceData, meta interface{}) error {
9095
client := meta.(*gitlab.Client)
96+
9197
project := d.Get("project").(string)
9298
key := d.Get("key").(string)
93-
options := &gitlab.UpdateBuildVariableOptions{
94-
Key: gitlab.String(d.Get("key").(string)),
95-
Value: gitlab.String(d.Get("value").(string)),
96-
Protected: gitlab.Bool(d.Get("protected").(bool)),
99+
value := d.Get("value").(string)
100+
protected := d.Get("protected").(bool)
101+
102+
options := &gitlab.UpdateVariableOptions{
103+
Key: &key,
104+
Value: &value,
105+
Protected: &protected,
106+
EnvironmentScope: nil,
97107
}
98108
log.Printf("[DEBUG] update gitlab project variable %s/%s", project, key)
99109

100-
v, _, err := client.BuildVariables.UpdateBuildVariable(project, key, options)
110+
v, _, err := client.ProjectVariables.UpdateVariable(project, key, options)
101111
if err != nil {
102112
return err
103113
}
@@ -113,6 +123,6 @@ func resourceGitlabProjectVariableDelete(d *schema.ResourceData, meta interface{
113123
key := d.Get("key").(string)
114124
log.Printf("[DEBUG] Delete gitlab project variable %s/%s", project, key)
115125

116-
_, err := client.BuildVariables.RemoveBuildVariable(project, key)
126+
_, err := client.ProjectVariables.RemoveVariable(project, key)
117127
return err
118128
}

gitlab/resource_gitlab_project_variable_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestAccGitlabProjectVariable_basic(t *testing.T) {
14-
var projectVariable gitlab.BuildVariable
14+
var projectVariable gitlab.ProjectVariable
1515
rString := acctest.RandString(5)
1616

1717
resource.Test(t, resource.TestCase{
@@ -58,7 +58,7 @@ func TestAccGitlabProjectVariable_basic(t *testing.T) {
5858
})
5959
}
6060

61-
func testAccCheckGitlabProjectVariableExists(n string, projectVariable *gitlab.BuildVariable) resource.TestCheckFunc {
61+
func testAccCheckGitlabProjectVariableExists(n string, projectVariable *gitlab.ProjectVariable) resource.TestCheckFunc {
6262
return func(s *terraform.State) error {
6363
rs, ok := s.RootModule().Resources[n]
6464
if !ok {
@@ -75,7 +75,7 @@ func testAccCheckGitlabProjectVariableExists(n string, projectVariable *gitlab.B
7575
}
7676
conn := testAccProvider.Meta().(*gitlab.Client)
7777

78-
gotVariable, _, err := conn.BuildVariables.GetBuildVariable(repoName, key)
78+
gotVariable, _, err := conn.ProjectVariables.GetVariable(repoName, key)
7979
if err != nil {
8080
return err
8181
}
@@ -90,7 +90,7 @@ type testAccGitlabProjectVariableExpectedAttributes struct {
9090
Protected bool
9191
}
9292

93-
func testAccCheckGitlabProjectVariableAttributes(variable *gitlab.BuildVariable, want *testAccGitlabProjectVariableExpectedAttributes) resource.TestCheckFunc {
93+
func testAccCheckGitlabProjectVariableAttributes(variable *gitlab.ProjectVariable, want *testAccGitlabProjectVariableExpectedAttributes) resource.TestCheckFunc {
9494
return func(s *terraform.State) error {
9595
if variable.Key != want.Key {
9696
return fmt.Errorf("got key %s; want %s", variable.Key, want.Key)

0 commit comments

Comments
 (0)