diff --git a/client/shared_environment_variable.go b/client/shared_environment_variable.go index f3cdacf0..eeef7bde 100644 --- a/client/shared_environment_variable.go +++ b/client/shared_environment_variable.go @@ -8,14 +8,15 @@ import ( ) type SharedEnvironmentVariableResponse struct { - Key string `json:"key"` - TeamID string `json:"ownerId"` - ID string `json:"id,omitempty"` - Value string `json:"value"` - Type string `json:"type"` - Target []string `json:"target"` - ProjectIDs []string `json:"projectId"` - Comment string `json:"comment"` + Key string `json:"key"` + TeamID string `json:"ownerId"` + ID string `json:"id,omitempty"` + Value string `json:"value"` + Type string `json:"type"` + Target []string `json:"target"` + ProjectIDs []string `json:"projectId"` + Comment string `json:"comment"` + ApplyToAllCustomEnvironments bool `json:"applyToAllCustomEnvironments"` } type SharedEnvVarRequest struct { @@ -25,10 +26,11 @@ type SharedEnvVarRequest struct { } type SharedEnvironmentVariableRequest struct { - Type string `json:"type"` - ProjectIDs []string `json:"projectId"` - Target []string `json:"target"` - EnvironmentVariables []SharedEnvVarRequest `json:"evs"` + Type string `json:"type"` + ProjectIDs []string `json:"projectId"` + Target []string `json:"target"` + ApplyToAllCustomEnvironments bool `json:"applyToAllCustomEnvironments"` + EnvironmentVariables []SharedEnvVarRequest `json:"evs"` } type CreateSharedEnvironmentVariableRequest struct { @@ -169,14 +171,15 @@ type UpdateSharedEnvironmentVariableRequestProjectIDUpdates struct { } type UpdateSharedEnvironmentVariableRequest struct { - Value string `json:"value,omitempty"` - Type string `json:"type,omitempty"` - ProjectIDs []string `json:"projectId,omitempty"` - ProjectIDUpdates UpdateSharedEnvironmentVariableRequestProjectIDUpdates `json:"projectIdUpdates,omitempty"` - Target []string `json:"target,omitempty"` - Comment string `json:"comment,omitempty"` - TeamID string `json:"-"` - EnvID string `json:"-"` + Value string `json:"value,omitempty"` + Type string `json:"type,omitempty"` + ProjectIDs []string `json:"projectId,omitempty"` + ProjectIDUpdates UpdateSharedEnvironmentVariableRequestProjectIDUpdates `json:"projectIdUpdates,omitempty"` + ApplyToAllCustomEnvironments bool `json:"applyToAllCustomEnvironments,omitempty"` + Target []string `json:"target,omitempty"` + Comment string `json:"comment,omitempty"` + TeamID string `json:"-"` + EnvID string `json:"-"` } func (c *Client) UpdateSharedEnvironmentVariable(ctx context.Context, request UpdateSharedEnvironmentVariableRequest) (e SharedEnvironmentVariableResponse, err error) { diff --git a/docs/data-sources/shared_environment_variable.md b/docs/data-sources/shared_environment_variable.md index ede35006..2cbd1b76 100644 --- a/docs/data-sources/shared_environment_variable.md +++ b/docs/data-sources/shared_environment_variable.md @@ -45,6 +45,7 @@ data "vercel_shared_environment_variable" "example_by_key_and_target" { ### Read-Only +- `apply_to_all_custom_environments` (Boolean) Whether the Environment Variable should be applied to all custom environments. - `comment` (String) A comment explaining what the environment variable is for. - `project_ids` (Set of String) The ID of the Vercel project. - `sensitive` (Boolean) Whether the Environment Variable is sensitive or not. diff --git a/docs/resources/shared_environment_variable.md b/docs/resources/shared_environment_variable.md index a1157104..daa9ee79 100644 --- a/docs/resources/shared_environment_variable.md +++ b/docs/resources/shared_environment_variable.md @@ -53,6 +53,7 @@ resource "vercel_shared_environment_variable" "example" { ### Optional +- `apply_to_all_custom_environments` (Boolean) Whether the shared environment variable should be applied to all custom environments in the linked projects. - `comment` (String) A comment explaining what the environment variable is for. - `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)) - `team_id` (String) The ID of the Vercel team. Shared environment variables require a team. diff --git a/vercel/data_source_shared_environment_variable.go b/vercel/data_source_shared_environment_variable.go index a0ab833d..259ef60a 100644 --- a/vercel/data_source_shared_environment_variable.go +++ b/vercel/data_source_shared_environment_variable.go @@ -139,6 +139,10 @@ For more detailed information, please see the [Vercel documentation](https://ver Description: "A comment explaining what the environment variable is for.", Computed: true, }, + "apply_to_all_custom_environments": schema.BoolAttribute{ + Description: "Whether the Environment Variable should be applied to all custom environments.", + Computed: true, + }, }, } } diff --git a/vercel/data_source_shared_environment_variable_test.go b/vercel/data_source_shared_environment_variable_test.go index daab29a2..576674a1 100644 --- a/vercel/data_source_shared_environment_variable_test.go +++ b/vercel/data_source_shared_environment_variable_test.go @@ -18,6 +18,7 @@ func TestAcc_SharedEnvironmentVariableDataSource(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "key", "test_acc_"+name), resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "value", "foobar"), + resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "apply_to_all_custom_environments", "true"), resource.TestCheckTypeSetElemAttr("data.vercel_shared_environment_variable.test", "target.*", "production"), resource.TestCheckTypeSetElemAttr("data.vercel_shared_environment_variable.test", "target.*", "preview"), resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "sensitive", "false"), @@ -49,6 +50,7 @@ resource "vercel_shared_environment_variable" "test" { value = "foobar" target = [ "production", "preview" ] project_ids = [ vercel_project.test.id ] + apply_to_all_custom_environments = true } data "vercel_shared_environment_variable" "test" { diff --git a/vercel/resource_shared_environment_variable.go b/vercel/resource_shared_environment_variable.go index 70a0f977..d21fe238 100644 --- a/vercel/resource_shared_environment_variable.go +++ b/vercel/resource_shared_environment_variable.go @@ -160,20 +160,26 @@ For more detailed information, please see the [Vercel documentation](https://ver stringvalidator.LengthBetween(0, 1000), }, }, + "apply_to_all_custom_environments": schema.BoolAttribute{ + Description: "Whether the shared environment variable should be applied to all custom environments in the linked projects.", + Optional: true, + Computed: true, + }, }, } } // SharedEnvironmentVariable reflects the state terraform stores internally for a project environment variable. type SharedEnvironmentVariable struct { - Target types.Set `tfsdk:"target"` - Key types.String `tfsdk:"key"` - Value types.String `tfsdk:"value"` - TeamID types.String `tfsdk:"team_id"` - ProjectIDs types.Set `tfsdk:"project_ids"` - ID types.String `tfsdk:"id"` - Sensitive types.Bool `tfsdk:"sensitive"` - Comment types.String `tfsdk:"comment"` + Target types.Set `tfsdk:"target"` + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` + TeamID types.String `tfsdk:"team_id"` + ProjectIDs types.Set `tfsdk:"project_ids"` + ID types.String `tfsdk:"id"` + Sensitive types.Bool `tfsdk:"sensitive"` + Comment types.String `tfsdk:"comment"` + ApplyToAllCustomEnvironments types.Bool `tfsdk:"apply_to_all_custom_environments"` } func (e *SharedEnvironmentVariable) toCreateSharedEnvironmentVariableRequest(ctx context.Context, diags diag.Diagnostics) (req client.CreateSharedEnvironmentVariableRequest, ok bool) { @@ -201,9 +207,10 @@ func (e *SharedEnvironmentVariable) toCreateSharedEnvironmentVariableRequest(ctx return client.CreateSharedEnvironmentVariableRequest{ EnvironmentVariable: client.SharedEnvironmentVariableRequest{ - Target: target, - Type: envVariableType, - ProjectIDs: projectIDs, + ApplyToAllCustomEnvironments: e.ApplyToAllCustomEnvironments.ValueBool(), + Target: target, + Type: envVariableType, + ProjectIDs: projectIDs, EnvironmentVariables: []client.SharedEnvVarRequest{ { Key: e.Key.ValueString(), @@ -238,13 +245,14 @@ func (e *SharedEnvironmentVariable) toUpdateSharedEnvironmentVariableRequest(ctx envVariableType = "encrypted" } return client.UpdateSharedEnvironmentVariableRequest{ - Value: e.Value.ValueString(), - Target: target, - Type: envVariableType, - TeamID: e.TeamID.ValueString(), - EnvID: e.ID.ValueString(), - ProjectIDs: projectIDs, - Comment: e.Comment.ValueString(), + ApplyToAllCustomEnvironments: e.ApplyToAllCustomEnvironments.ValueBool(), + Value: e.Value.ValueString(), + Target: target, + Type: envVariableType, + TeamID: e.TeamID.ValueString(), + EnvID: e.ID.ValueString(), + ProjectIDs: projectIDs, + Comment: e.Comment.ValueString(), }, true } @@ -268,14 +276,15 @@ func convertResponseToSharedEnvironmentVariable(response client.SharedEnvironmen } return SharedEnvironmentVariable{ - Target: types.SetValueMust(types.StringType, target), - Key: types.StringValue(response.Key), - Value: value, - ProjectIDs: types.SetValueMust(types.StringType, projectIDs), - TeamID: toTeamID(response.TeamID), - ID: types.StringValue(response.ID), - Sensitive: types.BoolValue(response.Type == "sensitive"), - Comment: types.StringValue(response.Comment), + ApplyToAllCustomEnvironments: types.BoolValue(response.ApplyToAllCustomEnvironments), + Target: types.SetValueMust(types.StringType, target), + Key: types.StringValue(response.Key), + Value: value, + ProjectIDs: types.SetValueMust(types.StringType, projectIDs), + TeamID: toTeamID(response.TeamID), + ID: types.StringValue(response.ID), + Sensitive: types.BoolValue(response.Type == "sensitive"), + Comment: types.StringValue(response.Comment), } } diff --git a/vercel/resource_shared_environment_variable_test.go b/vercel/resource_shared_environment_variable_test.go index 41f3b5b9..45413c1c 100644 --- a/vercel/resource_shared_environment_variable_test.go +++ b/vercel/resource_shared_environment_variable_test.go @@ -42,6 +42,7 @@ func TestAcc_SharedEnvironmentVariables(t *testing.T) { resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "key", fmt.Sprintf("test_acc_foo_%s", nameSuffix)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "value", "bar"), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "comment", "Test comment for example"), + resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "apply_to_all_custom_environments", "true"), resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.example", "target.*", "production"), testAccSharedEnvironmentVariableExists(testClient(t), "vercel_shared_environment_variable.sensitive_example", testTeam(t)), @@ -63,6 +64,7 @@ func TestAcc_SharedEnvironmentVariables(t *testing.T) { testAccSharedEnvironmentVariableExists(testClient(t), "vercel_shared_environment_variable.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "key", fmt.Sprintf("test_acc_foo_%s", nameSuffix)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "value", "updated-bar"), + resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "apply_to_all_custom_environments", "false"), resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.example", "target.*", "development"), resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.example", "target.*", "preview"), @@ -113,6 +115,7 @@ resource "vercel_shared_environment_variable" "example" { vercel_project.example.id ] comment = "Test comment for example" + apply_to_all_custom_environments = true } resource "vercel_shared_environment_variable" "sensitive_example" { @@ -155,6 +158,7 @@ resource "vercel_shared_environment_variable" "example" { vercel_project.example.id, vercel_project.example2.id ] + apply_to_all_custom_environments = false } resource "vercel_shared_environment_variable" "sensitive_example" {