4
4
"context"
5
5
"log"
6
6
"net/http"
7
+ "net/url"
7
8
8
9
"github.com/google/go-github/v55/github"
9
10
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@@ -63,7 +64,8 @@ func resourceGithubActionsEnvironmentVariableCreate(d *schema.ResourceData, meta
63
64
ctx := context .Background ()
64
65
65
66
repoName := d .Get ("repository" ).(string )
66
- env := d .Get ("environment" ).(string )
67
+ envName := d .Get ("environment" ).(string )
68
+ escapedEnvName := url .PathEscape (envName )
67
69
name := d .Get ("variable_name" ).(string )
68
70
69
71
variable := & github.ActionsVariable {
@@ -76,12 +78,12 @@ func resourceGithubActionsEnvironmentVariableCreate(d *schema.ResourceData, meta
76
78
return err
77
79
}
78
80
79
- _ , err = client .Actions .CreateEnvVariable (ctx , int (repo .GetID ()), env , variable )
81
+ _ , err = client .Actions .CreateEnvVariable (ctx , int (repo .GetID ()), escapedEnvName , variable )
80
82
if err != nil {
81
83
return err
82
84
}
83
85
84
- d .SetId (buildThreePartID (repoName , env , name ))
86
+ d .SetId (buildThreePartID (repoName , envName , name ))
85
87
return resourceGithubActionsEnvironmentVariableRead (d , meta )
86
88
}
87
89
@@ -91,7 +93,8 @@ func resourceGithubActionsEnvironmentVariableUpdate(d *schema.ResourceData, meta
91
93
ctx := context .Background ()
92
94
93
95
repoName := d .Get ("repository" ).(string )
94
- env := d .Get ("environment" ).(string )
96
+ envName := d .Get ("environment" ).(string )
97
+ escapedEnvName := url .PathEscape (envName )
95
98
name := d .Get ("variable_name" ).(string )
96
99
97
100
variable := & github.ActionsVariable {
@@ -103,12 +106,12 @@ func resourceGithubActionsEnvironmentVariableUpdate(d *schema.ResourceData, meta
103
106
if err != nil {
104
107
return err
105
108
}
106
- _ , err = client .Actions .UpdateEnvVariable (ctx , int (repo .GetID ()), env , variable )
109
+ _ , err = client .Actions .UpdateEnvVariable (ctx , int (repo .GetID ()), escapedEnvName , variable )
107
110
if err != nil {
108
111
return err
109
112
}
110
113
111
- d .SetId (buildThreePartID (repoName , env , name ))
114
+ d .SetId (buildThreePartID (repoName , envName , name ))
112
115
return resourceGithubActionsEnvironmentVariableRead (d , meta )
113
116
}
114
117
@@ -117,17 +120,18 @@ func resourceGithubActionsEnvironmentVariableRead(d *schema.ResourceData, meta i
117
120
owner := meta .(* Owner ).name
118
121
ctx := context .Background ()
119
122
120
- repoName , env , name , err := parseThreePartID (d .Id (), "repository" , "environment" , "variable_name" )
123
+ repoName , envName , name , err := parseThreePartID (d .Id (), "repository" , "environment" , "variable_name" )
121
124
if err != nil {
122
125
return err
123
126
}
127
+ escapedEnvName := url .PathEscape (envName )
124
128
125
129
repo , _ , err := client .Repositories .Get (ctx , owner , repoName )
126
130
if err != nil {
127
131
return err
128
132
}
129
133
130
- variable , _ , err := client .Actions .GetEnvVariable (ctx , int (repo .GetID ()), env , name )
134
+ variable , _ , err := client .Actions .GetEnvVariable (ctx , int (repo .GetID ()), escapedEnvName , name )
131
135
if err != nil {
132
136
if ghErr , ok := err .(* github.ErrorResponse ); ok {
133
137
if ghErr .Response .StatusCode == http .StatusNotFound {
@@ -141,7 +145,7 @@ func resourceGithubActionsEnvironmentVariableRead(d *schema.ResourceData, meta i
141
145
}
142
146
143
147
d .Set ("repository" , repoName )
144
- d .Set ("environment" , env )
148
+ d .Set ("environment" , envName )
145
149
d .Set ("variable_name" , name )
146
150
d .Set ("value" , variable .Value )
147
151
d .Set ("created_at" , variable .CreatedAt .String ())
@@ -155,17 +159,18 @@ func resourceGithubActionsEnvironmentVariableDelete(d *schema.ResourceData, meta
155
159
owner := meta .(* Owner ).name
156
160
ctx := context .WithValue (context .Background (), ctxId , d .Id ())
157
161
158
- repoName , env , name , err := parseThreePartID (d .Id (), "repository" , "environment" , "variable_name" )
162
+ repoName , envName , name , err := parseThreePartID (d .Id (), "repository" , "environment" , "variable_name" )
159
163
if err != nil {
160
164
return err
161
165
}
166
+ escapedEnvName := url .QueryEscape (envName )
162
167
163
168
repo , _ , err := client .Repositories .Get (ctx , owner , repoName )
164
169
if err != nil {
165
170
return err
166
171
}
167
172
168
- _ , err = client .Actions .DeleteEnvVariable (ctx , int (repo .GetID ()), env , name )
173
+ _ , err = client .Actions .DeleteEnvVariable (ctx , int (repo .GetID ()), escapedEnvName , name )
169
174
170
175
return err
171
176
}
0 commit comments