Skip to content

Commit 656872f

Browse files
authored
Support setting apply_to_all_custom_environments on vercel_shared_environment_variable resources (#329)
1 parent 84fb20e commit 656872f

7 files changed

+70
-46
lines changed

client/shared_environment_variable.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
)
99

1010
type SharedEnvironmentVariableResponse struct {
11-
Key string `json:"key"`
12-
TeamID string `json:"ownerId"`
13-
ID string `json:"id,omitempty"`
14-
Value string `json:"value"`
15-
Type string `json:"type"`
16-
Target []string `json:"target"`
17-
ProjectIDs []string `json:"projectId"`
18-
Comment string `json:"comment"`
11+
Key string `json:"key"`
12+
TeamID string `json:"ownerId"`
13+
ID string `json:"id,omitempty"`
14+
Value string `json:"value"`
15+
Type string `json:"type"`
16+
Target []string `json:"target"`
17+
ProjectIDs []string `json:"projectId"`
18+
Comment string `json:"comment"`
19+
ApplyToAllCustomEnvironments bool `json:"applyToAllCustomEnvironments"`
1920
}
2021

2122
type SharedEnvVarRequest struct {
@@ -25,10 +26,11 @@ type SharedEnvVarRequest struct {
2526
}
2627

2728
type SharedEnvironmentVariableRequest struct {
28-
Type string `json:"type"`
29-
ProjectIDs []string `json:"projectId"`
30-
Target []string `json:"target"`
31-
EnvironmentVariables []SharedEnvVarRequest `json:"evs"`
29+
Type string `json:"type"`
30+
ProjectIDs []string `json:"projectId"`
31+
Target []string `json:"target"`
32+
ApplyToAllCustomEnvironments bool `json:"applyToAllCustomEnvironments"`
33+
EnvironmentVariables []SharedEnvVarRequest `json:"evs"`
3234
}
3335

3436
type CreateSharedEnvironmentVariableRequest struct {
@@ -169,14 +171,15 @@ type UpdateSharedEnvironmentVariableRequestProjectIDUpdates struct {
169171
}
170172

171173
type UpdateSharedEnvironmentVariableRequest struct {
172-
Value string `json:"value,omitempty"`
173-
Type string `json:"type,omitempty"`
174-
ProjectIDs []string `json:"projectId,omitempty"`
175-
ProjectIDUpdates UpdateSharedEnvironmentVariableRequestProjectIDUpdates `json:"projectIdUpdates,omitempty"`
176-
Target []string `json:"target,omitempty"`
177-
Comment string `json:"comment,omitempty"`
178-
TeamID string `json:"-"`
179-
EnvID string `json:"-"`
174+
Value string `json:"value,omitempty"`
175+
Type string `json:"type,omitempty"`
176+
ProjectIDs []string `json:"projectId,omitempty"`
177+
ProjectIDUpdates UpdateSharedEnvironmentVariableRequestProjectIDUpdates `json:"projectIdUpdates,omitempty"`
178+
ApplyToAllCustomEnvironments bool `json:"applyToAllCustomEnvironments,omitempty"`
179+
Target []string `json:"target,omitempty"`
180+
Comment string `json:"comment,omitempty"`
181+
TeamID string `json:"-"`
182+
EnvID string `json:"-"`
180183
}
181184

182185
func (c *Client) UpdateSharedEnvironmentVariable(ctx context.Context, request UpdateSharedEnvironmentVariableRequest) (e SharedEnvironmentVariableResponse, err error) {

docs/data-sources/shared_environment_variable.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ data "vercel_shared_environment_variable" "example_by_key_and_target" {
4545

4646
### Read-Only
4747

48+
- `apply_to_all_custom_environments` (Boolean) Whether the Environment Variable should be applied to all custom environments.
4849
- `comment` (String) A comment explaining what the environment variable is for.
4950
- `project_ids` (Set of String) The ID of the Vercel project.
5051
- `sensitive` (Boolean) Whether the Environment Variable is sensitive or not.

docs/resources/shared_environment_variable.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ resource "vercel_shared_environment_variable" "example" {
5353

5454
### Optional
5555

56+
- `apply_to_all_custom_environments` (Boolean) Whether the shared environment variable should be applied to all custom environments in the linked projects.
5657
- `comment` (String) A comment explaining what the environment variable is for.
5758
- `sensitive` (Boolean) Whether the Environment Variable is sensitive or not. (May be affected by a [team-wide environment variable policy](https://vercel.com/docs/projects/environment-variables/sensitive-environment-variables#environment-variables-policy))
5859
- `team_id` (String) The ID of the Vercel team. Shared environment variables require a team.

vercel/data_source_shared_environment_variable.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ For more detailed information, please see the [Vercel documentation](https://ver
139139
Description: "A comment explaining what the environment variable is for.",
140140
Computed: true,
141141
},
142+
"apply_to_all_custom_environments": schema.BoolAttribute{
143+
Description: "Whether the Environment Variable should be applied to all custom environments.",
144+
Computed: true,
145+
},
142146
},
143147
}
144148
}

vercel/data_source_shared_environment_variable_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestAcc_SharedEnvironmentVariableDataSource(t *testing.T) {
1818
Check: resource.ComposeAggregateTestCheckFunc(
1919
resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "key", "test_acc_"+name),
2020
resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "value", "foobar"),
21+
resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "apply_to_all_custom_environments", "true"),
2122
resource.TestCheckTypeSetElemAttr("data.vercel_shared_environment_variable.test", "target.*", "production"),
2223
resource.TestCheckTypeSetElemAttr("data.vercel_shared_environment_variable.test", "target.*", "preview"),
2324
resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "sensitive", "false"),
@@ -49,6 +50,7 @@ resource "vercel_shared_environment_variable" "test" {
4950
value = "foobar"
5051
target = [ "production", "preview" ]
5152
project_ids = [ vercel_project.test.id ]
53+
apply_to_all_custom_environments = true
5254
}
5355
5456
data "vercel_shared_environment_variable" "test" {

vercel/resource_shared_environment_variable.go

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,26 @@ For more detailed information, please see the [Vercel documentation](https://ver
160160
stringvalidator.LengthBetween(0, 1000),
161161
},
162162
},
163+
"apply_to_all_custom_environments": schema.BoolAttribute{
164+
Description: "Whether the shared environment variable should be applied to all custom environments in the linked projects.",
165+
Optional: true,
166+
Computed: true,
167+
},
163168
},
164169
}
165170
}
166171

