这是indexloc提供的服务,不要输入任何密码
Skip to content

Add comment field to all env vars. #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func (c *Client) ListDNSRecords(ctx context.Context, domain, teamID string) (r [
url: url,
body: "",
}, &dr)
for _, record := range dr.Records {
record.TeamID = c.teamID(teamID)
for i := 0; i < len(dr.Records); i++ {
dr.Records[i].TeamID = c.teamID(teamID)
}
return dr.Records, err
}
Expand Down
6 changes: 4 additions & 2 deletions client/environment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type EnvironmentVariableRequest struct {
Target []string `json:"target"`
GitBranch *string `json:"gitBranch,omitempty"`
Type string `json:"type"`
Comment string `json:"comment"`
}

type CreateEnvironmentVariableRequest struct {
Expand Down Expand Up @@ -78,6 +79,7 @@ type UpdateEnvironmentVariableRequest struct {
Target []string `json:"target"`
GitBranch *string `json:"gitBranch,omitempty"`
Type string `json:"type"`
Comment string `json:"comment"`
ProjectID string `json:"-"`
TeamID string `json:"-"`
EnvID string `json:"-"`
Expand Down Expand Up @@ -141,8 +143,8 @@ func (c *Client) GetEnvironmentVariables(ctx context.Context, projectID, teamID
url: url,
body: "",
}, &envResponse)
for _, env := range envResponse.Env {
env.TeamID = c.teamID(teamID)
for i := 0; i < len(envResponse.Env); i++ {
envResponse.Env[i].TeamID = c.teamID(teamID)
}
return envResponse.Env, err
}
Expand Down
5 changes: 3 additions & 2 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type EnvironmentVariable struct {
Type string `json:"type"`
ID string `json:"id,omitempty"`
TeamID string `json:"-"`
Comment string `json:"comment"`
}

type DeploymentExpiration struct {
Expand Down Expand Up @@ -257,8 +258,8 @@ func (c *Client) ListProjects(ctx context.Context, teamID string) (r []ProjectRe
url: url,
body: "",
}, &pr)
for _, p := range pr.Projects {
p.TeamID = c.teamID(teamID)
for i := 0; i < len(pr.Projects); i++ {
pr.Projects[i].TeamID = c.teamID(teamID)
}
return pr.Projects, err
}
Expand Down
11 changes: 7 additions & 4 deletions client/shared_environment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ type SharedEnvironmentVariableResponse struct {
Type string `json:"type"`
Target []string `json:"target"`
ProjectIDs []string `json:"projectId"`
Comment string `json:"comment"`
}

type SharedEnvVarRequest struct {
Key string `json:"key"`
Value string `json:"value"`
Key string `json:"key"`
Value string `json:"value"`
Comment string `json:"comment"`
}

type SharedEnvironmentVariableRequest struct {
Expand Down Expand Up @@ -126,8 +128,8 @@ func (c *Client) ListSharedEnvironmentVariables(ctx context.Context, teamID stri
url: url,
body: "",
}, &res)
for _, v := range res.Data {
v.TeamID = c.teamID(teamID)
for i := 0; i < len(res.Data); i++ {
res.Data[i].TeamID = c.teamID(teamID)
}
return res.Data, err
}
Expand All @@ -137,6 +139,7 @@ type UpdateSharedEnvironmentVariableRequest struct {
Type string `json:"type"`
ProjectIDs []string `json:"projectId"`
Target []string `json:"target"`
Comment string `json:"comment"`
TeamID string `json:"-"`
EnvID string `json:"-"`
}
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ output "project_id" {

Read-Only:

- `comment` (String) A comment explaining what the environment variable is for.
- `git_branch` (String) The git branch of the environment variable.
- `id` (String) The ID of the environment variable
- `key` (String) The name of the environment variable.
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/shared_environment_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data "vercel_shared_environment_variable" "example_by_key_and_target" {

### Read-Only

- `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.
- `value` (String, Sensitive) The value of the Environment Variable.
1 change: 1 addition & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Required:

Optional:

- `comment` (String) A comment explaining what the environment variable is for.
- `git_branch` (String) The git branch of the Environment Variable.
- `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))

Expand Down
14 changes: 9 additions & 5 deletions docs/resources/project_environment_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ resource "vercel_project_environment_variable" "example" {
key = "foo"
value = "bar"
target = ["production"]
comment = "a production secret"
}

# An environment variable that will be created
Expand All @@ -50,16 +51,18 @@ resource "vercel_project_environment_variable" "example_git_branch" {
value = "bar-staging"
target = ["preview"]
git_branch = "staging"
comment = "a staging secret"
}

# A sensitive environment variable that will be created
# for this project for the "production" environment.
resource "vercel_project_environment_variable" "example_sensitive" {
project_id = vercel_project.example.id
key = "foo"
value = "bar-production"
target = ["production"]
sensitive = true
project_id = vercel_project.example.id
key = "foo"
value = "bar-production"
target = ["production"]
sensitive = true
comment = "a sensitive production secret"
}
```

Expand All @@ -75,6 +78,7 @@ resource "vercel_project_environment_variable" "example_sensitive" {

### Optional

- `comment` (String) A comment explaining what the environment variable is for.
- `git_branch` (String) The git branch of the Environment Variable.
- `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.Required when configuring a team resource if a default team has not been set in the provider.
Expand Down
8 changes: 5 additions & 3 deletions docs/resources/shared_environment_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ resource "vercel_project" "example" {
# A shared environment variable that will be created
# and associated with the "example" project.
resource "vercel_shared_environment_variable" "example" {
key = "EXAMPLE"
value = "some_value"
target = ["production"]
key = "EXAMPLE"
value = "some_value"
target = ["production"]
comment = "an example shared variable"
project_ids = [
vercel_project.example.id
]
Expand All @@ -52,6 +53,7 @@ resource "vercel_shared_environment_variable" "example" {

### Optional

- `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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resource "vercel_project_environment_variable" "example" {
key = "foo"
value = "bar"
target = ["production"]
comment = "a production secret"
}

# An environment variable that will be created
Expand All @@ -24,14 +25,17 @@ resource "vercel_project_environment_variable" "example_git_branch" {
value = "bar-staging"
target = ["preview"]
git_branch = "staging"
comment = "a staging secret"
}

# A sensitive environment variable that will be created
# for this project for the "production" environment.
resource "vercel_project_environment_variable" "example_sensitive" {
project_id = vercel_project.example.id
key = "foo"
value = "bar-production"
target = ["production"]
sensitive = true
}
project_id = vercel_project.example.id
key = "foo"
value = "bar-production"
target = ["production"]
sensitive = true
comment = "a sensitive production secret"
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ resource "vercel_project" "example" {
# A shared environment variable that will be created
# and associated with the "example" project.
resource "vercel_shared_environment_variable" "example" {
key = "EXAMPLE"
value = "some_value"
target = ["production"]
key = "EXAMPLE"
value = "some_value"
target = ["production"]
comment = "an example shared variable"
project_ids = [
vercel_project.example.id
]
Expand Down
4 changes: 4 additions & 0 deletions vercel/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ For more detailed information, please see the [Vercel documentation](https://ver
Description: "Whether the Environment Variable is sensitive or not. Note that the value will be `null` for sensitive environment variables.",
Computed: true,
},
"comment": schema.StringAttribute{
Description: "A comment explaining what the environment variable is for.",
Computed: true,
},
},
},
},
Expand Down
11 changes: 4 additions & 7 deletions vercel/data_source_shared_environment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ For more detailed information, please see the [Vercel documentation](https://ver
Description: "Whether the Environment Variable is sensitive or not.",
Computed: true,
},
"comment": schema.StringAttribute{
Description: "A comment explaining what the environment variable is for.",
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -225,13 +229,6 @@ func (d *sharedEnvironmentVariableDataSource) Read(ctx context.Context, req data
}

result := convertResponseToSharedEnvironmentVariable(out, types.StringNull())
if err != nil {
resp.Diagnostics.AddError(
"Error converting shared environment variable response to model",
"Could not read shared environment variable, unexpected error: "+err.Error(),
)
return
}
tflog.Info(ctx, "read shared environment variable", map[string]interface{}{
"team_id": result.TeamID.ValueString(),
"project_id": result.ID.ValueString(),
Expand Down
14 changes: 14 additions & 0 deletions vercel/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
Optional: true,
Computed: true,
},
"comment": schema.StringAttribute{
Description: "A comment explaining what the environment variable is for.",
Optional: true,
Computed: true,
Validators: []validator.String{
stringLengthBetween(0, 1000),
},
},
},
},
},
Expand Down Expand Up @@ -633,6 +641,7 @@ func parseEnvironment(vars []EnvironmentItem) []client.EnvironmentVariable {
GitBranch: e.GitBranch.ValueStringPointer(),
Type: envVariableType,
ID: e.ID.ValueString(),
Comment: e.Comment.ValueString(),
})
}
return out
Expand Down Expand Up @@ -722,6 +731,7 @@ type EnvironmentItem struct {
Value types.String `tfsdk:"value"`
ID types.String `tfsdk:"id"`
Sensitive types.Bool `tfsdk:"sensitive"`
Comment types.String `tfsdk:"comment"`
}

func (e *EnvironmentItem) toEnvironmentVariableRequest() client.EnvironmentVariableRequest {
Expand All @@ -744,6 +754,7 @@ func (e *EnvironmentItem) toEnvironmentVariableRequest() client.EnvironmentVaria
Target: target,
GitBranch: e.GitBranch.ValueStringPointer(),
Type: envVariableType,
Comment: e.Comment.ValueString(),
}
}

Expand Down Expand Up @@ -996,6 +1007,7 @@ var envVariableElemType = types.ObjectType{
"git_branch": types.StringType,
"id": types.StringType,
"sensitive": types.BoolType,
"comment": types.StringType,
},
}

Expand Down Expand Up @@ -1185,6 +1197,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
"git_branch": types.StringType,
"id": types.StringType,
"sensitive": types.BoolType,
"comment": types.StringType,
},
map[string]attr.Value{
"key": types.StringValue(e.Key),
Expand All @@ -1193,6 +1206,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
"git_branch": types.StringPointerValue(e.GitBranch),
"id": types.StringValue(e.ID),
"sensitive": types.BoolValue(e.Type == "sensitive"),
"comment": types.StringValue(e.Comment),
},
))
}
Expand Down
12 changes: 12 additions & 0 deletions vercel/resource_project_environment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
Validators: []validator.Bool{},
PlanModifiers: []planmodifier.Bool{boolplanmodifier.RequiresReplace()},
},
"comment": schema.StringAttribute{
Description: "A comment explaining what the environment variable is for.",
Optional: true,
Computed: true,
Validators: []validator.String{
stringLengthBetween(0, 1000),
},
},
},
}
}
Expand All @@ -128,6 +136,7 @@ type ProjectEnvironmentVariable struct {
ProjectID types.String `tfsdk:"project_id"`
ID types.String `tfsdk:"id"`
Sensitive types.Bool `tfsdk:"sensitive"`
Comment types.String `tfsdk:"comment"`
}

func (r *projectEnvironmentVariableResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
Expand Down Expand Up @@ -193,6 +202,7 @@ func (e *ProjectEnvironmentVariable) toCreateEnvironmentVariableRequest() client
Target: target,
GitBranch: e.GitBranch.ValueStringPointer(),
Type: envVariableType,
Comment: e.Comment.ValueString(),
},
ProjectID: e.ProjectID.ValueString(),
TeamID: e.TeamID.ValueString(),
Expand Down Expand Up @@ -221,6 +231,7 @@ func (e *ProjectEnvironmentVariable) toUpdateEnvironmentVariableRequest() client
ProjectID: e.ProjectID.ValueString(),
TeamID: e.TeamID.ValueString(),
EnvID: e.ID.ValueString(),
Comment: e.Comment.ValueString(),
}
}

Expand All @@ -247,6 +258,7 @@ func convertResponseToProjectEnvironmentVariable(response client.EnvironmentVari
ProjectID: projectID,
ID: types.StringValue(response.ID),
Sensitive: types.BoolValue(response.Type == "sensitive"),
Comment: types.StringValue(response.Comment),
}
}

Expand Down
Loading
Loading