Skip to content

Commit fe020b1

Browse files
authored
Add support for automatically exposing system env variables (#159)
This is a feature [in the Vercel UI](https://vercel.com/docs/projects/environment-variables/system-environment-variables) Add support to the TF provider. Closes #158
1 parent d54b3c6 commit fe020b1

10 files changed

+23
-1
lines changed

client/project_get.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type ProjectResponse struct {
8888
PasswordProtection *PasswordProtection `json:"passwordProtection"`
8989
TrustedIps *TrustedIps `json:"trustedIps"`
9090
ProtectionBypass map[string]ProtectionBypass `json:"protectionBypass"`
91+
AutoExposeSystemEnvVars *bool `json:"autoExposeSystemEnvs"`
9192
}
9293

9394
// GetProject retrieves information about an existing project from Vercel.

client/project_update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type UpdateProjectRequest struct {
2727
VercelAuthentication *VercelAuthentication `json:"ssoProtection"`
2828
PasswordProtection *PasswordProtectionWithPassword `json:"passwordProtection"`
2929
TrustedIps *TrustedIps `json:"trustedIps"`
30+
AutoExposeSystemEnvVars *bool `json:"autoExposeSystemEnvs,omitempty"`
3031
}
3132

3233
// UpdateProject updates an existing projects configuration within Vercel.

docs/data-sources/project.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ output "project_id" {
4242

4343
### Read-Only
4444

45+
- `automatically_expose_system_environment_variables` (Boolean) Vercel provides a set of Environment Variables that are automatically populated by the System, such as the URL of the Deployment or the name of the Git branch deployed. To expose them to your Deployments, enable this field
4546
- `build_command` (String) The build command for this project. If omitted, this value will be automatically detected.
4647
- `dev_command` (String) The dev command for this project. If omitted, this value will be automatically detected.
4748
- `environment` (Attributes Set) A list of environment variables that should be configured for the project. (see [below for nested schema](#nestedatt--environment))

docs/resources/project.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ resource "vercel_project" "example" {
5555

5656
### Optional
5757

58+
- `automatically_expose_system_environment_variables` (Boolean) Vercel provides a set of Environment Variables that are automatically populated by the System, such as the URL of the Deployment or the name of the Git branch deployed. To expose them to your Deployments, enable this field
5859
- `build_command` (String) The build command for this project. If omitted, this value will be automatically detected.
5960
- `dev_command` (String) The dev command for this project. If omitted, this value will be automatically detected.
6061
- `environment` (Attributes Set) A set of Environment Variables that should be configured for the project. (see [below for nested schema](#nestedatt--environment))

vercel/data_source_project.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ For more detailed information, please see the [Vercel documentation](https://ver
213213
Computed: true,
214214
Description: "The name of a directory or relative path to the source code of your project. When null is used it will default to the project root.",
215215
},
216+
"automatically_expose_system_environment_variables": schema.BoolAttribute{
217+
Computed: true,
218+
Description: "Vercel provides a set of Environment Variables that are automatically populated by the System, such as the URL of the Deployment or the name of the Git branch deployed. To expose them to your Deployments, enable this field",
219+
},
216220
},
217221
}
218222
}

vercel/data_source_project_model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type ProjectDataSource struct {
2626
VercelAuthentication *VercelAuthentication `tfsdk:"vercel_authentication"`
2727
PasswordProtection *PasswordProtection `tfsdk:"password_protection"`
2828
TrustedIps *TrustedIps `tfsdk:"trusted_ips"`
29+
AutoExposeSystemEnvVars types.Bool `tfsdk:"automatically_expose_system_environment_variables"`
2930
}
3031

3132
func convertResponseToProjectDataSource(ctx context.Context, response client.ProjectResponse, plan Project) (ProjectDataSource, error) {
@@ -58,5 +59,6 @@ func convertResponseToProjectDataSource(ctx context.Context, response client.Pro
5859
VercelAuthentication: project.VercelAuthentication,
5960
PasswordProtection: pp,
6061
TrustedIps: project.TrustedIps,
62+
AutoExposeSystemEnvVars: fromBoolPointer(response.AutoExposeSystemEnvVars),
6163
}, nil
6264
}

vercel/data_source_project_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestAcc_ProjectDataSource(t *testing.T) {
2828
resource.TestCheckResourceAttr("data.vercel_project.test", "vercel_authentication.deployment_type", "standard_protection"),
2929
resource.TestCheckResourceAttr("data.vercel_project.test", "password_protection.deployment_type", "standard_protection"),
3030
resource.TestCheckResourceAttr("data.vercel_project.test", "trusted_ips.addresses.#", "1"),
31+
resource.TestCheckResourceAttr("data.vercel_project.test", "automatically_expose_system_environment_variables", "true"),
3132
resource.TestCheckTypeSetElemNestedAttrs("data.vercel_project.test", "trusted_ips.addresses.*", map[string]string{
3233
"value": "1.1.1.1",
3334
"note": "notey note",
@@ -82,6 +83,7 @@ resource "vercel_project" "test" {
8283
target = ["production"]
8384
}
8485
]
86+
automatically_expose_system_environment_variables = true
8587
}
8688
8789
data "vercel_project" "test" {

vercel/resource_project.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
298298
Computed: true,
299299
Description: "If `protection_bypass_for_automation` is enabled, use this value in the `x-vercel-protection-bypass` header to bypass Vercel Authentication and Password Protection for both Preview and Production Deployments.",
300300
},
301+
"automatically_expose_system_environment_variables": schema.BoolAttribute{
302+
Optional: true,
303+
Computed: true,
304+
Description: "Vercel provides a set of Environment Variables that are automatically populated by the System, such as the URL of the Deployment or the name of the Git branch deployed. To expose them to your Deployments, enable this field",
305+
},
301306
},
302307
}
303308
}
@@ -348,7 +353,7 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest
348353
return
349354
}
350355

351-
if plan.PasswordProtection != nil || plan.VercelAuthentication != nil || plan.TrustedIps != nil {
356+
if plan.PasswordProtection != nil || plan.VercelAuthentication != nil || plan.TrustedIps != nil || !plan.AutoExposeSystemEnvVars.IsNull() {
352357
out, err = r.client.UpdateProject(ctx, result.ID.ValueString(), plan.TeamID.ValueString(), plan.toUpdateProjectRequest(plan.Name.ValueString()), !plan.Environment.IsNull())
353358
if err != nil {
354359
resp.Diagnostics.AddError(

vercel/resource_project_model.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Project struct {
3030
TrustedIps *TrustedIps `tfsdk:"trusted_ips"`
3131
ProtectionBypassForAutomation types.Bool `tfsdk:"protection_bypass_for_automation"`
3232
ProtectionBypassForAutomationSecret types.String `tfsdk:"protection_bypass_for_automation_secret"`
33+
AutoExposeSystemEnvVars types.Bool `tfsdk:"automatically_expose_system_environment_variables"`
3334
}
3435

3536
var nullProject = Project{
@@ -120,6 +121,7 @@ func (p *Project) toUpdateProjectRequest(oldName string) client.UpdateProjectReq
120121
PasswordProtection: p.PasswordProtection.toUpdateProjectRequest(),
121122
VercelAuthentication: p.VercelAuthentication.toUpdateProjectRequest(),
122123
TrustedIps: p.TrustedIps.toUpdateProjectRequest(),
124+
AutoExposeSystemEnvVars: toBoolPointer(p.AutoExposeSystemEnvVars),
123125
}
124126
}
125127

@@ -471,5 +473,6 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
471473
TrustedIps: tip,
472474
ProtectionBypassForAutomation: protectionBypass,
473475
ProtectionBypassForAutomationSecret: protectionBypassSecret,
476+
AutoExposeSystemEnvVars: fromBoolPointer(response.AutoExposeSystemEnvVars),
474477
}, nil
475478
}

vercel/resource_project_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func TestAcc_Project(t *testing.T) {
5959
resource.TestCheckResourceAttr("vercel_project.test", "root_directory", "ui/src"),
6060
resource.TestCheckResourceAttr("vercel_project.test", "ignore_command", "echo 'wat'"),
6161
resource.TestCheckResourceAttr("vercel_project.test", "serverless_function_region", "syd1"),
62+
resource.TestCheckResourceAttr("vercel_project.test", "automatically_expose_system_environment_variables", "true"),
6263
resource.TestCheckTypeSetElemNestedAttrs("vercel_project.test", "environment.*", map[string]string{
6364
"key": "foo",
6465
"value": "bar",
@@ -570,6 +571,7 @@ resource "vercel_project" "test" {
570571
output_directory = ".output"
571572
public_source = true
572573
root_directory = "ui/src"
574+
automatically_expose_system_environment_variables = true
573575
environment = [
574576
{
575577
key = "foo"

0 commit comments

Comments
 (0)