167172
// SharedEnvironmentVariable reflects the state terraform stores internally for a project environment variable.
168173
type SharedEnvironmentVariable struct {
169-
Target types.Set `tfsdk:"target"`
170-
Key types.String `tfsdk:"key"`
171-
Value types.String `tfsdk:"value"`
172-
TeamID types.String `tfsdk:"team_id"`
173-
ProjectIDs types.Set `tfsdk:"project_ids"`
174-
ID types.String `tfsdk:"id"`
175-
Sensitive types.Bool `tfsdk:"sensitive"`
176-
Comment types.String `tfsdk:"comment"`
174+
Target types.Set `tfsdk:"target"`
175+
Key types.String `tfsdk:"key"`
176+
Value types.String `tfsdk:"value"`
177+
TeamID types.String `tfsdk:"team_id"`
178+
ProjectIDs types.Set `tfsdk:"project_ids"`
179+
ID types.String `tfsdk:"id"`
180+
Sensitive types.Bool `tfsdk:"sensitive"`
181+
Comment types.String `tfsdk:"comment"`
182+
ApplyToAllCustomEnvironments types.Bool `tfsdk:"apply_to_all_custom_environments"`
177183
}
178184

179185
func (e *SharedEnvironmentVariable) toCreateSharedEnvironmentVariableRequest(ctx context.Context, diags diag.Diagnostics) (req client.CreateSharedEnvironmentVariableRequest, ok bool) {
@@ -201,9 +207,10 @@ func (e *SharedEnvironmentVariable) toCreateSharedEnvironmentVariableRequest(ctx
201207

202208
return client.CreateSharedEnvironmentVariableRequest{
203209
EnvironmentVariable: client.SharedEnvironmentVariableRequest{
204-
Target: target,
205-
Type: envVariableType,
206-
ProjectIDs: projectIDs,
210+
ApplyToAllCustomEnvironments: e.ApplyToAllCustomEnvironments.ValueBool(),
211+
Target: target,
212+
Type: envVariableType,
213+
ProjectIDs: projectIDs,
207214
EnvironmentVariables: []client.SharedEnvVarRequest{
208215
{
209216
Key: e.Key.ValueString(),
@@ -238,13 +245,14 @@ func (e *SharedEnvironmentVariable) toUpdateSharedEnvironmentVariableRequest(ctx
238245
envVariableType = "encrypted"
239246
}
240247
return client.UpdateSharedEnvironmentVariableRequest{
241-
Value: e.Value.ValueString(),
242-
Target: target,
243-
Type: envVariableType,
244-
TeamID: e.TeamID.ValueString(),
245-
EnvID: e.ID.ValueString(),
246-
ProjectIDs: projectIDs,
247-
Comment: e.Comment.ValueString(),
248+
ApplyToAllCustomEnvironments: e.ApplyToAllCustomEnvironments.ValueBool(),
249+
Value: e.Value.ValueString(),
250+
Target: target,
251+
Type: envVariableType,
252+
TeamID: e.TeamID.ValueString(),
253+
EnvID: e.ID.ValueString(),
254+
ProjectIDs: projectIDs,
255+
Comment: e.Comment.ValueString(),
248256
}, true
249257
}
250258

@@ -268,14 +276,15 @@ func convertResponseToSharedEnvironmentVariable(response client.SharedEnvironmen
268276
}
269277

270278
return SharedEnvironmentVariable{
271-
Target: types.SetValueMust(types.StringType, target),
272-
Key: types.StringValue(response.Key),
273-
Value: value,
274-
ProjectIDs: types.SetValueMust(types.StringType, projectIDs),
275-
TeamID: toTeamID(response.TeamID),
276-
ID: types.StringValue(response.ID),
277-
Sensitive: types.BoolValue(response.Type == "sensitive"),
278-
Comment: types.StringValue(response.Comment),
279+
ApplyToAllCustomEnvironments: types.BoolValue(response.ApplyToAllCustomEnvironments),
280+
Target: types.SetValueMust(types.StringType, target),
281+
Key: types.StringValue(response.Key),
282+
Value: value,
283+
ProjectIDs: types.SetValueMust(types.StringType, projectIDs),
284+
TeamID: toTeamID(response.TeamID),
285+
ID: types.StringValue(response.ID),
286+
Sensitive: types.BoolValue(response.Type == "sensitive"),
287+
Comment: types.StringValue(response.Comment),
279288
}
280289
}
281290

vercel/resource_shared_environment_variable_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestAcc_SharedEnvironmentVariables(t *testing.T) {
4242
resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "key", fmt.Sprintf("test_acc_foo_%s", nameSuffix)),
4343
resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "value", "bar"),
4444
resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "comment", "Test comment for example"),
45+
resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "apply_to_all_custom_environments", "true"),
4546
resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.example", "target.*", "production"),
4647

4748
testAccSharedEnvironmentVariableExists(testClient(t), "vercel_shared_environment_variable.sensitive_example", testTeam(t)),
@@ -63,6 +64,7 @@ func TestAcc_SharedEnvironmentVariables(t *testing.T) {
6364
testAccSharedEnvironmentVariableExists(testClient(t), "vercel_shared_environment_variable.example", testTeam(t)),
6465
resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "key", fmt.Sprintf("test_acc_foo_%s", nameSuffix)),
6566
resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "value", "updated-bar"),
67+
resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "apply_to_all_custom_environments", "false"),
6668
resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.example", "target.*", "development"),
6769
resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.example", "target.*", "preview"),
6870

@@ -113,6 +115,7 @@ resource "vercel_shared_environment_variable" "example" {
113115
vercel_project.example.id
114116
]
115117
comment = "Test comment for example"
118+
apply_to_all_custom_environments = true
116119
}
117120
118121
resource "vercel_shared_environment_variable" "sensitive_example" {
@@ -155,6 +158,7 @@ resource "vercel_shared_environment_variable" "example" {
155158
vercel_project.example.id,
156159
vercel_project.example2.id
157160
]
161+
apply_to_all_custom_environments = false
158162
}
159163
160164
resource "vercel_shared_environment_variable" "sensitive_example" {

0 commit comments

Comments
 (0)