From 545a47da0e8c3c44237edca4822a041529debe28 Mon Sep 17 00:00:00 2001 From: ecklf Date: Wed, 24 Aug 2022 10:04:25 +0200 Subject: [PATCH 01/15] support individual project environment variable --- client/environment_variable_upsert.go | 7 +- client/environment_variables_get.go | 22 ++ vercel/provider.go | 11 +- vercel/resource_project.go | 4 +- .../resource_project_environment_variable.go | 231 ++++++++++++++++++ ...urce_project_environment_variable_model.go | 52 ++++ 6 files changed, 317 insertions(+), 10 deletions(-) create mode 100644 vercel/resource_project_environment_variable.go create mode 100644 vercel/resource_project_environment_variable_model.go diff --git a/client/environment_variable_upsert.go b/client/environment_variable_upsert.go index 77a028f2..1dc738f6 100644 --- a/client/environment_variable_upsert.go +++ b/client/environment_variable_upsert.go @@ -15,7 +15,7 @@ type UpsertEnvironmentVariableRequest EnvironmentVariable // UpsertEnvironmentVariable will either create a brand new environment variable if one does not exist, or will // update an existing environment variable to the latest information. -func (c *Client) UpsertEnvironmentVariable(ctx context.Context, projectID, teamID string, request UpsertEnvironmentVariableRequest) error { +func (c *Client) UpsertEnvironmentVariable(ctx context.Context, projectID, teamID string, request UpsertEnvironmentVariableRequest) (e EnvironmentVariable, err error) { url := fmt.Sprintf("%s/v8/projects/%s/env", c.baseURL, projectID) if teamID != "" { url = fmt.Sprintf("%s?teamId=%s", url, teamID) @@ -28,12 +28,13 @@ func (c *Client) UpsertEnvironmentVariable(ctx context.Context, projectID, teamI strings.NewReader(payload), ) if err != nil { - return err + return e, err } tflog.Trace(ctx, "upserting environment variable", map[string]interface{}{ "url": url, "payload": payload, }) - return c.doRequest(req, nil) + err = c.doRequest(req, &e) + return e, err } diff --git a/client/environment_variables_get.go b/client/environment_variables_get.go index c082b0ad..15809df0 100644 --- a/client/environment_variables_get.go +++ b/client/environment_variables_get.go @@ -32,3 +32,25 @@ func (c *Client) getEnvironmentVariables(ctx context.Context, projectID, teamID err = c.doRequest(req, &envResponse) return envResponse.Env, err } + +func (c *Client) GetEnvironmentVariable(ctx context.Context, projectID, teamID, envID string) (e EnvironmentVariable, err error) { + url := fmt.Sprintf("%s/v1/projects/%s/env/%s", c.baseURL, projectID, envID) + if teamID != "" { + url = fmt.Sprintf("%s&teamId=%s", url, teamID) + } + req, err := http.NewRequestWithContext( + ctx, + "GET", + url, + nil, + ) + if err != nil { + return e, err + } + + tflog.Trace(ctx, "getting environment variable", map[string]interface{}{ + "url": url, + }) + err = c.doRequest(req, &e) + return e, err +} diff --git a/vercel/provider.go b/vercel/provider.go index 3dfb3e7e..3fe6fc19 100644 --- a/vercel/provider.go +++ b/vercel/provider.go @@ -45,11 +45,12 @@ Use the navigation to the left to read about the available resources. // GetResources shows the available resources for the vercel provider func (p *vercelProvider) GetResources(_ context.Context) (map[string]provider.ResourceType, diag.Diagnostics) { return map[string]provider.ResourceType{ - "vercel_alias": resourceAliasType{}, - "vercel_deployment": resourceDeploymentType{}, - "vercel_project": resourceProjectType{}, - "vercel_project_domain": resourceProjectDomainType{}, - "vercel_dns_record": resourceDNSRecordType{}, + "vercel_alias": resourceAliasType{}, + "vercel_deployment": resourceDeploymentType{}, + "vercel_project": resourceProjectType{}, + "vercel_project_domain": resourceProjectDomainType{}, + "vercel_project_environment_variable": resourceProjectEnvironmentVariableType{}, + "vercel_dns_record": resourceDNSRecordType{}, }, nil } diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 126c21fb..c1576586 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -354,7 +354,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, }) } for _, v := range toUpsert { - err := r.p.client.UpsertEnvironmentVariable( + result, err := r.p.client.UpsertEnvironmentVariable( ctx, state.ID.Value, state.TeamID.Value, @@ -374,7 +374,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, tflog.Trace(ctx, "upserted environment variable", map[string]interface{}{ "team_id": plan.TeamID.Value, "project_id": plan.ID.Value, - "environment_id": v.ID.Value, + "environment_id": result.ID, }) } diff --git a/vercel/resource_project_environment_variable.go b/vercel/resource_project_environment_variable.go new file mode 100644 index 00000000..037a939c --- /dev/null +++ b/vercel/resource_project_environment_variable.go @@ -0,0 +1,231 @@ +package vercel + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/vercel/terraform-provider-vercel/client" +) + +type resourceProjectEnvironmentVariableType struct{} + +// GetSchema returns the schema information for a project environment variable resource. +func (r resourceProjectEnvironmentVariableType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { + return tfsdk.Schema{ + Description: ` +Provides a Project environment variable resource. + +A Project environment variable resource defines an environment variable on a Vercel Project. + +For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables).`, + Attributes: map[string]tfsdk.Attribute{ + "target": { + Required: true, + Description: "The environments that the environment variable should be present on. Valid targets are either `production`, `preview`, or `development`.", + Type: types.SetType{ + ElemType: types.StringType, + }, + }, + "key": { + Required: true, + PlanModifiers: tfsdk.AttributePlanModifiers{resource.RequiresReplace()}, + Description: "The name of the environment variable.", + Type: types.StringType, + }, + "value": { + Required: true, + Description: "The value of the environment variable.", + Type: types.StringType, + }, + "git_branch": { + Optional: true, + Description: "The git branch of the environment variable.", + Type: types.StringType, + }, + "project_id": { + Required: true, + Description: "The ID of the Vercel project.", + PlanModifiers: tfsdk.AttributePlanModifiers{resource.RequiresReplace()}, + Type: types.StringType, + }, + "team_id": { + Optional: true, + Description: "The ID of the Vercel team.", + PlanModifiers: tfsdk.AttributePlanModifiers{resource.RequiresReplace()}, + Type: types.StringType, + }, + "id": { + Description: "The ID of the environment variable.", + Type: types.StringType, + PlanModifiers: tfsdk.AttributePlanModifiers{resource.UseStateForUnknown()}, + Computed: true, + }, + }, + }, nil +} + +// NewResource instantiates a new Resource of this ResourceType. +func (r resourceProjectEnvironmentVariableType) NewResource(_ context.Context, p provider.Provider) (resource.Resource, diag.Diagnostics) { + return resourceProjectEnvironmentVariable{ + p: *(p.(*vercelProvider)), + }, nil +} + +type resourceProjectEnvironmentVariable struct { + p vercelProvider +} + +// Create will create a new project environment variable for a Vercel project. +// This is called automatically by the provider when a new resource should be created. +func (r resourceProjectEnvironmentVariable) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + if !r.p.configured { + resp.Diagnostics.AddError( + "Provider not configured", + "The provider hasn't been configured before apply. This leads to weird stuff happening, so we'd prefer if you didn't do that. Thanks!", + ) + return + } + + var plan ProjectEnvironmentVariable + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + response, err := r.p.client.UpsertEnvironmentVariable(ctx, plan.ProjectID.Value, plan.TeamID.Value, plan.toUpsertEnvironmentVariableRequest()) + if err != nil { + resp.Diagnostics.AddError( + "Error creating project environment variable", + "Could not create project environment variable, unexpected error: "+err.Error(), + ) + return + } + + result := convertResponseToProjectEnvironmentVariable(response, plan) + + tflog.Trace(ctx, "created project environment variable", map[string]interface{}{ + "id": result.ID.Value, + "team_id": result.TeamID.Value, + "project_id": result.ProjectID.Value, + }) + + diags = resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +// Read will read an environment variable of a Vercel project by requesting it from the Vercel API, and will update terraform +// with this information. +func (r resourceProjectEnvironmentVariable) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state ProjectEnvironmentVariable + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + out, err := r.p.client.GetEnvironmentVariable(ctx, state.ProjectID.Value, state.TeamID.Value, state.ID.Value) + if client.NotFound(err) { + resp.State.RemoveResource(ctx) + return + } + if err != nil { + resp.Diagnostics.AddError( + "Error reading project environment variable", + fmt.Sprintf("Could not get project environment variable %s %s %s, unexpected error: %s", + state.ID.Value, + state.ProjectID.Value, + state.TeamID.Value, + err, + ), + ) + return + } + + result := convertResponseToProjectEnvironmentVariable(out, state) + tflog.Trace(ctx, "read project environment variable", map[string]interface{}{ + "id": result.ID.Value, + "team_id": result.TeamID.Value, + "project_id": result.ProjectID.Value, + }) + + diags = resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +// Update updates the project environment variable of a Vercel project state. +func (r resourceProjectEnvironmentVariable) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan ProjectEnvironmentVariable + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + response, err := r.p.client.UpsertEnvironmentVariable(ctx, plan.ProjectID.Value, plan.TeamID.Value, plan.toUpsertEnvironmentVariableRequest()) + if err != nil { + resp.Diagnostics.AddError( + "Error updating project environment variable", + "Could not update project environment variable, unexpected error: "+err.Error(), + ) + return + } + + result := convertResponseToProjectEnvironmentVariable(response, plan) + + tflog.Trace(ctx, "updated project environment variable", map[string]interface{}{ + "id": result.ID.Value, + "team_id": result.TeamID.Value, + "project_id": result.ProjectID.Value, + }) + + diags = resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +// Delete deletes a Vercel project environment variable. +func (r resourceProjectEnvironmentVariable) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state ProjectEnvironmentVariable + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + err := r.p.client.DeleteEnvironmentVariable(ctx, state.ProjectID.Value, state.TeamID.Value, state.ID.Value) + if client.NotFound(err) { + return + } + if err != nil { + resp.Diagnostics.AddError( + "Error deleting project environment variable", + fmt.Sprintf( + "Could not delete project environment variable %s, unexpected error: %s", + state.ID.Value, + err, + ), + ) + return + } + + tflog.Trace(ctx, "deleted project environment variable", map[string]interface{}{ + "id": state.ID.Value, + "team_id": state.TeamID.Value, + "project_id": state.ProjectID.Value, + }) +} diff --git a/vercel/resource_project_environment_variable_model.go b/vercel/resource_project_environment_variable_model.go new file mode 100644 index 00000000..57e0d9d1 --- /dev/null +++ b/vercel/resource_project_environment_variable_model.go @@ -0,0 +1,52 @@ +package vercel + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/vercel/terraform-provider-vercel/client" +) + +// ProjectEnvironmentVariable reflects the state terraform stores internally for a project environment variable. +type ProjectEnvironmentVariable struct { + Target []types.String `tfsdk:"target"` + GitBranch types.String `tfsdk:"git_branch"` + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` + TeamID types.String `tfsdk:"team_id"` + ProjectID types.String `tfsdk:"project_id"` + ID types.String `tfsdk:"id"` +} + +func (e *ProjectEnvironmentVariable) toUpsertEnvironmentVariableRequest() client.UpsertEnvironmentVariableRequest { + var target []string + for _, t := range e.Target { + target = append(target, t.Value) + } + return client.UpsertEnvironmentVariableRequest{ + Key: e.Key.Value, + Value: e.Value.Value, + Target: target, + GitBranch: toStrPointer(e.GitBranch), + Type: "encrypted", + ID: e.ID.Value, + } +} + +// convertResponseToProjectEnvironmentVariable is used to populate terraform state based on an API response. +// Where possible, values from the API response are used to populate state. If not possible, +// values from plan are used. +func convertResponseToProjectEnvironmentVariable(response client.EnvironmentVariable, plan ProjectEnvironmentVariable) ProjectEnvironmentVariable { + target := []types.String{} + for _, t := range response.Target { + target = append(target, types.String{Value: t}) + } + + return ProjectEnvironmentVariable{ + Target: target, + GitBranch: fromStringPointer(response.GitBranch), + Key: types.String{Value: response.Key}, + Value: types.String{Value: response.Value}, + TeamID: plan.TeamID, + ProjectID: plan.ProjectID, + ID: types.String{Value: response.ID}, + } +} From f948cf0a1ac658b3bcd324f01c248f00743430e5 Mon Sep 17 00:00:00 2001 From: Darpan Kakadia Date: Wed, 24 Aug 2022 16:47:37 +0200 Subject: [PATCH 02/15] [examples] project environment variable --- .../resource.tf | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/resources/vercel_project_environment_variable/resource.tf diff --git a/examples/resources/vercel_project_environment_variable/resource.tf b/examples/resources/vercel_project_environment_variable/resource.tf new file mode 100644 index 00000000..bb85fa1d --- /dev/null +++ b/examples/resources/vercel_project_environment_variable/resource.tf @@ -0,0 +1,27 @@ +resource "vercel_project" "example" { + name = "example-project" + + git_repository = { + type = "github" + repo = "vercel/some-repo" + } +} + +# An environment variable that will be created +# for this project for the "production" environment. +resource "vercel_project_environment_variable" "example" { + project_id = vercel_project.example.id + key = "foo" + value = "bar" + target = ["production"] +} + +# An environment variable that will be created +# for this project for the "preview" environment when the branch is "staging". +resource "vercel_project_environment_variable" "example_git_branch" { + project_id = vercel_project.example.id + key = "foo" + value = "bar-staging" + target = ["preview"] + git_branch = "staging" +} From 7f063f3084ffe7ca18d408eb91a16fb5b5370ea4 Mon Sep 17 00:00:00 2001 From: Douglas Parsons Date: Wed, 24 Aug 2022 16:57:40 +0100 Subject: [PATCH 03/15] Add conversion to crazy tfsdk types --- client/deployment_create.go | 2 +- client/environment_variable_upsert.go | 1 + client/project_get.go | 18 ++-- vercel/data_source_project.go | 4 +- vercel/resource_deployment.go | 2 +- vercel/resource_project.go | 47 ++++++-- vercel/resource_project_domain.go | 2 +- .../resource_project_environment_variable.go | 11 ++ vercel/resource_project_model.go | 102 +++++++++++++----- 9 files changed, 142 insertions(+), 47 deletions(-) diff --git a/client/deployment_create.go b/client/deployment_create.go index 143e913b..ad749e56 100644 --- a/client/deployment_create.go +++ b/client/deployment_create.go @@ -150,7 +150,7 @@ func (e MissingFilesError) Error() string { } func (c *Client) getGitSource(ctx context.Context, projectID, ref, teamID string) (gs gitSource, err error) { - project, err := c.GetProject(ctx, projectID, teamID) + project, err := c.GetProject(ctx, projectID, teamID, false) if err != nil { return gs, fmt.Errorf("error getting project: %w", err) } diff --git a/client/environment_variable_upsert.go b/client/environment_variable_upsert.go index 1dc738f6..27d27232 100644 --- a/client/environment_variable_upsert.go +++ b/client/environment_variable_upsert.go @@ -36,5 +36,6 @@ func (c *Client) UpsertEnvironmentVariable(ctx context.Context, projectID, teamI "payload": payload, }) err = c.doRequest(req, &e) + e.Value = request.Value return e, err } diff --git a/client/project_get.go b/client/project_get.go index 5e08c7f1..f9791a86 100644 --- a/client/project_get.go +++ b/client/project_get.go @@ -70,7 +70,7 @@ type ProjectResponse struct { } // GetProject retrieves information about an existing project from Vercel. -func (c *Client) GetProject(ctx context.Context, projectID, teamID string) (r ProjectResponse, err error) { +func (c *Client) GetProject(ctx context.Context, projectID, teamID string, shouldFetchEnvironment bool) (r ProjectResponse, err error) { url := fmt.Sprintf("%s/v8/projects/%s", c.baseURL, projectID) if teamID != "" { url = fmt.Sprintf("%s?teamId=%s", url, teamID) @@ -85,17 +85,23 @@ func (c *Client) GetProject(ctx context.Context, projectID, teamID string) (r Pr return r, err } tflog.Trace(ctx, "getting project", map[string]interface{}{ - "url": url, + "url": url, + "shouldFetchEnvironment": shouldFetchEnvironment, }) err = c.doRequest(req, &r) if err != nil { return r, err } - env, err := c.getEnvironmentVariables(ctx, projectID, teamID) - if err != nil { - return r, fmt.Errorf("error getting environment variables for project: %w", err) + if shouldFetchEnvironment { + r.EnvironmentVariables, err = c.getEnvironmentVariables(ctx, projectID, teamID) + if err != nil { + return r, fmt.Errorf("error getting environment variables for project: %w", err) + } + } else { + // The get project endpoint returns environment variables, but returns them fully + // encrypted. This isn't useful, so we just remove them. + r.EnvironmentVariables = nil } - r.EnvironmentVariables = env return r, err } diff --git a/vercel/data_source_project.go b/vercel/data_source_project.go index 2c8a1f1a..42831f9f 100644 --- a/vercel/data_source_project.go +++ b/vercel/data_source_project.go @@ -170,7 +170,7 @@ func (r dataSourceProject) Read(ctx context.Context, req datasource.ReadRequest, return } - out, err := r.p.client.GetProject(ctx, config.Name.Value, config.TeamID.Value) + out, err := r.p.client.GetProject(ctx, config.Name.Value, config.TeamID.Value, true) if err != nil { resp.Diagnostics.AddError( "Error reading project", @@ -183,7 +183,7 @@ func (r dataSourceProject) Read(ctx context.Context, req datasource.ReadRequest, return } - result := convertResponseToProject(out, config.coercedFields()) + result := convertResponseToProject(out, config.coercedFields(), types.Set{Null: true}) tflog.Trace(ctx, "read project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, diff --git a/vercel/resource_deployment.go b/vercel/resource_deployment.go index 6c1f44af..bf7391ae 100644 --- a/vercel/resource_deployment.go +++ b/vercel/resource_deployment.go @@ -246,7 +246,7 @@ func (r resourceDeployment) Create(ctx context.Context, req resource.CreateReque Ref: plan.Ref.Value, } - _, err = r.p.client.GetProject(ctx, plan.ProjectID.Value, plan.TeamID.Value) + _, err = r.p.client.GetProject(ctx, plan.ProjectID.Value, plan.TeamID.Value, false) var apiErr client.APIError if err != nil && errors.As(err, &apiErr) && apiErr.StatusCode == 404 { resp.Diagnostics.AddError( diff --git a/vercel/resource_project.go b/vercel/resource_project.go index c1576586..c55ea75c 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -214,7 +214,16 @@ func (r resourceProject) Create(ctx context.Context, req resource.CreateRequest, return } - out, err := r.p.client.CreateProject(ctx, plan.TeamID.Value, plan.toCreateProjectRequest()) + environment, err := plan.environment(ctx) + if err != nil { + resp.Diagnostics.AddError( + "Error parsing project environment variables", + "Could not read environment variables, unexpected error: "+err.Error(), + ) + return + } + + out, err := r.p.client.CreateProject(ctx, plan.TeamID.Value, plan.toCreateProjectRequest(environment)) if err != nil { resp.Diagnostics.AddError( "Error creating project", @@ -223,7 +232,7 @@ func (r resourceProject) Create(ctx context.Context, req resource.CreateRequest, return } - result := convertResponseToProject(out, plan.coercedFields()) + result := convertResponseToProject(out, plan.coercedFields(), plan.Environment) tflog.Trace(ctx, "created project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, @@ -246,7 +255,7 @@ func (r resourceProject) Read(ctx context.Context, req resource.ReadRequest, res return } - out, err := r.p.client.GetProject(ctx, state.ID.Value, state.TeamID.Value) + out, err := r.p.client.GetProject(ctx, state.ID.Value, state.TeamID.Value, !state.Environment.Null) if client.NotFound(err) { resp.State.RemoveResource(ctx) return @@ -263,7 +272,7 @@ func (r resourceProject) Read(ctx context.Context, req resource.ReadRequest, res return } - result := convertResponseToProject(out, state.coercedFields()) + result := convertResponseToProject(out, state.coercedFields(), state.Environment) tflog.Trace(ctx, "read project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, @@ -332,7 +341,29 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, } /* Update the environment variables first */ - toUpsert, toRemove := diffEnvVars(state.Environment, plan.Environment) + planEnvs, err := plan.environment(ctx) + if err != nil { + resp.Diagnostics.AddError( + "Error parsing project environment variables", + "Could not read environment variables, unexpected error: "+err.Error(), + ) + return + } + stateEnvs, err := state.environment(ctx) + if err != nil { + resp.Diagnostics.AddError( + "Error parsing project environment variables from state", + "Could not read environment variables, unexpected error: "+err.Error(), + ) + return + } + + tflog.Error(ctx, "planEnvs", map[string]interface{}{ + "plan_envs": planEnvs, + "state_envs": stateEnvs, + }) + + toUpsert, toRemove := diffEnvVars(stateEnvs, planEnvs) for _, v := range toRemove { err := r.p.client.DeleteEnvironmentVariable(ctx, state.ID.Value, state.TeamID.Value, v.ID.Value) if err != nil { @@ -392,7 +423,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, return } - result := convertResponseToProject(out, plan.coercedFields()) + result := convertResponseToProject(out, plan.coercedFields(), plan.Environment) tflog.Trace(ctx, "updated project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, @@ -463,7 +494,7 @@ func (r resourceProject) ImportState(ctx context.Context, req resource.ImportSta ) } - out, err := r.p.client.GetProject(ctx, projectID, teamID) + out, err := r.p.client.GetProject(ctx, projectID, teamID, true) if err != nil { resp.Diagnostics.AddError( "Error reading project", @@ -484,7 +515,7 @@ func (r resourceProject) ImportState(ctx context.Context, req resource.ImportSta OutputDirectory: types.String{Null: true}, PublicSource: types.Bool{Null: true}, TeamID: types.String{Value: teamID, Null: teamID == ""}, - }) + }, types.Set{Null: true}) tflog.Trace(ctx, "imported project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, diff --git a/vercel/resource_project_domain.go b/vercel/resource_project_domain.go index 4a4cd5af..042d14b4 100644 --- a/vercel/resource_project_domain.go +++ b/vercel/resource_project_domain.go @@ -101,7 +101,7 @@ func (r resourceProjectDomain) Create(ctx context.Context, req resource.CreateRe return } - _, err := r.p.client.GetProject(ctx, plan.ProjectID.Value, plan.TeamID.Value) + _, err := r.p.client.GetProject(ctx, plan.ProjectID.Value, plan.TeamID.Value, false) var apiErr client.APIError if err != nil && errors.As(err, &apiErr) && apiErr.StatusCode == 404 { resp.Diagnostics.AddError( diff --git a/vercel/resource_project_environment_variable.go b/vercel/resource_project_environment_variable.go index 037a939c..b7ae82bf 100644 --- a/vercel/resource_project_environment_variable.go +++ b/vercel/resource_project_environment_variable.go @@ -2,6 +2,7 @@ package vercel import ( "context" + "errors" "fmt" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -99,6 +100,16 @@ func (r resourceProjectEnvironmentVariable) Create(ctx context.Context, req reso return } + _, err := r.p.client.GetProject(ctx, plan.ProjectID.Value, plan.TeamID.Value, false) + var apiErr client.APIError + if err != nil && errors.As(err, &apiErr) && apiErr.StatusCode == 404 { + resp.Diagnostics.AddError( + "Error creating project environment variable", + "Could not find project, please make sure both the project_id and team_id match the project and team you wish to deploy to.", + ) + return + } + response, err := r.p.client.UpsertEnvironmentVariable(ctx, plan.ProjectID.Value, plan.TeamID.Value, plan.toUpsertEnvironmentVariableRequest()) if err != nil { resp.Diagnostics.AddError( diff --git a/vercel/resource_project_model.go b/vercel/resource_project_model.go index 319beb60..8875f0f5 100644 --- a/vercel/resource_project_model.go +++ b/vercel/resource_project_model.go @@ -1,26 +1,43 @@ package vercel import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/vercel/terraform-provider-vercel/client" ) // Project reflects the state terraform stores internally for a project. type Project struct { - BuildCommand types.String `tfsdk:"build_command"` - DevCommand types.String `tfsdk:"dev_command"` - Environment []EnvironmentItem `tfsdk:"environment"` - Framework types.String `tfsdk:"framework"` - GitRepository *GitRepository `tfsdk:"git_repository"` - ID types.String `tfsdk:"id"` - IgnoreCommand types.String `tfsdk:"ignore_command"` - InstallCommand types.String `tfsdk:"install_command"` - Name types.String `tfsdk:"name"` - OutputDirectory types.String `tfsdk:"output_directory"` - PublicSource types.Bool `tfsdk:"public_source"` - RootDirectory types.String `tfsdk:"root_directory"` - ServerlessFunctionRegion types.String `tfsdk:"serverless_function_region"` - TeamID types.String `tfsdk:"team_id"` + BuildCommand types.String `tfsdk:"build_command"` + DevCommand types.String `tfsdk:"dev_command"` + Environment types.Set `tfsdk:"environment"` + Framework types.String `tfsdk:"framework"` + GitRepository *GitRepository `tfsdk:"git_repository"` + ID types.String `tfsdk:"id"` + IgnoreCommand types.String `tfsdk:"ignore_command"` + InstallCommand types.String `tfsdk:"install_command"` + Name types.String `tfsdk:"name"` + OutputDirectory types.String `tfsdk:"output_directory"` + PublicSource types.Bool `tfsdk:"public_source"` + RootDirectory types.String `tfsdk:"root_directory"` + ServerlessFunctionRegion types.String `tfsdk:"serverless_function_region"` + TeamID types.String `tfsdk:"team_id"` +} + +func (p *Project) environment(ctx context.Context) ([]EnvironmentItem, error) { + if p.Environment.Null { + return nil, nil + } + + var vars []EnvironmentItem + err := p.Environment.ElementsAs(ctx, &vars, true) + if err != nil { + return nil, fmt.Errorf("error reading project environment variables: %s", err) + } + return vars, nil } func parseEnvironment(vars []EnvironmentItem) []client.EnvironmentVariable { @@ -43,12 +60,12 @@ func parseEnvironment(vars []EnvironmentItem) []client.EnvironmentVariable { return out } -func (p *Project) toCreateProjectRequest() client.CreateProjectRequest { +func (p *Project) toCreateProjectRequest(envs []EnvironmentItem) client.CreateProjectRequest { return client.CreateProjectRequest{ BuildCommand: toStrPointer(p.BuildCommand), CommandForIgnoringBuildStep: toStrPointer(p.IgnoreCommand), DevCommand: toStrPointer(p.DevCommand), - EnvironmentVariables: parseEnvironment(p.Environment), + EnvironmentVariables: parseEnvironment(envs), Framework: toStrPointer(p.Framework), GitRepository: p.GitRepository.toCreateProjectRequest(), InstallCommand: toStrPointer(p.InstallCommand), @@ -167,7 +184,7 @@ func uncoerceBool(plan, res types.Bool) types.Bool { return res } -func convertResponseToProject(response client.ProjectResponse, fields projectCoercedFields) Project { +func convertResponseToProject(response client.ProjectResponse, fields projectCoercedFields, environment types.Set) Project { var gr *GitRepository if repo := response.Repository(); repo != nil { gr = &GitRepository{ @@ -175,25 +192,54 @@ func convertResponseToProject(response client.ProjectResponse, fields projectCoe Repo: types.String{Value: repo.Repo}, } } - var env []EnvironmentItem + + var env []attr.Value for _, e := range response.EnvironmentVariables { - target := []types.String{} + target := []attr.Value{} for _, t := range e.Target { target = append(target, types.String{Value: t}) } - env = append(env, EnvironmentItem{ - Key: types.String{Value: e.Key}, - Value: types.String{Value: e.Value}, - Target: target, - GitBranch: fromStringPointer(e.GitBranch), - ID: types.String{Value: e.ID}, + env = append(env, types.Object{ + Attrs: map[string]attr.Value{ + "key": types.String{Value: e.Key}, + "value": types.String{Value: e.Value}, + "target": types.Set{ + Elems: target, + ElemType: types.StringType, + }, + "git_branch": fromStringPointer(e.GitBranch), + "id": types.String{Value: e.ID}, + }, + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + "target": types.SetType{ + ElemType: types.StringType, + }, + "git_branch": types.StringType, + "id": types.StringType, + }, }) } return Project{ - BuildCommand: uncoerceString(fields.BuildCommand, fromStringPointer(response.BuildCommand)), - DevCommand: uncoerceString(fields.DevCommand, fromStringPointer(response.DevCommand)), - Environment: env, + BuildCommand: uncoerceString(fields.BuildCommand, fromStringPointer(response.BuildCommand)), + DevCommand: uncoerceString(fields.DevCommand, fromStringPointer(response.DevCommand)), + Environment: types.Set{ + Null: len(response.EnvironmentVariables) == 0 && environment.Null, + Elems: env, + ElemType: types.ObjectType{ + AttrTypes: map[string]attr.Type{ + "key": types.StringType, + "value": types.StringType, + "target": types.SetType{ + ElemType: types.StringType, + }, + "git_branch": types.StringType, + "id": types.StringType, + }, + }, + }, Framework: fromStringPointer(response.Framework), GitRepository: gr, ID: types.String{Value: response.ID}, From e06aa9926886cd8254b1fbd14417810a94d4498b Mon Sep 17 00:00:00 2001 From: Darpan Kakadia Date: Thu, 25 Aug 2022 12:05:57 +0200 Subject: [PATCH 04/15] [client] create & update env variable --- client/environment_variable_create.go | 49 ++++++++++++++++++++++++++ client/environment_variable_update.go | 50 +++++++++++++++++++++++++++ client/environment_variable_upsert.go | 41 ---------------------- 3 files changed, 99 insertions(+), 41 deletions(-) create mode 100644 client/environment_variable_create.go create mode 100644 client/environment_variable_update.go delete mode 100644 client/environment_variable_upsert.go diff --git a/client/environment_variable_create.go b/client/environment_variable_create.go new file mode 100644 index 00000000..0ad9f216 --- /dev/null +++ b/client/environment_variable_create.go @@ -0,0 +1,49 @@ +package client + +import ( + "context" + "fmt" + "net/http" + "strings" + + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// CreateEnvironmentVariableRequest defines the information that needs to be passed to Vercel in order to +// create an environment variable. +type CreateEnvironmentVariableRequest struct { + Key string `json:"key"` + Value string `json:"value"` + Target []string `json:"target"` + GitBranch *string `json:"gitBranch,omitempty"` + Type string `json:"type"` + ProjectID string `json:"-"` + TeamID string `json:"-"` +} + +// CreateEnvironmentVariable will create a brand new environment variable if one does not exist. +func (c *Client) CreateEnvironmentVariable(ctx context.Context, request CreateEnvironmentVariableRequest) (e EnvironmentVariable, err error) { + url := fmt.Sprintf("%s/v9/projects/%s/env", c.baseURL, request.ProjectID) + if request.TeamID != "" { + url = fmt.Sprintf("%s?teamId=%s", url, request.TeamID) + } + payload := string(mustMarshal(request)) + req, err := http.NewRequestWithContext( + ctx, + "POST", + url, + strings.NewReader(payload), + ) + if err != nil { + return e, err + } + + tflog.Trace(ctx, "creating environment variable", map[string]interface{}{ + "url": url, + "payload": payload, + }) + err = c.doRequest(req, &e) + // The API response returns an encrypted environment variable, but we want to return the decrypted version. + e.Value = request.Value + return e, err +} diff --git a/client/environment_variable_update.go b/client/environment_variable_update.go new file mode 100644 index 00000000..aeac3004 --- /dev/null +++ b/client/environment_variable_update.go @@ -0,0 +1,50 @@ +package client + +import ( + "context" + "fmt" + "net/http" + "strings" + + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// UpdateEnvironmentVariableRequest defines the information that needs to be passed to Vercel in order to +// update an environment variable. +type UpdateEnvironmentVariableRequest struct { + Key string `json:"key"` + Value string `json:"value"` + Target []string `json:"target"` + GitBranch *string `json:"gitBranch,omitempty"` + Type string `json:"type"` + ProjectID string `json:"-"` + TeamID string `json:"-"` + EnvID string `json:"-"` +} + +// UpdateEnvironmentVariable will update an existing environment variable to the latest information. +func (c *Client) UpdateEnvironmentVariable(ctx context.Context, request UpdateEnvironmentVariableRequest) (e EnvironmentVariable, err error) { + url := fmt.Sprintf("%s/v9/projects/%s/env/%s", c.baseURL, request.ProjectID, request.EnvID) + if request.TeamID != "" { + url = fmt.Sprintf("%s?teamId=%s", url, request.TeamID) + } + payload := string(mustMarshal(request)) + req, err := http.NewRequestWithContext( + ctx, + "PATCH", + url, + strings.NewReader(payload), + ) + if err != nil { + return e, err + } + + tflog.Trace(ctx, "updating environment variable", map[string]interface{}{ + "url": url, + "payload": payload, + }) + err = c.doRequest(req, &e) + // The API response returns an encrypted environment variable, but we want to return the decrypted version. + e.Value = request.Value + return e, err +} diff --git a/client/environment_variable_upsert.go b/client/environment_variable_upsert.go deleted file mode 100644 index 27d27232..00000000 --- a/client/environment_variable_upsert.go +++ /dev/null @@ -1,41 +0,0 @@ -package client - -import ( - "context" - "fmt" - "net/http" - "strings" - - "github.com/hashicorp/terraform-plugin-log/tflog" -) - -// UpsertEnvironmentVariableRequest defines the information that needs to be passed to Vercel in order to -// create or update an environment variable. -type UpsertEnvironmentVariableRequest EnvironmentVariable - -// UpsertEnvironmentVariable will either create a brand new environment variable if one does not exist, or will -// update an existing environment variable to the latest information. -func (c *Client) UpsertEnvironmentVariable(ctx context.Context, projectID, teamID string, request UpsertEnvironmentVariableRequest) (e EnvironmentVariable, err error) { - url := fmt.Sprintf("%s/v8/projects/%s/env", c.baseURL, projectID) - if teamID != "" { - url = fmt.Sprintf("%s?teamId=%s", url, teamID) - } - payload := string(mustMarshal(request)) - req, err := http.NewRequestWithContext( - ctx, - "POST", - url, - strings.NewReader(payload), - ) - if err != nil { - return e, err - } - - tflog.Trace(ctx, "upserting environment variable", map[string]interface{}{ - "url": url, - "payload": payload, - }) - err = c.doRequest(req, &e) - e.Value = request.Value - return e, err -} From cf0a1cdee29280f294d1fdc79d46ed61b32fd106 Mon Sep 17 00:00:00 2001 From: Darpan Kakadia Date: Thu, 25 Aug 2022 12:07:04 +0200 Subject: [PATCH 05/15] [resource_project_environment_variable] tests and fixes --- .../resource_project_environment_variable.go | 4 +- ...urce_project_environment_variable_model.go | 24 ++- ...ource_project_environment_variable_test.go | 160 ++++++++++++++++++ 3 files changed, 183 insertions(+), 5 deletions(-) create mode 100644 vercel/resource_project_environment_variable_test.go diff --git a/vercel/resource_project_environment_variable.go b/vercel/resource_project_environment_variable.go index b7ae82bf..11daa977 100644 --- a/vercel/resource_project_environment_variable.go +++ b/vercel/resource_project_environment_variable.go @@ -110,7 +110,7 @@ func (r resourceProjectEnvironmentVariable) Create(ctx context.Context, req reso return } - response, err := r.p.client.UpsertEnvironmentVariable(ctx, plan.ProjectID.Value, plan.TeamID.Value, plan.toUpsertEnvironmentVariableRequest()) + response, err := r.p.client.CreateEnvironmentVariable(ctx, plan.toCreateEnvironmentVariableRequest()) if err != nil { resp.Diagnostics.AddError( "Error creating project environment variable", @@ -185,7 +185,7 @@ func (r resourceProjectEnvironmentVariable) Update(ctx context.Context, req reso return } - response, err := r.p.client.UpsertEnvironmentVariable(ctx, plan.ProjectID.Value, plan.TeamID.Value, plan.toUpsertEnvironmentVariableRequest()) + response, err := r.p.client.UpdateEnvironmentVariable(ctx, plan.toUpdateEnvironmentVariableRequest()) if err != nil { resp.Diagnostics.AddError( "Error updating project environment variable", diff --git a/vercel/resource_project_environment_variable_model.go b/vercel/resource_project_environment_variable_model.go index 57e0d9d1..fa2deb60 100644 --- a/vercel/resource_project_environment_variable_model.go +++ b/vercel/resource_project_environment_variable_model.go @@ -16,18 +16,36 @@ type ProjectEnvironmentVariable struct { ID types.String `tfsdk:"id"` } -func (e *ProjectEnvironmentVariable) toUpsertEnvironmentVariableRequest() client.UpsertEnvironmentVariableRequest { +func (e *ProjectEnvironmentVariable) toCreateEnvironmentVariableRequest() client.CreateEnvironmentVariableRequest { var target []string for _, t := range e.Target { target = append(target, t.Value) } - return client.UpsertEnvironmentVariableRequest{ + return client.CreateEnvironmentVariableRequest{ Key: e.Key.Value, Value: e.Value.Value, Target: target, GitBranch: toStrPointer(e.GitBranch), Type: "encrypted", - ID: e.ID.Value, + ProjectID: e.ProjectID.Value, + TeamID: e.TeamID.Value, + } +} + +func (e *ProjectEnvironmentVariable) toUpdateEnvironmentVariableRequest() client.UpdateEnvironmentVariableRequest { + var target []string + for _, t := range e.Target { + target = append(target, t.Value) + } + return client.UpdateEnvironmentVariableRequest{ + Key: e.Key.Value, + Value: e.Value.Value, + Target: target, + GitBranch: toStrPointer(e.GitBranch), + Type: "encrypted", + ProjectID: e.ProjectID.Value, + TeamID: e.TeamID.Value, + EnvID: e.ID.Value, } } diff --git a/vercel/resource_project_environment_variable_test.go b/vercel/resource_project_environment_variable_test.go new file mode 100644 index 00000000..90437deb --- /dev/null +++ b/vercel/resource_project_environment_variable_test.go @@ -0,0 +1,160 @@ +package vercel_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +// func testAccDNSRecordDestroy1(n, teamID string) resource.TestCheckFunc { +// return func(s *terraform.State) error { +// rs, ok := s.RootModule().Resources[n] +// if !ok { +// return fmt.Errorf("not found: %s", n) +// } + +// if rs.Primary.ID == "" { +// return fmt.Errorf("no ID is set") +// } + +// _, err := testClient().GetDNSRecord(context.TODO(), rs.Primary.ID, teamID) + +// var apiErr client.APIError +// if err == nil { +// return fmt.Errorf("Found project but expected it to have been deleted") +// } +// if err != nil && errors.As(err, &apiErr) { +// if apiErr.StatusCode == 404 { +// return nil +// } +// return fmt.Errorf("Unexpected error checking for deleted project: %s", apiErr) +// } + +// return err +// } +// } + +func testAccProjectEnvironmentVariableExists(n, teamID string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("no ID is set") + } + + _, err := testClient().GetEnvironmentVariable(context.TODO(), rs.Primary.Attributes["project_id"], teamID, rs.Primary.ID) + return err + } +} + +func TestAcc_ProjectEnvironmentVariables(t *testing.T) { + nameSuffix := acctest.RandString(16) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + CheckDestroy: resource.ComposeAggregateTestCheckFunc( + ), + Steps: []resource.TestStep{ + { + Config: testAccProjectEnvironmentVariablesConfig(nameSuffix), + Check: resource.ComposeAggregateTestCheckFunc( + testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example", testTeam()), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "key", "foo"), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "value", "bar"), + resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example", "target.*", "production"), + + testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example_git_branch", testTeam()), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "key", "foo"), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "value", "bar-staging"), + resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_git_branch", "target.*", "preview"), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "bla"), + ), + }, + { + Config: testAccProjectEnvironmentVariablesConfigUpdated(nameSuffix), + Check: resource.ComposeAggregateTestCheckFunc( + testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example", testTeam()), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "key", "foo"), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "value", "bar-new"), + resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example", "target.*", "production"), + resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example", "target.*", "preview"), + + testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example_git_branch", testTeam()), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "key", "foo"), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "value", "bar-staging"), + resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_git_branch", "target.*", "preview"), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "test-pr"), + ), + }, + }, + }) +} + +func testAccProjectEnvironmentVariablesConfig(projectName string) string { + return fmt.Sprintf(` + resource "vercel_project" "example" { + name = "test-acc-example-project-%[1]s" + %[3]s + + git_repository = { + type = "github" + repo = "%[2]s" + } + } + + resource "vercel_project_environment_variable" "example" { + project_id = vercel_project.example.id + %[3]s + key = "foo" + value = "bar" + target = ["production"] + } + + resource "vercel_project_environment_variable" "example_git_branch" { + project_id = vercel_project.example.id + %[3]s + key = "foo" + value = "bar-staging" + target = ["preview"] + git_branch = "bla" + } +`, projectName, testGithubRepo(), teamIDConfig()) +} + +func testAccProjectEnvironmentVariablesConfigUpdated(projectName string) string { + return fmt.Sprintf(` + resource "vercel_project" "example" { + name = "test-acc-example-project-%[1]s" + %[3]s + + git_repository = { + type = "github" + repo = "%[2]s" + } + } + + resource "vercel_project_environment_variable" "example" { + project_id = vercel_project.example.id + %[3]s + key = "foo" + value = "bar-new" + target = ["production", "preview"] + } + + resource "vercel_project_environment_variable" "example_git_branch" { + project_id = vercel_project.example.id + %[3]s + key = "foo" + value = "bar-staging" + target = ["preview"] + git_branch = "test-pr" + } +`, projectName, testGithubRepo(), teamIDConfig()) +} From 351bf9bf5e6258d75b9464d00131b14a73a5bda3 Mon Sep 17 00:00:00 2001 From: Darpan Kakadia Date: Thu, 25 Aug 2022 12:07:43 +0200 Subject: [PATCH 06/15] [project] get project --- client/project_get.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/project_get.go b/client/project_get.go index f9791a86..bc50121d 100644 --- a/client/project_get.go +++ b/client/project_get.go @@ -70,7 +70,7 @@ type ProjectResponse struct { } // GetProject retrieves information about an existing project from Vercel. -func (c *Client) GetProject(ctx context.Context, projectID, teamID string, shouldFetchEnvironment bool) (r ProjectResponse, err error) { +func (c *Client) GetProject(ctx context.Context, projectID, teamID string, shouldFetchEnvironmentVariables bool) (r ProjectResponse, err error) { url := fmt.Sprintf("%s/v8/projects/%s", c.baseURL, projectID) if teamID != "" { url = fmt.Sprintf("%s?teamId=%s", url, teamID) @@ -86,14 +86,14 @@ func (c *Client) GetProject(ctx context.Context, projectID, teamID string, shoul } tflog.Trace(ctx, "getting project", map[string]interface{}{ "url": url, - "shouldFetchEnvironment": shouldFetchEnvironment, + "shouldFetchEnvironment": shouldFetchEnvironmentVariables, }) err = c.doRequest(req, &r) if err != nil { return r, err } - if shouldFetchEnvironment { + if shouldFetchEnvironmentVariables { r.EnvironmentVariables, err = c.getEnvironmentVariables(ctx, projectID, teamID) if err != nil { return r, fmt.Errorf("error getting environment variables for project: %w", err) From c1569bd5f0151a17d738abbff1728b2d8a1034e2 Mon Sep 17 00:00:00 2001 From: Darpan Kakadia Date: Thu, 25 Aug 2022 12:08:07 +0200 Subject: [PATCH 07/15] [resource_project_environment_variable] docs --- .../resources/project_environment_variable.md | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 docs/resources/project_environment_variable.md diff --git a/docs/resources/project_environment_variable.md b/docs/resources/project_environment_variable.md new file mode 100644 index 00000000..b56a43cb --- /dev/null +++ b/docs/resources/project_environment_variable.md @@ -0,0 +1,70 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "vercel_project_environment_variable Resource - terraform-provider-vercel" +subcategory: "" +description: |- + Provides a Project environment variable resource. + A Project environment variable resource defines an environment variable on a Vercel Project. + For more detailed information, please see the Vercel documentation https://vercel.com/docs/concepts/projects/environment-variables. +--- + +# vercel_project_environment_variable (Resource) + +Provides a Project environment variable resource. + +A Project environment variable resource defines an environment variable on a Vercel Project. + +For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables). + +## Example Usage + +```terraform +resource "vercel_project" "example" { + name = "example-project" + + git_repository = { + type = "github" + repo = "vercel/some-repo" + } +} + +# An environment variable that will be created +# for this project for the "production" environment. +resource "vercel_project_environment_variable" "example" { + project_id = vercel_project.example.id + key = "foo" + value = "bar" + target = ["production"] +} + +# An environment variable that will be created +# for this project for the "preview" environment when the branch is "staging". +resource "vercel_project_environment_variable" "example_git_branch" { + project_id = vercel_project.example.id + key = "foo" + value = "bar-staging" + target = ["preview"] + git_branch = "staging" +} +``` + + +## Schema + +### Required + +- `key` (String) The name of the environment variable. +- `project_id` (String) The ID of the Vercel project. +- `target` (Set of String) The environments that the environment variable should be present on. Valid targets are either `production`, `preview`, or `development`. +- `value` (String) The value of the environment variable. + +### Optional + +- `git_branch` (String) The git branch of the environment variable. +- `team_id` (String) The ID of the Vercel team. + +### Read-Only + +- `id` (String) The ID of the environment variable. + + From d81d3b69d0ad1a621eafda076ecb160d7abad578 Mon Sep 17 00:00:00 2001 From: Darpan Kakadia Date: Thu, 25 Aug 2022 12:08:33 +0200 Subject: [PATCH 08/15] refactor create & update env vars & fix tests --- vercel/resource_project.go | 18 ++++++++---------- vercel/resource_project_domain_test.go | 1 - vercel/resource_project_model.go | 7 ++++--- vercel/resource_project_test.go | 9 ++++----- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/vercel/resource_project.go b/vercel/resource_project.go index c55ea75c..72eef03b 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -306,9 +306,9 @@ func containsEnvVar(env []EnvironmentItem, v EnvironmentItem) bool { // diffEnvVars is used to determine the set of environment variables that need to be updated, // and the set of environment variables that need to be removed. -func diffEnvVars(oldVars, newVars []EnvironmentItem) (toUpsert, toRemove []EnvironmentItem) { +func diffEnvVars(oldVars, newVars []EnvironmentItem) (toCreate, toRemove []EnvironmentItem) { toRemove = []EnvironmentItem{} - toUpsert = []EnvironmentItem{} + toCreate = []EnvironmentItem{} for _, e := range oldVars { if !containsEnvVar(newVars, e) { toRemove = append(toRemove, e) @@ -316,10 +316,10 @@ func diffEnvVars(oldVars, newVars []EnvironmentItem) (toUpsert, toRemove []Envir } for _, e := range newVars { if !containsEnvVar(oldVars, e) { - toUpsert = append(toUpsert, e) + toCreate = append(toCreate, e) } } - return toUpsert, toRemove + return toCreate, toRemove } // Update will update a project and it's associated environment variables via the vercel API. @@ -363,7 +363,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, "state_envs": stateEnvs, }) - toUpsert, toRemove := diffEnvVars(stateEnvs, planEnvs) + toCreate, toRemove := diffEnvVars(stateEnvs, planEnvs) for _, v := range toRemove { err := r.p.client.DeleteEnvironmentVariable(ctx, state.ID.Value, state.TeamID.Value, v.ID.Value) if err != nil { @@ -384,12 +384,10 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, "environment_id": v.ID.Value, }) } - for _, v := range toUpsert { - result, err := r.p.client.UpsertEnvironmentVariable( + for _, v := range toCreate { + result, err := r.p.client.CreateEnvironmentVariable( ctx, - state.ID.Value, - state.TeamID.Value, - v.toUpsertEnvironmentVariableRequest(), + v.toCreateEnvironmentVariableRequest(plan.ID.Value, plan.TeamID.Value), ) if err != nil { resp.Diagnostics.AddError( diff --git a/vercel/resource_project_domain_test.go b/vercel/resource_project_domain_test.go index da0ea9f4..153ff970 100644 --- a/vercel/resource_project_domain_test.go +++ b/vercel/resource_project_domain_test.go @@ -12,7 +12,6 @@ import ( ) func TestAcc_ProjectDomain(t *testing.T) { - t.Parallel() testTeamID := resource.TestCheckNoResourceAttr("vercel_project.test", "team_id") if testTeam() != "" { testTeamID = resource.TestCheckResourceAttr("vercel_project.test", "team_id", testTeam()) diff --git a/vercel/resource_project_model.go b/vercel/resource_project_model.go index 8875f0f5..815e1d92 100644 --- a/vercel/resource_project_model.go +++ b/vercel/resource_project_model.go @@ -105,18 +105,19 @@ type EnvironmentItem struct { ID types.String `tfsdk:"id"` } -func (e *EnvironmentItem) toUpsertEnvironmentVariableRequest() client.UpsertEnvironmentVariableRequest { +func (e *EnvironmentItem) toCreateEnvironmentVariableRequest(projectID, teamID string) client.CreateEnvironmentVariableRequest { var target []string for _, t := range e.Target { target = append(target, t.Value) } - return client.UpsertEnvironmentVariableRequest{ + return client.CreateEnvironmentVariableRequest{ Key: e.Key.Value, Value: e.Value.Value, Target: target, GitBranch: toStrPointer(e.GitBranch), Type: "encrypted", - ID: e.ID.Value, + ProjectID: projectID, + TeamID: teamID, } } diff --git a/vercel/resource_project_test.go b/vercel/resource_project_test.go index 5e7cd4a4..8a6822e3 100644 --- a/vercel/resource_project_test.go +++ b/vercel/resource_project_test.go @@ -63,7 +63,6 @@ func TestAcc_Project(t *testing.T) { } func TestAcc_ProjectAddingEnvAfterInitialCreation(t *testing.T) { - t.Parallel() projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -87,7 +86,7 @@ func TestAcc_ProjectAddingEnvAfterInitialCreation(t *testing.T) { } func TestAcc_ProjectWithGitRepository(t *testing.T) { - t.Parallel() + projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -123,7 +122,7 @@ func TestAcc_ProjectWithGitRepository(t *testing.T) { } func TestAcc_ProjectImport(t *testing.T) { - t.Parallel() + projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -156,7 +155,7 @@ func testAccProjectExists(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no projectID is set") } - _, err := testClient().GetProject(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient().GetProject(context.TODO(), rs.Primary.ID, teamID, false) return err } } @@ -172,7 +171,7 @@ func testAccProjectDestroy(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no projectID is set") } - _, err := testClient().GetProject(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient().GetProject(context.TODO(), rs.Primary.ID, teamID, false) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } From eb4be3dfddc6049e4d7c2833f147f50e351724da Mon Sep 17 00:00:00 2001 From: Darpan Kakadia Date: Thu, 25 Aug 2022 16:34:40 +0200 Subject: [PATCH 09/15] [test] imports and delete checks --- .../resource_project_environment_variable.go | 60 +++++++++++++- ...urce_project_environment_variable_model.go | 6 +- ...ource_project_environment_variable_test.go | 78 +++++++++++++++++++ 3 files changed, 138 insertions(+), 6 deletions(-) diff --git a/vercel/resource_project_environment_variable.go b/vercel/resource_project_environment_variable.go index 11daa977..e0761618 100644 --- a/vercel/resource_project_environment_variable.go +++ b/vercel/resource_project_environment_variable.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/provider" @@ -119,7 +120,7 @@ func (r resourceProjectEnvironmentVariable) Create(ctx context.Context, req reso return } - result := convertResponseToProjectEnvironmentVariable(response, plan) + result := convertResponseToProjectEnvironmentVariable(response, plan.TeamID, plan.ProjectID) tflog.Trace(ctx, "created project environment variable", map[string]interface{}{ "id": result.ID.Value, @@ -162,7 +163,7 @@ func (r resourceProjectEnvironmentVariable) Read(ctx context.Context, req resour return } - result := convertResponseToProjectEnvironmentVariable(out, state) + result := convertResponseToProjectEnvironmentVariable(out, state.TeamID, state.ProjectID) tflog.Trace(ctx, "read project environment variable", map[string]interface{}{ "id": result.ID.Value, "team_id": result.TeamID.Value, @@ -194,7 +195,7 @@ func (r resourceProjectEnvironmentVariable) Update(ctx context.Context, req reso return } - result := convertResponseToProjectEnvironmentVariable(response, plan) + result := convertResponseToProjectEnvironmentVariable(response, plan.TeamID, plan.ProjectID) tflog.Trace(ctx, "updated project environment variable", map[string]interface{}{ "id": result.ID.Value, @@ -240,3 +241,56 @@ func (r resourceProjectEnvironmentVariable) Delete(ctx context.Context, req reso "project_id": state.ProjectID.Value, }) } + +// splitID is a helper function for splitting an import ID into the corresponding parts. +// It also validates whether the ID is in a correct format. +func splitProjectEnvironmentVariableID(id string) (teamID, projectID, envID string, ok bool) { + attributes := strings.Split(id, "/") + if len(attributes) == 3 { + return attributes[0], attributes[1], attributes[2], true + } + if len(attributes) == 2 { + return "", attributes[0], attributes[1], true + } + + return "", "", "", false +} + +// ImportState takes an identifier and reads all the project environment variable information from the Vercel API. +// The results are then stored in terraform state. +func (r resourceProjectEnvironmentVariable) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + teamID, projectID, envID, ok := splitProjectEnvironmentVariableID(req.ID) + if !ok { + resp.Diagnostics.AddError( + "Error importing project environment variable", + fmt.Sprintf("Invalid id '%s' specified. should be in format \"team_id/project_id/env_id\" or \"project_id/env_id\"", req.ID), + ) + } + + out, err := r.p.client.GetEnvironmentVariable(ctx, projectID, teamID, envID) + if err != nil { + resp.Diagnostics.AddError( + "Error reading project environment variable", + fmt.Sprintf("Could not get project environment variable %s %s %s, unexpected error: %s", + teamID, + projectID, + envID, + err, + ), + ) + return + } + + result := convertResponseToProjectEnvironmentVariable(out, types.String{Value: teamID, Null: teamID == ""}, types.String{Value: projectID}) + tflog.Trace(ctx, "imported project environment variable", map[string]interface{}{ + "team_id": result.TeamID.Value, + "project_id": result.ProjectID.Value, + "env_id": result.ID.Value, + }) + + diags := resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} \ No newline at end of file diff --git a/vercel/resource_project_environment_variable_model.go b/vercel/resource_project_environment_variable_model.go index fa2deb60..37e61592 100644 --- a/vercel/resource_project_environment_variable_model.go +++ b/vercel/resource_project_environment_variable_model.go @@ -52,7 +52,7 @@ func (e *ProjectEnvironmentVariable) toUpdateEnvironmentVariableRequest() client // convertResponseToProjectEnvironmentVariable is used to populate terraform state based on an API response. // Where possible, values from the API response are used to populate state. If not possible, // values from plan are used. -func convertResponseToProjectEnvironmentVariable(response client.EnvironmentVariable, plan ProjectEnvironmentVariable) ProjectEnvironmentVariable { +func convertResponseToProjectEnvironmentVariable(response client.EnvironmentVariable, teamID, projectID types.String) ProjectEnvironmentVariable { target := []types.String{} for _, t := range response.Target { target = append(target, types.String{Value: t}) @@ -63,8 +63,8 @@ func convertResponseToProjectEnvironmentVariable(response client.EnvironmentVari GitBranch: fromStringPointer(response.GitBranch), Key: types.String{Value: response.Key}, Value: types.String{Value: response.Value}, - TeamID: plan.TeamID, - ProjectID: plan.ProjectID, + TeamID: teamID, + ProjectID: projectID, ID: types.String{Value: response.ID}, } } diff --git a/vercel/resource_project_environment_variable_test.go b/vercel/resource_project_environment_variable_test.go index 90437deb..ed5eb33c 100644 --- a/vercel/resource_project_environment_variable_test.go +++ b/vercel/resource_project_environment_variable_test.go @@ -54,12 +54,38 @@ func testAccProjectEnvironmentVariableExists(n, teamID string) resource.TestChec } } +func testAccProjectEnvironmentVariablesDoNotExists(n, teamID string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("no ID is set") + } + + project, err := testClient().GetProject(context.TODO(), rs.Primary.Attributes["project_id"], teamID, true) + + if err != nil { + return fmt.Errorf("could not fetch the project: %w", err) + } + + if len(project.EnvironmentVariables) != 0 { + return fmt.Errorf("project environment variables not deleted, they still exist") + } + + return nil + } +} + func TestAcc_ProjectEnvironmentVariables(t *testing.T) { nameSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( + testAccProjectDestroy("vercel_project.example", testTeam()), ), Steps: []resource.TestStep{ { @@ -93,10 +119,46 @@ func TestAcc_ProjectEnvironmentVariables(t *testing.T) { resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "test-pr"), ), }, + { + ResourceName: "vercel_project_environment_variable.example", + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: getProjectEnvironmentVariableImportID("vercel_project_environment_variable.example"), + }, + { + ResourceName: "vercel_project_environment_variable.example_git_branch", + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: getProjectEnvironmentVariableImportID("vercel_project_environment_variable.example_git_branch"), + }, + { + Config: testAccProjectEnvironmentVariablesConfigDeleted(nameSuffix), + Check: resource.ComposeAggregateTestCheckFunc( + testAccProjectEnvironmentVariablesDoNotExists("vercel_project.example", testTeam()), + ), + }, }, }) } +func getProjectEnvironmentVariableImportID(n string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[n] + if !ok { + return "", fmt.Errorf("not found: %s", n) + } + + if rs.Primary.ID == "" { + return "", fmt.Errorf("no ID is set") + } + + if rs.Primary.Attributes["team_id"] == "" { + return fmt.Sprintf("%s/%s", rs.Primary.Attributes["project_id"], rs.Primary.ID), nil + } + return fmt.Sprintf("%s/%s/%s", rs.Primary.Attributes["team_id"], rs.Primary.Attributes["project_id"], rs.Primary.ID), nil + } +} + func testAccProjectEnvironmentVariablesConfig(projectName string) string { return fmt.Sprintf(` resource "vercel_project" "example" { @@ -158,3 +220,19 @@ func testAccProjectEnvironmentVariablesConfigUpdated(projectName string) string } `, projectName, testGithubRepo(), teamIDConfig()) } + +func testAccProjectEnvironmentVariablesConfigDeleted(projectName string) string { + return fmt.Sprintf(` + resource "vercel_project" "example" { + name = "test-acc-example-project-%[1]s" + %[3]s + + git_repository = { + type = "github" + repo = "%[2]s" + } + } +`, projectName, testGithubRepo(), teamIDConfig()) +} + + From 84e0b8f6db6b1f9d4a2e7bee5bc325d517c2e4e1 Mon Sep 17 00:00:00 2001 From: Darpan Kakadia Date: Thu, 25 Aug 2022 16:37:10 +0200 Subject: [PATCH 10/15] [tracing] test --- client/environment_variables_get.go | 2 +- client/request.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/client/environment_variables_get.go b/client/environment_variables_get.go index 15809df0..0173229e 100644 --- a/client/environment_variables_get.go +++ b/client/environment_variables_get.go @@ -26,7 +26,7 @@ func (c *Client) getEnvironmentVariables(ctx context.Context, projectID, teamID envResponse := struct { Env []EnvironmentVariable `json:"envs"` }{} - tflog.Trace(ctx, "getting environment variable", map[string]interface{}{ + tflog.Info(ctx, "getting environment variable", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &envResponse) diff --git a/client/request.go b/client/request.go index 88dea93d..931a43e5 100644 --- a/client/request.go +++ b/client/request.go @@ -1,10 +1,13 @@ package client import ( + "context" "encoding/json" "fmt" "io" "net/http" + + "github.com/hashicorp/terraform-plugin-log/tflog" ) // APIError is an error type that exposes additional information about why an API request failed. @@ -33,16 +36,29 @@ func (c *Client) doRequest(req *http.Request, v interface{}) error { req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.token)) resp, err := c.http().Do(req) + tflog.Info(context.TODO(), "response", map[string]interface{}{ + "status": resp.StatusCode, + "body": resp, + }) if err != nil { return fmt.Errorf("error doing http request: %w", err) } defer resp.Body.Close() responseBody, err := io.ReadAll(resp.Body) + tflog.Info(context.TODO(), "response 1", map[string]interface{}{ + "status": resp.StatusCode, + "body": string(responseBody), + }) if err != nil { return fmt.Errorf("error reading response body: %w", err) } + tflog.Info(context.TODO(), "response 2", map[string]interface{}{ + "status": resp.StatusCode, + "body": string(responseBody), + }) + if resp.StatusCode >= 300 { var errorResponse APIError if string(responseBody) == "" { From 026a9156cc04b937a0211bcbd3625d032ba21bca Mon Sep 17 00:00:00 2001 From: Douglas Parsons Date: Thu, 25 Aug 2022 16:25:49 +0100 Subject: [PATCH 11/15] Fix issues and increase logging verbosity --- client/alias_create.go | 2 +- client/alias_delete.go | 2 +- client/alias_get.go | 2 +- client/deployment_create.go | 2 +- client/deployment_delete.go | 2 +- client/deployment_get.go | 2 +- client/dns_record_update.go | 2 +- client/environment_variable_create.go | 4 +- client/environment_variable_update.go | 6 +- client/environment_variables_delete.go | 2 +- client/environment_variables_get.go | 6 +- client/file_create.go | 2 +- client/project_delete.go | 2 +- client/project_domain_create.go | 2 +- client/project_domain_delete.go | 2 +- client/project_domain_get.go | 2 +- client/project_domain_update.go | 2 +- client/project_get.go | 4 +- client/project_list.go | 2 +- client/project_update.go | 2 +- client/request.go | 16 --- client/team_create.go | 2 +- client/team_delete.go | 2 +- client/team_get.go | 2 +- vercel/data_source_alias.go | 2 +- vercel/data_source_project.go | 2 +- vercel/resource_alias.go | 6 +- vercel/resource_deployment.go | 6 +- vercel/resource_dns_record.go | 8 +- vercel/resource_project.go | 14 +- vercel/resource_project_domain.go | 10 +- .../resource_project_environment_variable.go | 14 +- ...urce_project_environment_variable_model.go | 4 +- ...ource_project_environment_variable_test.go | 121 +++++++----------- 34 files changed, 107 insertions(+), 154 deletions(-) diff --git a/client/alias_create.go b/client/alias_create.go index 75044b04..3406c0c7 100644 --- a/client/alias_create.go +++ b/client/alias_create.go @@ -37,7 +37,7 @@ func (c *Client) CreateAlias(ctx context.Context, request CreateAliasRequest, de return r, err } - tflog.Trace(ctx, "creating alias", map[string]interface{}{ + tflog.Info(ctx, "creating alias", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/alias_delete.go b/client/alias_delete.go index a0dbfecb..bcd53f5d 100644 --- a/client/alias_delete.go +++ b/client/alias_delete.go @@ -28,7 +28,7 @@ func (c *Client) DeleteAlias(ctx context.Context, aliasUID string, teamID string return r, err } - tflog.Trace(ctx, "deleting alias", map[string]interface{}{ + tflog.Info(ctx, "deleting alias", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/alias_get.go b/client/alias_get.go index 80a57bdf..a8a94821 100644 --- a/client/alias_get.go +++ b/client/alias_get.go @@ -30,7 +30,7 @@ func (c *Client) GetAlias(ctx context.Context, alias, teamID string) (r AliasRes if err != nil { return r, fmt.Errorf("creating request: %s", err) } - tflog.Trace(ctx, "getting alias", map[string]interface{}{ + tflog.Info(ctx, "getting alias", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/deployment_create.go b/client/deployment_create.go index ad749e56..de8afe16 100644 --- a/client/deployment_create.go +++ b/client/deployment_create.go @@ -210,7 +210,7 @@ func (c *Client) CreateDeployment(ctx context.Context, request CreateDeploymentR return r, err } - tflog.Trace(ctx, "creating deployment", map[string]interface{}{ + tflog.Info(ctx, "creating deployment", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/deployment_delete.go b/client/deployment_delete.go index f947257a..75ec9a17 100644 --- a/client/deployment_delete.go +++ b/client/deployment_delete.go @@ -29,7 +29,7 @@ func (c *Client) DeleteDeployment(ctx context.Context, deploymentID string, team return r, err } - tflog.Trace(ctx, "deleting deployment", map[string]interface{}{ + tflog.Info(ctx, "deleting deployment", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/deployment_get.go b/client/deployment_get.go index eb63e79c..19118f05 100644 --- a/client/deployment_get.go +++ b/client/deployment_get.go @@ -24,7 +24,7 @@ func (c *Client) GetDeployment(ctx context.Context, deploymentID, teamID string) return r, err } - tflog.Trace(ctx, "getting deployment", map[string]interface{}{ + tflog.Info(ctx, "getting deployment", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/dns_record_update.go b/client/dns_record_update.go index aa8c9d1b..be6a1886 100644 --- a/client/dns_record_update.go +++ b/client/dns_record_update.go @@ -41,7 +41,7 @@ func (c *Client) UpdateDNSRecord(ctx context.Context, teamID, recordID string, r return r, err } - tflog.Trace(ctx, "updating DNS record", map[string]interface{}{ + tflog.Info(ctx, "updating DNS record", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/environment_variable_create.go b/client/environment_variable_create.go index 0ad9f216..fb351502 100644 --- a/client/environment_variable_create.go +++ b/client/environment_variable_create.go @@ -18,7 +18,7 @@ type CreateEnvironmentVariableRequest struct { GitBranch *string `json:"gitBranch,omitempty"` Type string `json:"type"` ProjectID string `json:"-"` - TeamID string `json:"-"` + TeamID string `json:"-"` } // CreateEnvironmentVariable will create a brand new environment variable if one does not exist. @@ -38,7 +38,7 @@ func (c *Client) CreateEnvironmentVariable(ctx context.Context, request CreateEn return e, err } - tflog.Trace(ctx, "creating environment variable", map[string]interface{}{ + tflog.Info(ctx, "creating environment variable", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/environment_variable_update.go b/client/environment_variable_update.go index aeac3004..4093d773 100644 --- a/client/environment_variable_update.go +++ b/client/environment_variable_update.go @@ -18,8 +18,8 @@ type UpdateEnvironmentVariableRequest struct { GitBranch *string `json:"gitBranch,omitempty"` Type string `json:"type"` ProjectID string `json:"-"` - TeamID string `json:"-"` - EnvID string `json:"-"` + TeamID string `json:"-"` + EnvID string `json:"-"` } // UpdateEnvironmentVariable will update an existing environment variable to the latest information. @@ -39,7 +39,7 @@ func (c *Client) UpdateEnvironmentVariable(ctx context.Context, request UpdateEn return e, err } - tflog.Trace(ctx, "updating environment variable", map[string]interface{}{ + tflog.Info(ctx, "updating environment variable", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/environment_variables_delete.go b/client/environment_variables_delete.go index 8966f6d2..dc525503 100644 --- a/client/environment_variables_delete.go +++ b/client/environment_variables_delete.go @@ -24,7 +24,7 @@ func (c *Client) DeleteEnvironmentVariable(ctx context.Context, projectID, teamI return err } - tflog.Trace(ctx, "deleting environment variable", map[string]interface{}{ + tflog.Info(ctx, "deleting environment variable", map[string]interface{}{ "url": url, }) return c.doRequest(req, nil) diff --git a/client/environment_variables_get.go b/client/environment_variables_get.go index 0173229e..8495fa7a 100644 --- a/client/environment_variables_get.go +++ b/client/environment_variables_get.go @@ -26,7 +26,7 @@ func (c *Client) getEnvironmentVariables(ctx context.Context, projectID, teamID envResponse := struct { Env []EnvironmentVariable `json:"envs"` }{} - tflog.Info(ctx, "getting environment variable", map[string]interface{}{ + tflog.Info(ctx, "getting environment variables", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &envResponse) @@ -36,7 +36,7 @@ func (c *Client) getEnvironmentVariables(ctx context.Context, projectID, teamID func (c *Client) GetEnvironmentVariable(ctx context.Context, projectID, teamID, envID string) (e EnvironmentVariable, err error) { url := fmt.Sprintf("%s/v1/projects/%s/env/%s", c.baseURL, projectID, envID) if teamID != "" { - url = fmt.Sprintf("%s&teamId=%s", url, teamID) + url = fmt.Sprintf("%s?teamId=%s", url, teamID) } req, err := http.NewRequestWithContext( ctx, @@ -48,7 +48,7 @@ func (c *Client) GetEnvironmentVariable(ctx context.Context, projectID, teamID, return e, err } - tflog.Trace(ctx, "getting environment variable", map[string]interface{}{ + tflog.Info(ctx, "getting environment variable", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &e) diff --git a/client/file_create.go b/client/file_create.go index 854d239c..24819e85 100644 --- a/client/file_create.go +++ b/client/file_create.go @@ -35,7 +35,7 @@ func (c *Client) CreateFile(ctx context.Context, request CreateFileRequest) erro req.Header.Add("x-vercel-digest", request.SHA) req.Header.Set("Content-Type", "application/octet-stream") - tflog.Trace(ctx, "uploading file", map[string]interface{}{ + tflog.Info(ctx, "uploading file", map[string]interface{}{ "url": url, "sha": request.SHA, }) diff --git a/client/project_delete.go b/client/project_delete.go index a1f3b94c..18b7a19b 100644 --- a/client/project_delete.go +++ b/client/project_delete.go @@ -25,7 +25,7 @@ func (c *Client) DeleteProject(ctx context.Context, projectID, teamID string) er return err } - tflog.Trace(ctx, "deleting project", map[string]interface{}{ + tflog.Info(ctx, "deleting project", map[string]interface{}{ "url": url, }) return c.doRequest(req, nil) diff --git a/client/project_domain_create.go b/client/project_domain_create.go index 148e42e4..9b1724c8 100644 --- a/client/project_domain_create.go +++ b/client/project_domain_create.go @@ -38,7 +38,7 @@ func (c *Client) CreateProjectDomain(ctx context.Context, projectID, teamID stri return r, err } - tflog.Trace(ctx, "creating project domain", map[string]interface{}{ + tflog.Info(ctx, "creating project domain", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/project_domain_delete.go b/client/project_domain_delete.go index cf89ba03..ee0b5d60 100644 --- a/client/project_domain_delete.go +++ b/client/project_domain_delete.go @@ -25,7 +25,7 @@ func (c *Client) DeleteProjectDomain(ctx context.Context, projectID, domain, tea return err } - tflog.Trace(ctx, "deleting project domain", map[string]interface{}{ + tflog.Info(ctx, "deleting project domain", map[string]interface{}{ "url": url, }) return c.doRequest(req, nil) diff --git a/client/project_domain_get.go b/client/project_domain_get.go index 3cb2d863..390cc658 100644 --- a/client/project_domain_get.go +++ b/client/project_domain_get.go @@ -35,7 +35,7 @@ func (c *Client) GetProjectDomain(ctx context.Context, projectID, domain, teamID return r, err } - tflog.Trace(ctx, "getting project domain", map[string]interface{}{ + tflog.Info(ctx, "getting project domain", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/project_domain_update.go b/client/project_domain_update.go index b0e634fd..10e6ccb2 100644 --- a/client/project_domain_update.go +++ b/client/project_domain_update.go @@ -34,7 +34,7 @@ func (c *Client) UpdateProjectDomain(ctx context.Context, projectID, domain, tea return r, err } - tflog.Trace(ctx, "updating project domain", map[string]interface{}{ + tflog.Info(ctx, "updating project domain", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/project_get.go b/client/project_get.go index bc50121d..28999a22 100644 --- a/client/project_get.go +++ b/client/project_get.go @@ -84,13 +84,13 @@ func (c *Client) GetProject(ctx context.Context, projectID, teamID string, shoul if err != nil { return r, err } - tflog.Trace(ctx, "getting project", map[string]interface{}{ + tflog.Info(ctx, "getting project", map[string]interface{}{ "url": url, "shouldFetchEnvironment": shouldFetchEnvironmentVariables, }) err = c.doRequest(req, &r) if err != nil { - return r, err + return r, fmt.Errorf("unable to get project: %w", err) } if shouldFetchEnvironmentVariables { diff --git a/client/project_list.go b/client/project_list.go index fd7aab48..a0d2580f 100644 --- a/client/project_list.go +++ b/client/project_list.go @@ -28,7 +28,7 @@ func (c *Client) ListProjects(ctx context.Context, teamID string) (r []ProjectRe pr := struct { Projects []ProjectResponse `json:"projects"` }{} - tflog.Trace(ctx, "listing projects", map[string]interface{}{ + tflog.Info(ctx, "listing projects", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &pr) diff --git a/client/project_update.go b/client/project_update.go index a0da6a4c..d3e0b909 100644 --- a/client/project_update.go +++ b/client/project_update.go @@ -45,7 +45,7 @@ func (c *Client) UpdateProject(ctx context.Context, projectID, teamID string, re return r, err } - tflog.Trace(ctx, "updating project", map[string]interface{}{ + tflog.Info(ctx, "updating project", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/request.go b/client/request.go index 931a43e5..88dea93d 100644 --- a/client/request.go +++ b/client/request.go @@ -1,13 +1,10 @@ package client import ( - "context" "encoding/json" "fmt" "io" "net/http" - - "github.com/hashicorp/terraform-plugin-log/tflog" ) // APIError is an error type that exposes additional information about why an API request failed. @@ -36,29 +33,16 @@ func (c *Client) doRequest(req *http.Request, v interface{}) error { req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.token)) resp, err := c.http().Do(req) - tflog.Info(context.TODO(), "response", map[string]interface{}{ - "status": resp.StatusCode, - "body": resp, - }) if err != nil { return fmt.Errorf("error doing http request: %w", err) } defer resp.Body.Close() responseBody, err := io.ReadAll(resp.Body) - tflog.Info(context.TODO(), "response 1", map[string]interface{}{ - "status": resp.StatusCode, - "body": string(responseBody), - }) if err != nil { return fmt.Errorf("error reading response body: %w", err) } - tflog.Info(context.TODO(), "response 2", map[string]interface{}{ - "status": resp.StatusCode, - "body": string(responseBody), - }) - if resp.StatusCode >= 300 { var errorResponse APIError if string(responseBody) == "" { diff --git a/client/team_create.go b/client/team_create.go index 6b6be677..fe88a00c 100644 --- a/client/team_create.go +++ b/client/team_create.go @@ -35,7 +35,7 @@ func (c *Client) CreateTeam(ctx context.Context, request TeamCreateRequest) (r T return r, err } - tflog.Trace(ctx, "creating team", map[string]interface{}{ + tflog.Info(ctx, "creating team", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/team_delete.go b/client/team_delete.go index 163a7cb0..ca486e9c 100644 --- a/client/team_delete.go +++ b/client/team_delete.go @@ -21,7 +21,7 @@ func (c *Client) DeleteTeam(ctx context.Context, teamID string) error { return err } - tflog.Trace(ctx, "deleting team", map[string]interface{}{ + tflog.Info(ctx, "deleting team", map[string]interface{}{ "url": url, }) return c.doRequest(req, nil) diff --git a/client/team_get.go b/client/team_get.go index 1503f29d..9fb03dd0 100644 --- a/client/team_get.go +++ b/client/team_get.go @@ -26,7 +26,7 @@ func (c *Client) GetTeam(ctx context.Context, teamID, slug string) (r TeamRespon return r, err } - tflog.Trace(ctx, "getting team", map[string]interface{}{ + tflog.Info(ctx, "getting team", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/vercel/data_source_alias.go b/vercel/data_source_alias.go index 64e3d772..0eda6b09 100644 --- a/vercel/data_source_alias.go +++ b/vercel/data_source_alias.go @@ -81,7 +81,7 @@ func (r dataSourceAlias) Read(ctx context.Context, req datasource.ReadRequest, r } result := convertResponseToAlias(out, config) - tflog.Trace(ctx, "read alias", map[string]interface{}{ + tflog.Info(ctx, "read alias", map[string]interface{}{ "team_id": result.TeamID.Value, "alias": result.Alias.Value, }) diff --git a/vercel/data_source_project.go b/vercel/data_source_project.go index 42831f9f..fb134798 100644 --- a/vercel/data_source_project.go +++ b/vercel/data_source_project.go @@ -184,7 +184,7 @@ func (r dataSourceProject) Read(ctx context.Context, req datasource.ReadRequest, } result := convertResponseToProject(out, config.coercedFields(), types.Set{Null: true}) - tflog.Trace(ctx, "read project", map[string]interface{}{ + tflog.Info(ctx, "read project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) diff --git a/vercel/resource_alias.go b/vercel/resource_alias.go index 482d23c1..a07a8a35 100644 --- a/vercel/resource_alias.go +++ b/vercel/resource_alias.go @@ -90,7 +90,7 @@ func (r resourceAlias) Create(ctx context.Context, req resource.CreateRequest, r } result := convertResponseToAlias(out, plan) - tflog.Trace(ctx, "created alias", map[string]interface{}{ + tflog.Info(ctx, "created alias", map[string]interface{}{ "team_id": plan.TeamID.Value, "deployment_id": plan.DeploymentID.Value, "alias_id": result.ID.Value, @@ -131,7 +131,7 @@ func (r resourceAlias) Read(ctx context.Context, req resource.ReadRequest, resp } result := convertResponseToAlias(out, state) - tflog.Trace(ctx, "read alias", map[string]interface{}{ + tflog.Info(ctx, "read alias", map[string]interface{}{ "team_id": result.TeamID.Value, "alias_id": result.ID.Value, }) @@ -190,7 +190,7 @@ func (r resourceAlias) Delete(ctx context.Context, req resource.DeleteRequest, r return } - tflog.Trace(ctx, "deleted alias", map[string]interface{}{ + tflog.Info(ctx, "deleted alias", map[string]interface{}{ "team_id": state.TeamID.Value, "alias_id": state.ID.Value, }) diff --git a/vercel/resource_deployment.go b/vercel/resource_deployment.go index bf7391ae..a7b80ce1 100644 --- a/vercel/resource_deployment.go +++ b/vercel/resource_deployment.go @@ -312,7 +312,7 @@ func (r resourceDeployment) Create(ctx context.Context, req resource.CreateReque } result := convertResponseToDeployment(out, plan) - tflog.Trace(ctx, "created deployment", map[string]interface{}{ + tflog.Info(ctx, "created deployment", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -352,7 +352,7 @@ func (r resourceDeployment) Read(ctx context.Context, req resource.ReadRequest, } result := convertResponseToDeployment(out, state) - tflog.Trace(ctx, "read deployment", map[string]interface{}{ + tflog.Info(ctx, "read deployment", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -419,6 +419,6 @@ func (r resourceDeployment) Delete(ctx context.Context, req resource.DeleteReque ) return } - tflog.Trace(ctx, fmt.Sprintf("deleted deployment %s", dResp.UID)) + tflog.Info(ctx, fmt.Sprintf("deleted deployment %s", dResp.UID)) } } diff --git a/vercel/resource_dns_record.go b/vercel/resource_dns_record.go index e6085c19..a1c9e2e8 100644 --- a/vercel/resource_dns_record.go +++ b/vercel/resource_dns_record.go @@ -212,7 +212,7 @@ func (r resourceDNSRecord) Create(ctx context.Context, req resource.CreateReques ) return } - tflog.Trace(ctx, "created DNS Record", map[string]interface{}{ + tflog.Info(ctx, "created DNS Record", map[string]interface{}{ "team_id": result.TeamID, "record_id": result.ID, "domain": result.Domain, @@ -261,7 +261,7 @@ func (r resourceDNSRecord) Read(ctx context.Context, req resource.ReadRequest, r ) return } - tflog.Trace(ctx, "read DNS record", map[string]interface{}{ + tflog.Info(ctx, "read DNS record", map[string]interface{}{ "team_id": result.TeamID, "record_id": result.ID, "domain": result.Domain, @@ -317,7 +317,7 @@ func (r resourceDNSRecord) Update(ctx context.Context, req resource.UpdateReques ) return } - tflog.Trace(ctx, "updated DNS record", map[string]interface{}{ + tflog.Info(ctx, "updated DNS record", map[string]interface{}{ "team_id": result.TeamID, "record_id": result.ID, "domain": result.Domain, @@ -358,7 +358,7 @@ func (r resourceDNSRecord) Delete(ctx context.Context, req resource.DeleteReques return } - tflog.Trace(ctx, "delete DNS record", map[string]interface{}{ + tflog.Info(ctx, "delete DNS record", map[string]interface{}{ "domain": state.Domain, "record_id": state.ID, "team_id": state.TeamID, diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 72eef03b..36e3798e 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -233,7 +233,7 @@ func (r resourceProject) Create(ctx context.Context, req resource.CreateRequest, } result := convertResponseToProject(out, plan.coercedFields(), plan.Environment) - tflog.Trace(ctx, "created project", map[string]interface{}{ + tflog.Info(ctx, "created project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -273,7 +273,7 @@ func (r resourceProject) Read(ctx context.Context, req resource.ReadRequest, res } result := convertResponseToProject(out, state.coercedFields(), state.Environment) - tflog.Trace(ctx, "read project", map[string]interface{}{ + tflog.Info(ctx, "read project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -378,7 +378,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, ) return } - tflog.Trace(ctx, "deleted environment variable", map[string]interface{}{ + tflog.Info(ctx, "deleted environment variable", map[string]interface{}{ "team_id": plan.TeamID.Value, "project_id": plan.ID.Value, "environment_id": v.ID.Value, @@ -400,7 +400,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, ), ) } - tflog.Trace(ctx, "upserted environment variable", map[string]interface{}{ + tflog.Info(ctx, "upserted environment variable", map[string]interface{}{ "team_id": plan.TeamID.Value, "project_id": plan.ID.Value, "environment_id": result.ID, @@ -422,7 +422,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, } result := convertResponseToProject(out, plan.coercedFields(), plan.Environment) - tflog.Trace(ctx, "updated project", map[string]interface{}{ + tflog.Info(ctx, "updated project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -462,7 +462,7 @@ func (r resourceProject) Delete(ctx context.Context, req resource.DeleteRequest, return } - tflog.Trace(ctx, "deleted project", map[string]interface{}{ + tflog.Info(ctx, "deleted project", map[string]interface{}{ "team_id": state.TeamID.Value, "project_id": state.ID.Value, }) @@ -514,7 +514,7 @@ func (r resourceProject) ImportState(ctx context.Context, req resource.ImportSta PublicSource: types.Bool{Null: true}, TeamID: types.String{Value: teamID, Null: teamID == ""}, }, types.Set{Null: true}) - tflog.Trace(ctx, "imported project", map[string]interface{}{ + tflog.Info(ctx, "imported project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) diff --git a/vercel/resource_project_domain.go b/vercel/resource_project_domain.go index 042d14b4..bdcca3e3 100644 --- a/vercel/resource_project_domain.go +++ b/vercel/resource_project_domain.go @@ -126,7 +126,7 @@ func (r resourceProjectDomain) Create(ctx context.Context, req resource.CreateRe } result := convertResponseToProjectDomain(out, plan.TeamID) - tflog.Trace(ctx, "added domain to project", map[string]interface{}{ + tflog.Info(ctx, "added domain to project", map[string]interface{}{ "project_id": result.ProjectID.Value, "domain": result.Domain.Value, "team_id": result.TeamID.Value, @@ -167,7 +167,7 @@ func (r resourceProjectDomain) Read(ctx context.Context, req resource.ReadReques } result := convertResponseToProjectDomain(out, state.TeamID) - tflog.Trace(ctx, "read project domain", map[string]interface{}{ + tflog.Info(ctx, "read project domain", map[string]interface{}{ "project_id": result.ProjectID.Value, "domain": result.Domain.Value, "team_id": result.TeamID.Value, @@ -209,7 +209,7 @@ func (r resourceProjectDomain) Update(ctx context.Context, req resource.UpdateRe } result := convertResponseToProjectDomain(out, plan.TeamID) - tflog.Trace(ctx, "update project domain", map[string]interface{}{ + tflog.Info(ctx, "update project domain", map[string]interface{}{ "project_id": result.ProjectID.Value, "domain": result.Domain.Value, "team_id": result.TeamID.Value, @@ -251,7 +251,7 @@ func (r resourceProjectDomain) Delete(ctx context.Context, req resource.DeleteRe return } - tflog.Trace(ctx, "delete project domain", map[string]interface{}{ + tflog.Info(ctx, "delete project domain", map[string]interface{}{ "project_id": state.ProjectID.Value, "domain": state.Domain.Value, "team_id": state.TeamID.Value, @@ -302,7 +302,7 @@ func (r resourceProjectDomain) ImportState(ctx context.Context, req resource.Imp stringTypeTeamID.Null = true } result := convertResponseToProjectDomain(out, stringTypeTeamID) - tflog.Trace(ctx, "imported project domain", map[string]interface{}{ + tflog.Info(ctx, "imported project domain", map[string]interface{}{ "project_id": result.ProjectID.Value, "domain": result.Domain.Value, "team_id": result.TeamID.Value, diff --git a/vercel/resource_project_environment_variable.go b/vercel/resource_project_environment_variable.go index e0761618..02048f01 100644 --- a/vercel/resource_project_environment_variable.go +++ b/vercel/resource_project_environment_variable.go @@ -122,7 +122,7 @@ func (r resourceProjectEnvironmentVariable) Create(ctx context.Context, req reso result := convertResponseToProjectEnvironmentVariable(response, plan.TeamID, plan.ProjectID) - tflog.Trace(ctx, "created project environment variable", map[string]interface{}{ + tflog.Info(ctx, "created project environment variable", map[string]interface{}{ "id": result.ID.Value, "team_id": result.TeamID.Value, "project_id": result.ProjectID.Value, @@ -164,7 +164,7 @@ func (r resourceProjectEnvironmentVariable) Read(ctx context.Context, req resour } result := convertResponseToProjectEnvironmentVariable(out, state.TeamID, state.ProjectID) - tflog.Trace(ctx, "read project environment variable", map[string]interface{}{ + tflog.Info(ctx, "read project environment variable", map[string]interface{}{ "id": result.ID.Value, "team_id": result.TeamID.Value, "project_id": result.ProjectID.Value, @@ -197,7 +197,7 @@ func (r resourceProjectEnvironmentVariable) Update(ctx context.Context, req reso result := convertResponseToProjectEnvironmentVariable(response, plan.TeamID, plan.ProjectID) - tflog.Trace(ctx, "updated project environment variable", map[string]interface{}{ + tflog.Info(ctx, "updated project environment variable", map[string]interface{}{ "id": result.ID.Value, "team_id": result.TeamID.Value, "project_id": result.ProjectID.Value, @@ -235,7 +235,7 @@ func (r resourceProjectEnvironmentVariable) Delete(ctx context.Context, req reso return } - tflog.Trace(ctx, "deleted project environment variable", map[string]interface{}{ + tflog.Info(ctx, "deleted project environment variable", map[string]interface{}{ "id": state.ID.Value, "team_id": state.TeamID.Value, "project_id": state.ProjectID.Value, @@ -282,10 +282,10 @@ func (r resourceProjectEnvironmentVariable) ImportState(ctx context.Context, req } result := convertResponseToProjectEnvironmentVariable(out, types.String{Value: teamID, Null: teamID == ""}, types.String{Value: projectID}) - tflog.Trace(ctx, "imported project environment variable", map[string]interface{}{ + tflog.Info(ctx, "imported project environment variable", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ProjectID.Value, - "env_id": result.ID.Value, + "env_id": result.ID.Value, }) diags := resp.State.Set(ctx, result) @@ -293,4 +293,4 @@ func (r resourceProjectEnvironmentVariable) ImportState(ctx context.Context, req if resp.Diagnostics.HasError() { return } -} \ No newline at end of file +} diff --git a/vercel/resource_project_environment_variable_model.go b/vercel/resource_project_environment_variable_model.go index 37e61592..853522b8 100644 --- a/vercel/resource_project_environment_variable_model.go +++ b/vercel/resource_project_environment_variable_model.go @@ -44,8 +44,8 @@ func (e *ProjectEnvironmentVariable) toUpdateEnvironmentVariableRequest() client GitBranch: toStrPointer(e.GitBranch), Type: "encrypted", ProjectID: e.ProjectID.Value, - TeamID: e.TeamID.Value, - EnvID: e.ID.Value, + TeamID: e.TeamID.Value, + EnvID: e.ID.Value, } } diff --git a/vercel/resource_project_environment_variable_test.go b/vercel/resource_project_environment_variable_test.go index ed5eb33c..915e3515 100644 --- a/vercel/resource_project_environment_variable_test.go +++ b/vercel/resource_project_environment_variable_test.go @@ -10,34 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) -// func testAccDNSRecordDestroy1(n, teamID string) resource.TestCheckFunc { -// return func(s *terraform.State) error { -// rs, ok := s.RootModule().Resources[n] -// if !ok { -// return fmt.Errorf("not found: %s", n) -// } - -// if rs.Primary.ID == "" { -// return fmt.Errorf("no ID is set") -// } - -// _, err := testClient().GetDNSRecord(context.TODO(), rs.Primary.ID, teamID) - -// var apiErr client.APIError -// if err == nil { -// return fmt.Errorf("Found project but expected it to have been deleted") -// } -// if err != nil && errors.As(err, &apiErr) { -// if apiErr.StatusCode == 404 { -// return nil -// } -// return fmt.Errorf("Unexpected error checking for deleted project: %s", apiErr) -// } - -// return err -// } -// } - func testAccProjectEnvironmentVariableExists(n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -54,7 +26,7 @@ func testAccProjectEnvironmentVariableExists(n, teamID string) resource.TestChec } } -func testAccProjectEnvironmentVariablesDoNotExists(n, teamID string) resource.TestCheckFunc { +func testAccProjectEnvironmentVariablesDoNotExist(n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -65,8 +37,7 @@ func testAccProjectEnvironmentVariablesDoNotExists(n, teamID string) resource.Te return fmt.Errorf("no ID is set") } - project, err := testClient().GetProject(context.TODO(), rs.Primary.Attributes["project_id"], teamID, true) - + project, err := testClient().GetProject(context.TODO(), rs.Primary.ID, teamID, true) if err != nil { return fmt.Errorf("could not fetch the project: %w", err) } @@ -100,7 +71,7 @@ func TestAcc_ProjectEnvironmentVariables(t *testing.T) { resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "key", "foo"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "value", "bar-staging"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_git_branch", "target.*", "preview"), - resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "bla"), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "production"), ), }, { @@ -116,7 +87,7 @@ func TestAcc_ProjectEnvironmentVariables(t *testing.T) { resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "key", "foo"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "value", "bar-staging"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_git_branch", "target.*", "preview"), - resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "test-pr"), + resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "test"), ), }, { @@ -134,7 +105,7 @@ func TestAcc_ProjectEnvironmentVariables(t *testing.T) { { Config: testAccProjectEnvironmentVariablesConfigDeleted(nameSuffix), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectEnvironmentVariablesDoNotExists("vercel_project.example", testTeam()), + testAccProjectEnvironmentVariablesDoNotExist("vercel_project.example", testTeam()), ), }, }, @@ -161,7 +132,7 @@ func getProjectEnvironmentVariableImportID(n string) resource.ImportStateIdFunc func testAccProjectEnvironmentVariablesConfig(projectName string) string { return fmt.Sprintf(` - resource "vercel_project" "example" { +resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" %[3]s @@ -169,70 +140,68 @@ func testAccProjectEnvironmentVariablesConfig(projectName string) string { type = "github" repo = "%[2]s" } - } +} - resource "vercel_project_environment_variable" "example" { +resource "vercel_project_environment_variable" "example" { project_id = vercel_project.example.id %[3]s key = "foo" value = "bar" target = ["production"] - } +} - resource "vercel_project_environment_variable" "example_git_branch" { +resource "vercel_project_environment_variable" "example_git_branch" { project_id = vercel_project.example.id %[3]s key = "foo" value = "bar-staging" target = ["preview"] - git_branch = "bla" - } + git_branch = "production" +} `, projectName, testGithubRepo(), teamIDConfig()) } func testAccProjectEnvironmentVariablesConfigUpdated(projectName string) string { return fmt.Sprintf(` - resource "vercel_project" "example" { - name = "test-acc-example-project-%[1]s" - %[3]s - - git_repository = { - type = "github" - repo = "%[2]s" - } - } +resource "vercel_project" "example" { + name = "test-acc-example-project-%[1]s" + %[3]s + + git_repository = { + type = "github" + repo = "%[2]s" + } +} - resource "vercel_project_environment_variable" "example" { - project_id = vercel_project.example.id - %[3]s - key = "foo" - value = "bar-new" - target = ["production", "preview"] - } +resource "vercel_project_environment_variable" "example" { + project_id = vercel_project.example.id + %[3]s + key = "foo" + value = "bar-new" + target = ["production", "preview"] +} - resource "vercel_project_environment_variable" "example_git_branch" { - project_id = vercel_project.example.id - %[3]s - key = "foo" - value = "bar-staging" - target = ["preview"] - git_branch = "test-pr" - } +resource "vercel_project_environment_variable" "example_git_branch" { + project_id = vercel_project.example.id + %[3]s + key = "foo" + value = "bar-staging" + target = ["preview"] + git_branch = "test" +} `, projectName, testGithubRepo(), teamIDConfig()) } func testAccProjectEnvironmentVariablesConfigDeleted(projectName string) string { return fmt.Sprintf(` - resource "vercel_project" "example" { - name = "test-acc-example-project-%[1]s" - %[3]s - - git_repository = { - type = "github" - repo = "%[2]s" - } - } +resource "vercel_project" "example" { + name = "test-acc-example-project-%[1]s" + %[3]s + + git_repository = { + type = "github" + repo = "%[2]s" + } +} `, projectName, testGithubRepo(), teamIDConfig()) } - - From 8611c45e344bf0b8ab10c34669ecb04df12d7f24 Mon Sep 17 00:00:00 2001 From: Douglas Parsons Date: Thu, 25 Aug 2022 16:34:16 +0100 Subject: [PATCH 12/15] Remove some unnecessary whitespace --- vercel/resource_project_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/vercel/resource_project_test.go b/vercel/resource_project_test.go index 8a6822e3..063231c7 100644 --- a/vercel/resource_project_test.go +++ b/vercel/resource_project_test.go @@ -86,7 +86,6 @@ func TestAcc_ProjectAddingEnvAfterInitialCreation(t *testing.T) { } func TestAcc_ProjectWithGitRepository(t *testing.T) { - projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -122,7 +121,6 @@ func TestAcc_ProjectWithGitRepository(t *testing.T) { } func TestAcc_ProjectImport(t *testing.T) { - projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, From ef5d341ba73762b2a1e2fde43e758672e01df08b Mon Sep 17 00:00:00 2001 From: Douglas Parsons Date: Thu, 25 Aug 2022 17:02:40 +0100 Subject: [PATCH 13/15] Flesh out docs --- Taskfile.yml | 3 ++ docs/resources/project.md | 33 ++++++----------- .../resources/project_environment_variable.md | 35 ++++++++++++++----- examples/resources/vercel_project/resource.tf | 16 --------- .../import.sh | 7 ++++ vercel/resource_project.go | 15 ++++---- .../resource_project_environment_variable.go | 20 ++++++----- 7 files changed, 68 insertions(+), 61 deletions(-) create mode 100644 examples/resources/vercel_project_environment_variable/import.sh diff --git a/Taskfile.yml b/Taskfile.yml index 1a3b249d..a40e2e44 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -24,6 +24,8 @@ tasks: desc: "Install the tfplugindocs tool" cmds: - go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.7.0 + status: + - which staticcheck docs: desc: "Update the docs generated from description fields" @@ -37,6 +39,7 @@ tasks: - "vercel/**/*.go" - "main.go" - "examples/**/*.tf" + - "examples/**/*.sh" generates: - docs/**/*.md diff --git a/docs/resources/project.md b/docs/resources/project.md index a87e2308..f04a624e 100644 --- a/docs/resources/project.md +++ b/docs/resources/project.md @@ -6,6 +6,8 @@ description: |- Provides a Project resource. A Project groups deployments and custom domains. To deploy on Vercel, you need to create a Project. For more detailed information, please see the Vercel documentation https://vercel.com/docs/concepts/projects/overview. + ~> Terraform currently provides both a standalone Project Environment Variable resource (a single Environment Variable), and a Project resource with Environment Variables defined in-line via the environment field. + At this time you cannot use a Vercel Project resource with in-line environment in conjunction with any vercel_project_environment_variable resources. Doing so will cause a conflict of settings and will overwrite Environment Variables. --- # vercel_project (Resource) @@ -16,6 +18,9 @@ A Project groups deployments and custom domains. To deploy on Vercel, you need t For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/overview). +~> Terraform currently provides both a standalone Project Environment Variable resource (a single Environment Variable), and a Project resource with Environment Variables defined in-line via the `environment` field. +At this time you cannot use a Vercel Project resource with in-line `environment` in conjunction with any `vercel_project_environment_variable` resources. Doing so will cause a conflict of settings and will overwrite Environment Variables. + ## Example Usage ```terraform @@ -26,14 +31,6 @@ resource "vercel_project" "with_git" { name = "example-project-with-git" framework = "nextjs" - environment = [ - { - key = "bar" - value = "baz" - target = ["preview"] - } - ] - git_repository = { type = "github" repo = "vercel/some-repo" @@ -46,14 +43,6 @@ resource "vercel_project" "with_git" { resource "vercel_project" "example" { name = "example-project" framework = "nextjs" - - environment = [ - { - key = "bar" - value = "baz" - target = ["preview", "production"] - } - ] } ``` @@ -68,7 +57,7 @@ resource "vercel_project" "example" { - `build_command` (String) The build command for this project. If omitted, this value will be automatically detected. - `dev_command` (String) The dev command for this project. If omitted, this value will be automatically detected. -- `environment` (Attributes Set) A set of environment variables that should be configured for the project. (see [below for nested schema](#nestedatt--environment)) +- `environment` (Attributes Set) A set of Environment Variables that should be configured for the project. (see [below for nested schema](#nestedatt--environment)) - `framework` (String) The framework that is being used for this project. If omitted, no framework is selected. - `git_repository` (Attributes) The Git Repository that will be connected to the project. When this is defined, any pushes to the specified connected Git Repository will be automatically deployed. This requires the corresponding Vercel for [Github](https://vercel.com/docs/concepts/git/vercel-for-github), [Gitlab](https://vercel.com/docs/concepts/git/vercel-for-gitlab) or [Bitbucket](https://vercel.com/docs/concepts/git/vercel-for-bitbucket) plugins to be installed. (see [below for nested schema](#nestedatt--git_repository)) - `ignore_command` (String) When a commit is pushed to the Git repository that is connected with your Project, its SHA will determine if a new Build has to be issued. If the SHA was deployed before, no new Build will be issued. You can customize this behavior with a command that exits with code 1 (new Build needed) or code 0. @@ -88,11 +77,11 @@ resource "vercel_project" "example" { Optional: -- `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. -- `target` (Set of String) The environments that the environment variable should be present on. Valid targets are either `production`, `preview`, or `development`. -- `value` (String, Sensitive) The value of the environment variable. +- `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. +- `target` (Set of String) The environments that the Environment Variable should be present on. Valid targets are either `production`, `preview`, or `development`. +- `value` (String, Sensitive) The value of the Environment Variable. diff --git a/docs/resources/project_environment_variable.md b/docs/resources/project_environment_variable.md index b56a43cb..f18ee8e0 100644 --- a/docs/resources/project_environment_variable.md +++ b/docs/resources/project_environment_variable.md @@ -3,19 +3,24 @@ page_title: "vercel_project_environment_variable Resource - terraform-provider-vercel" subcategory: "" description: |- - Provides a Project environment variable resource. - A Project environment variable resource defines an environment variable on a Vercel Project. + Provides a Project Environment Variable resource. + A Project Environment Variable resource defines an Environment Variable on a Vercel Project. For more detailed information, please see the Vercel documentation https://vercel.com/docs/concepts/projects/environment-variables. + ~> Terraform currently provides both a standalone Project Environment Variable resource (a single Environment Variable), and a Project resource with Environment Variables defined in-line via the environment field. + At this time you cannot use a Vercel Project resource with in-line environment in conjunction with any vercel_project_environment_variable resources. Doing so will cause a conflict of settings and will overwrite Environment Variables. --- # vercel_project_environment_variable (Resource) -Provides a Project environment variable resource. +Provides a Project Environment Variable resource. -A Project environment variable resource defines an environment variable on a Vercel Project. +A Project Environment Variable resource defines an Environment Variable on a Vercel Project. For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables). +~> Terraform currently provides both a standalone Project Environment Variable resource (a single Environment Variable), and a Project resource with Environment Variables defined in-line via the `environment` field. +At this time you cannot use a Vercel Project resource with in-line `environment` in conjunction with any `vercel_project_environment_variable` resources. Doing so will cause a conflict of settings and will overwrite Environment Variables. + ## Example Usage ```terraform @@ -53,18 +58,30 @@ resource "vercel_project_environment_variable" "example_git_branch" { ### Required -- `key` (String) The name of the environment variable. +- `key` (String) The name of the Environment Variable. - `project_id` (String) The ID of the Vercel project. -- `target` (Set of String) The environments that the environment variable should be present on. Valid targets are either `production`, `preview`, or `development`. -- `value` (String) The value of the environment variable. +- `target` (Set of String) The environments that the Environment Variable should be present on. Valid targets are either `production`, `preview`, or `development`. +- `value` (String) The value of the Environment Variable. ### Optional -- `git_branch` (String) The git branch of the environment variable. +- `git_branch` (String) The git branch of the Environment Variable. - `team_id` (String) The ID of the Vercel team. ### Read-Only -- `id` (String) The ID of the environment variable. +- `id` (String) The ID of the Environment Variable. + +## Import +Import is supported using the following syntax: +```shell +# Import via the team_id, project_id and environment variable id. +# team_id can be found in the team `settings` tab in the Vercel UI. +# environment variable id can be taken from the network tab on the project page. +terraform import vercel_project_environment_variable.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx/FdT2e1E5Of6Cihmt + +# If importing without a team, simply use the project_id and environment variable id. +terraform import vercel_project_environment_variable.example_git_branch prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx/FdT2e1E5Of6Cihmt +``` diff --git a/examples/resources/vercel_project/resource.tf b/examples/resources/vercel_project/resource.tf index ac3e1a77..dde97e38 100644 --- a/examples/resources/vercel_project/resource.tf +++ b/examples/resources/vercel_project/resource.tf @@ -5,14 +5,6 @@ resource "vercel_project" "with_git" { name = "example-project-with-git" framework = "nextjs" - environment = [ - { - key = "bar" - value = "baz" - target = ["preview"] - } - ] - git_repository = { type = "github" repo = "vercel/some-repo" @@ -25,12 +17,4 @@ resource "vercel_project" "with_git" { resource "vercel_project" "example" { name = "example-project" framework = "nextjs" - - environment = [ - { - key = "bar" - value = "baz" - target = ["preview", "production"] - } - ] } diff --git a/examples/resources/vercel_project_environment_variable/import.sh b/examples/resources/vercel_project_environment_variable/import.sh new file mode 100644 index 00000000..cc619c73 --- /dev/null +++ b/examples/resources/vercel_project_environment_variable/import.sh @@ -0,0 +1,7 @@ +# Import via the team_id, project_id and environment variable id. +# team_id can be found in the team `settings` tab in the Vercel UI. +# environment variable id can be taken from the network tab on the project page. +terraform import vercel_project_environment_variable.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx/FdT2e1E5Of6Cihmt + +# If importing without a team, simply use the project_id and environment variable id. +terraform import vercel_project_environment_variable.example_git_branch prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx/FdT2e1E5Of6Cihmt diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 36e3798e..38171aaa 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -27,6 +27,9 @@ Provides a Project resource. A Project groups deployments and custom domains. To deploy on Vercel, you need to create a Project. For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/overview). + +~> Terraform currently provides both a standalone Project Environment Variable resource (a single Environment Variable), and a Project resource with Environment Variables defined in-line via the ` + "`environment` field" + `. +At this time you cannot use a Vercel Project resource with in-line ` + "`environment` in conjunction with any `vercel_project_environment_variable`" + ` resources. Doing so will cause a conflict of settings and will overwrite Environment Variables. `, Attributes: map[string]tfsdk.Attribute{ "team_id": { @@ -89,11 +92,11 @@ For more detailed information, please see the [Vercel documentation](https://ver }, }, "environment": { - Description: "A set of environment variables that should be configured for the project.", + Description: "A set of Environment Variables that should be configured for the project.", Optional: true, Attributes: tfsdk.SetNestedAttributes(map[string]tfsdk.Attribute{ "target": { - Description: "The environments that the environment variable should be present on. Valid targets are either `production`, `preview`, or `development`.", + Description: "The environments that the Environment Variable should be present on. Valid targets are either `production`, `preview`, or `development`.", Type: types.SetType{ ElemType: types.StringType, }, @@ -103,23 +106,23 @@ For more detailed information, please see the [Vercel documentation](https://ver Required: true, }, "git_branch": { - Description: "The git branch of the environment variable.", + Description: "The git branch of the Environment Variable.", Type: types.StringType, Optional: true, }, "key": { - Description: "The name of the environment variable.", + Description: "The name of the Environment Variable.", Type: types.StringType, Required: true, }, "value": { - Description: "The value of the environment variable.", + Description: "The value of the Environment Variable.", Type: types.StringType, Required: true, Sensitive: true, }, "id": { - Description: "The ID of the environment variable", + Description: "The ID of the Environment Variable.", Type: types.StringType, PlanModifiers: tfsdk.AttributePlanModifiers{resource.UseStateForUnknown()}, Computed: true, diff --git a/vercel/resource_project_environment_variable.go b/vercel/resource_project_environment_variable.go index 02048f01..03b3cce3 100644 --- a/vercel/resource_project_environment_variable.go +++ b/vercel/resource_project_environment_variable.go @@ -21,15 +21,19 @@ type resourceProjectEnvironmentVariableType struct{} func (r resourceProjectEnvironmentVariableType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) { return tfsdk.Schema{ Description: ` -Provides a Project environment variable resource. +Provides a Project Environment Variable resource. -A Project environment variable resource defines an environment variable on a Vercel Project. +A Project Environment Variable resource defines an Environment Variable on a Vercel Project. -For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables).`, +For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables). + +~> Terraform currently provides both a standalone Project Environment Variable resource (a single Environment Variable), and a Project resource with Environment Variables defined in-line via the ` + "`environment` field" + `. +At this time you cannot use a Vercel Project resource with in-line ` + "`environment` in conjunction with any `vercel_project_environment_variable`" + ` resources. Doing so will cause a conflict of settings and will overwrite Environment Variables. +`, Attributes: map[string]tfsdk.Attribute{ "target": { Required: true, - Description: "The environments that the environment variable should be present on. Valid targets are either `production`, `preview`, or `development`.", + Description: "The environments that the Environment Variable should be present on. Valid targets are either `production`, `preview`, or `development`.", Type: types.SetType{ ElemType: types.StringType, }, @@ -37,17 +41,17 @@ For more detailed information, please see the [Vercel documentation](https://ver "key": { Required: true, PlanModifiers: tfsdk.AttributePlanModifiers{resource.RequiresReplace()}, - Description: "The name of the environment variable.", + Description: "The name of the Environment Variable.", Type: types.StringType, }, "value": { Required: true, - Description: "The value of the environment variable.", + Description: "The value of the Environment Variable.", Type: types.StringType, }, "git_branch": { Optional: true, - Description: "The git branch of the environment variable.", + Description: "The git branch of the Environment Variable.", Type: types.StringType, }, "project_id": { @@ -63,7 +67,7 @@ For more detailed information, please see the [Vercel documentation](https://ver Type: types.StringType, }, "id": { - Description: "The ID of the environment variable.", + Description: "The ID of the Environment Variable.", Type: types.StringType, PlanModifiers: tfsdk.AttributePlanModifiers{resource.UseStateForUnknown()}, Computed: true, From 4e21ea6244d0000328efd2376b65e28f5ee861a0 Mon Sep 17 00:00:00 2001 From: Douglas Parsons Date: Thu, 25 Aug 2022 17:04:11 +0100 Subject: [PATCH 14/15] Update versions in the README --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8b5e63cd..efb8fe49 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Requirements - [Terraform](https://www.terraform.io/downloads.html) 1.1 or higher -- [Go](https://golang.org/doc/install) 1.17 (to build the provider plugin) +- [Go](https://golang.org/doc/install) 1.19 (to build the provider plugin) - [Task](https://taskfile.dev) v3 (to run Taskfile commands) ## Building The Provider @@ -19,7 +19,7 @@ $ task build ## Developing the Provider -If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.17+ is _required_). +If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.19+ is _required_). To compile the provider, run `task build`. This will build the provider and put the provider binary in the repository root. @@ -41,7 +41,6 @@ The acceptance tests require a few environment variables to be set: * `VERCEL_API_TOKEN` - this can be generated [here](https://vercel.com/account/tokens) * `VERCEL_TERRAFORM_TESTING_TEAM` - a Vercel team_id where resources can be created and destroyed * `VERCEL_TERRAFORM_TESTING_GITHUB_REPO` - a GitHub repository in the form 'org/repo' that can be used to trigger deployments -* `VERCEL_TERRAFORM_TESTING_GITLAB_REPO` - a GitLab repository in the form 'namespace/repo' that can be used to trigger deployments * `VERCEL_TERRAFORM_TESTING_BITBUCKET_REPO` - a Bitbucket repository in the form 'project/repo' that can be used to trigger deployments ```sh @@ -51,7 +50,7 @@ $ task test In order to run the tests with extra debugging context, prefix with `TF_LOG` (see the [terraform documentation](https://www.terraform.io/docs/internals/debugging.html) for details). ```sh -$ TF_LOG=trace task test +$ TF_LOG=INFO task test ``` To run a specific set of tests, use the `-run` flag and specify a regex pattern matching the test names. From 003b4cfaae51c30b59ae95a12cea9b73cb0792ab Mon Sep 17 00:00:00 2001 From: Douglas Parsons Date: Thu, 25 Aug 2022 17:09:00 +0100 Subject: [PATCH 15/15] Reset logging to Trace --- client/alias_create.go | 2 +- client/alias_delete.go | 2 +- client/alias_get.go | 2 +- client/deployment_create.go | 2 +- client/deployment_delete.go | 2 +- client/deployment_get.go | 2 +- client/dns_record_update.go | 2 +- client/environment_variable_create.go | 2 +- client/environment_variable_update.go | 2 +- client/environment_variables_delete.go | 2 +- client/environment_variables_get.go | 4 ++-- client/file_create.go | 2 +- client/project_delete.go | 2 +- client/project_domain_create.go | 2 +- client/project_domain_delete.go | 2 +- client/project_domain_get.go | 2 +- client/project_domain_update.go | 2 +- client/project_get.go | 2 +- client/project_list.go | 2 +- client/project_update.go | 2 +- client/team_create.go | 2 +- client/team_delete.go | 2 +- client/team_get.go | 2 +- vercel/data_source_alias.go | 2 +- vercel/data_source_project.go | 2 +- vercel/resource_alias.go | 6 +++--- vercel/resource_deployment.go | 6 +++--- vercel/resource_dns_record.go | 8 ++++---- vercel/resource_project.go | 14 +++++++------- vercel/resource_project_domain.go | 10 +++++----- vercel/resource_project_environment_variable.go | 10 +++++----- 31 files changed, 53 insertions(+), 53 deletions(-) diff --git a/client/alias_create.go b/client/alias_create.go index 3406c0c7..75044b04 100644 --- a/client/alias_create.go +++ b/client/alias_create.go @@ -37,7 +37,7 @@ func (c *Client) CreateAlias(ctx context.Context, request CreateAliasRequest, de return r, err } - tflog.Info(ctx, "creating alias", map[string]interface{}{ + tflog.Trace(ctx, "creating alias", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/alias_delete.go b/client/alias_delete.go index bcd53f5d..a0dbfecb 100644 --- a/client/alias_delete.go +++ b/client/alias_delete.go @@ -28,7 +28,7 @@ func (c *Client) DeleteAlias(ctx context.Context, aliasUID string, teamID string return r, err } - tflog.Info(ctx, "deleting alias", map[string]interface{}{ + tflog.Trace(ctx, "deleting alias", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/alias_get.go b/client/alias_get.go index a8a94821..80a57bdf 100644 --- a/client/alias_get.go +++ b/client/alias_get.go @@ -30,7 +30,7 @@ func (c *Client) GetAlias(ctx context.Context, alias, teamID string) (r AliasRes if err != nil { return r, fmt.Errorf("creating request: %s", err) } - tflog.Info(ctx, "getting alias", map[string]interface{}{ + tflog.Trace(ctx, "getting alias", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/deployment_create.go b/client/deployment_create.go index de8afe16..ad749e56 100644 --- a/client/deployment_create.go +++ b/client/deployment_create.go @@ -210,7 +210,7 @@ func (c *Client) CreateDeployment(ctx context.Context, request CreateDeploymentR return r, err } - tflog.Info(ctx, "creating deployment", map[string]interface{}{ + tflog.Trace(ctx, "creating deployment", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/deployment_delete.go b/client/deployment_delete.go index 75ec9a17..f947257a 100644 --- a/client/deployment_delete.go +++ b/client/deployment_delete.go @@ -29,7 +29,7 @@ func (c *Client) DeleteDeployment(ctx context.Context, deploymentID string, team return r, err } - tflog.Info(ctx, "deleting deployment", map[string]interface{}{ + tflog.Trace(ctx, "deleting deployment", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/deployment_get.go b/client/deployment_get.go index 19118f05..eb63e79c 100644 --- a/client/deployment_get.go +++ b/client/deployment_get.go @@ -24,7 +24,7 @@ func (c *Client) GetDeployment(ctx context.Context, deploymentID, teamID string) return r, err } - tflog.Info(ctx, "getting deployment", map[string]interface{}{ + tflog.Trace(ctx, "getting deployment", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/dns_record_update.go b/client/dns_record_update.go index be6a1886..aa8c9d1b 100644 --- a/client/dns_record_update.go +++ b/client/dns_record_update.go @@ -41,7 +41,7 @@ func (c *Client) UpdateDNSRecord(ctx context.Context, teamID, recordID string, r return r, err } - tflog.Info(ctx, "updating DNS record", map[string]interface{}{ + tflog.Trace(ctx, "updating DNS record", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/environment_variable_create.go b/client/environment_variable_create.go index fb351502..944c28d1 100644 --- a/client/environment_variable_create.go +++ b/client/environment_variable_create.go @@ -38,7 +38,7 @@ func (c *Client) CreateEnvironmentVariable(ctx context.Context, request CreateEn return e, err } - tflog.Info(ctx, "creating environment variable", map[string]interface{}{ + tflog.Trace(ctx, "creating environment variable", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/environment_variable_update.go b/client/environment_variable_update.go index 4093d773..e40a5603 100644 --- a/client/environment_variable_update.go +++ b/client/environment_variable_update.go @@ -39,7 +39,7 @@ func (c *Client) UpdateEnvironmentVariable(ctx context.Context, request UpdateEn return e, err } - tflog.Info(ctx, "updating environment variable", map[string]interface{}{ + tflog.Trace(ctx, "updating environment variable", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/environment_variables_delete.go b/client/environment_variables_delete.go index dc525503..8966f6d2 100644 --- a/client/environment_variables_delete.go +++ b/client/environment_variables_delete.go @@ -24,7 +24,7 @@ func (c *Client) DeleteEnvironmentVariable(ctx context.Context, projectID, teamI return err } - tflog.Info(ctx, "deleting environment variable", map[string]interface{}{ + tflog.Trace(ctx, "deleting environment variable", map[string]interface{}{ "url": url, }) return c.doRequest(req, nil) diff --git a/client/environment_variables_get.go b/client/environment_variables_get.go index 8495fa7a..858a8cf1 100644 --- a/client/environment_variables_get.go +++ b/client/environment_variables_get.go @@ -26,7 +26,7 @@ func (c *Client) getEnvironmentVariables(ctx context.Context, projectID, teamID envResponse := struct { Env []EnvironmentVariable `json:"envs"` }{} - tflog.Info(ctx, "getting environment variables", map[string]interface{}{ + tflog.Trace(ctx, "getting environment variables", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &envResponse) @@ -48,7 +48,7 @@ func (c *Client) GetEnvironmentVariable(ctx context.Context, projectID, teamID, return e, err } - tflog.Info(ctx, "getting environment variable", map[string]interface{}{ + tflog.Trace(ctx, "getting environment variable", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &e) diff --git a/client/file_create.go b/client/file_create.go index 24819e85..854d239c 100644 --- a/client/file_create.go +++ b/client/file_create.go @@ -35,7 +35,7 @@ func (c *Client) CreateFile(ctx context.Context, request CreateFileRequest) erro req.Header.Add("x-vercel-digest", request.SHA) req.Header.Set("Content-Type", "application/octet-stream") - tflog.Info(ctx, "uploading file", map[string]interface{}{ + tflog.Trace(ctx, "uploading file", map[string]interface{}{ "url": url, "sha": request.SHA, }) diff --git a/client/project_delete.go b/client/project_delete.go index 18b7a19b..a1f3b94c 100644 --- a/client/project_delete.go +++ b/client/project_delete.go @@ -25,7 +25,7 @@ func (c *Client) DeleteProject(ctx context.Context, projectID, teamID string) er return err } - tflog.Info(ctx, "deleting project", map[string]interface{}{ + tflog.Trace(ctx, "deleting project", map[string]interface{}{ "url": url, }) return c.doRequest(req, nil) diff --git a/client/project_domain_create.go b/client/project_domain_create.go index 9b1724c8..148e42e4 100644 --- a/client/project_domain_create.go +++ b/client/project_domain_create.go @@ -38,7 +38,7 @@ func (c *Client) CreateProjectDomain(ctx context.Context, projectID, teamID stri return r, err } - tflog.Info(ctx, "creating project domain", map[string]interface{}{ + tflog.Trace(ctx, "creating project domain", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/project_domain_delete.go b/client/project_domain_delete.go index ee0b5d60..cf89ba03 100644 --- a/client/project_domain_delete.go +++ b/client/project_domain_delete.go @@ -25,7 +25,7 @@ func (c *Client) DeleteProjectDomain(ctx context.Context, projectID, domain, tea return err } - tflog.Info(ctx, "deleting project domain", map[string]interface{}{ + tflog.Trace(ctx, "deleting project domain", map[string]interface{}{ "url": url, }) return c.doRequest(req, nil) diff --git a/client/project_domain_get.go b/client/project_domain_get.go index 390cc658..3cb2d863 100644 --- a/client/project_domain_get.go +++ b/client/project_domain_get.go @@ -35,7 +35,7 @@ func (c *Client) GetProjectDomain(ctx context.Context, projectID, domain, teamID return r, err } - tflog.Info(ctx, "getting project domain", map[string]interface{}{ + tflog.Trace(ctx, "getting project domain", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/client/project_domain_update.go b/client/project_domain_update.go index 10e6ccb2..b0e634fd 100644 --- a/client/project_domain_update.go +++ b/client/project_domain_update.go @@ -34,7 +34,7 @@ func (c *Client) UpdateProjectDomain(ctx context.Context, projectID, domain, tea return r, err } - tflog.Info(ctx, "updating project domain", map[string]interface{}{ + tflog.Trace(ctx, "updating project domain", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/project_get.go b/client/project_get.go index 28999a22..bb909912 100644 --- a/client/project_get.go +++ b/client/project_get.go @@ -84,7 +84,7 @@ func (c *Client) GetProject(ctx context.Context, projectID, teamID string, shoul if err != nil { return r, err } - tflog.Info(ctx, "getting project", map[string]interface{}{ + tflog.Trace(ctx, "getting project", map[string]interface{}{ "url": url, "shouldFetchEnvironment": shouldFetchEnvironmentVariables, }) diff --git a/client/project_list.go b/client/project_list.go index a0d2580f..fd7aab48 100644 --- a/client/project_list.go +++ b/client/project_list.go @@ -28,7 +28,7 @@ func (c *Client) ListProjects(ctx context.Context, teamID string) (r []ProjectRe pr := struct { Projects []ProjectResponse `json:"projects"` }{} - tflog.Info(ctx, "listing projects", map[string]interface{}{ + tflog.Trace(ctx, "listing projects", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &pr) diff --git a/client/project_update.go b/client/project_update.go index d3e0b909..a0da6a4c 100644 --- a/client/project_update.go +++ b/client/project_update.go @@ -45,7 +45,7 @@ func (c *Client) UpdateProject(ctx context.Context, projectID, teamID string, re return r, err } - tflog.Info(ctx, "updating project", map[string]interface{}{ + tflog.Trace(ctx, "updating project", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/team_create.go b/client/team_create.go index fe88a00c..6b6be677 100644 --- a/client/team_create.go +++ b/client/team_create.go @@ -35,7 +35,7 @@ func (c *Client) CreateTeam(ctx context.Context, request TeamCreateRequest) (r T return r, err } - tflog.Info(ctx, "creating team", map[string]interface{}{ + tflog.Trace(ctx, "creating team", map[string]interface{}{ "url": url, "payload": payload, }) diff --git a/client/team_delete.go b/client/team_delete.go index ca486e9c..163a7cb0 100644 --- a/client/team_delete.go +++ b/client/team_delete.go @@ -21,7 +21,7 @@ func (c *Client) DeleteTeam(ctx context.Context, teamID string) error { return err } - tflog.Info(ctx, "deleting team", map[string]interface{}{ + tflog.Trace(ctx, "deleting team", map[string]interface{}{ "url": url, }) return c.doRequest(req, nil) diff --git a/client/team_get.go b/client/team_get.go index 9fb03dd0..1503f29d 100644 --- a/client/team_get.go +++ b/client/team_get.go @@ -26,7 +26,7 @@ func (c *Client) GetTeam(ctx context.Context, teamID, slug string) (r TeamRespon return r, err } - tflog.Info(ctx, "getting team", map[string]interface{}{ + tflog.Trace(ctx, "getting team", map[string]interface{}{ "url": url, }) err = c.doRequest(req, &r) diff --git a/vercel/data_source_alias.go b/vercel/data_source_alias.go index 0eda6b09..64e3d772 100644 --- a/vercel/data_source_alias.go +++ b/vercel/data_source_alias.go @@ -81,7 +81,7 @@ func (r dataSourceAlias) Read(ctx context.Context, req datasource.ReadRequest, r } result := convertResponseToAlias(out, config) - tflog.Info(ctx, "read alias", map[string]interface{}{ + tflog.Trace(ctx, "read alias", map[string]interface{}{ "team_id": result.TeamID.Value, "alias": result.Alias.Value, }) diff --git a/vercel/data_source_project.go b/vercel/data_source_project.go index fb134798..42831f9f 100644 --- a/vercel/data_source_project.go +++ b/vercel/data_source_project.go @@ -184,7 +184,7 @@ func (r dataSourceProject) Read(ctx context.Context, req datasource.ReadRequest, } result := convertResponseToProject(out, config.coercedFields(), types.Set{Null: true}) - tflog.Info(ctx, "read project", map[string]interface{}{ + tflog.Trace(ctx, "read project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) diff --git a/vercel/resource_alias.go b/vercel/resource_alias.go index a07a8a35..482d23c1 100644 --- a/vercel/resource_alias.go +++ b/vercel/resource_alias.go @@ -90,7 +90,7 @@ func (r resourceAlias) Create(ctx context.Context, req resource.CreateRequest, r } result := convertResponseToAlias(out, plan) - tflog.Info(ctx, "created alias", map[string]interface{}{ + tflog.Trace(ctx, "created alias", map[string]interface{}{ "team_id": plan.TeamID.Value, "deployment_id": plan.DeploymentID.Value, "alias_id": result.ID.Value, @@ -131,7 +131,7 @@ func (r resourceAlias) Read(ctx context.Context, req resource.ReadRequest, resp } result := convertResponseToAlias(out, state) - tflog.Info(ctx, "read alias", map[string]interface{}{ + tflog.Trace(ctx, "read alias", map[string]interface{}{ "team_id": result.TeamID.Value, "alias_id": result.ID.Value, }) @@ -190,7 +190,7 @@ func (r resourceAlias) Delete(ctx context.Context, req resource.DeleteRequest, r return } - tflog.Info(ctx, "deleted alias", map[string]interface{}{ + tflog.Trace(ctx, "deleted alias", map[string]interface{}{ "team_id": state.TeamID.Value, "alias_id": state.ID.Value, }) diff --git a/vercel/resource_deployment.go b/vercel/resource_deployment.go index a7b80ce1..bf7391ae 100644 --- a/vercel/resource_deployment.go +++ b/vercel/resource_deployment.go @@ -312,7 +312,7 @@ func (r resourceDeployment) Create(ctx context.Context, req resource.CreateReque } result := convertResponseToDeployment(out, plan) - tflog.Info(ctx, "created deployment", map[string]interface{}{ + tflog.Trace(ctx, "created deployment", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -352,7 +352,7 @@ func (r resourceDeployment) Read(ctx context.Context, req resource.ReadRequest, } result := convertResponseToDeployment(out, state) - tflog.Info(ctx, "read deployment", map[string]interface{}{ + tflog.Trace(ctx, "read deployment", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -419,6 +419,6 @@ func (r resourceDeployment) Delete(ctx context.Context, req resource.DeleteReque ) return } - tflog.Info(ctx, fmt.Sprintf("deleted deployment %s", dResp.UID)) + tflog.Trace(ctx, fmt.Sprintf("deleted deployment %s", dResp.UID)) } } diff --git a/vercel/resource_dns_record.go b/vercel/resource_dns_record.go index a1c9e2e8..e6085c19 100644 --- a/vercel/resource_dns_record.go +++ b/vercel/resource_dns_record.go @@ -212,7 +212,7 @@ func (r resourceDNSRecord) Create(ctx context.Context, req resource.CreateReques ) return } - tflog.Info(ctx, "created DNS Record", map[string]interface{}{ + tflog.Trace(ctx, "created DNS Record", map[string]interface{}{ "team_id": result.TeamID, "record_id": result.ID, "domain": result.Domain, @@ -261,7 +261,7 @@ func (r resourceDNSRecord) Read(ctx context.Context, req resource.ReadRequest, r ) return } - tflog.Info(ctx, "read DNS record", map[string]interface{}{ + tflog.Trace(ctx, "read DNS record", map[string]interface{}{ "team_id": result.TeamID, "record_id": result.ID, "domain": result.Domain, @@ -317,7 +317,7 @@ func (r resourceDNSRecord) Update(ctx context.Context, req resource.UpdateReques ) return } - tflog.Info(ctx, "updated DNS record", map[string]interface{}{ + tflog.Trace(ctx, "updated DNS record", map[string]interface{}{ "team_id": result.TeamID, "record_id": result.ID, "domain": result.Domain, @@ -358,7 +358,7 @@ func (r resourceDNSRecord) Delete(ctx context.Context, req resource.DeleteReques return } - tflog.Info(ctx, "delete DNS record", map[string]interface{}{ + tflog.Trace(ctx, "delete DNS record", map[string]interface{}{ "domain": state.Domain, "record_id": state.ID, "team_id": state.TeamID, diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 38171aaa..a8620a81 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -236,7 +236,7 @@ func (r resourceProject) Create(ctx context.Context, req resource.CreateRequest, } result := convertResponseToProject(out, plan.coercedFields(), plan.Environment) - tflog.Info(ctx, "created project", map[string]interface{}{ + tflog.Trace(ctx, "created project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -276,7 +276,7 @@ func (r resourceProject) Read(ctx context.Context, req resource.ReadRequest, res } result := convertResponseToProject(out, state.coercedFields(), state.Environment) - tflog.Info(ctx, "read project", map[string]interface{}{ + tflog.Trace(ctx, "read project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -381,7 +381,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, ) return } - tflog.Info(ctx, "deleted environment variable", map[string]interface{}{ + tflog.Trace(ctx, "deleted environment variable", map[string]interface{}{ "team_id": plan.TeamID.Value, "project_id": plan.ID.Value, "environment_id": v.ID.Value, @@ -403,7 +403,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, ), ) } - tflog.Info(ctx, "upserted environment variable", map[string]interface{}{ + tflog.Trace(ctx, "upserted environment variable", map[string]interface{}{ "team_id": plan.TeamID.Value, "project_id": plan.ID.Value, "environment_id": result.ID, @@ -425,7 +425,7 @@ func (r resourceProject) Update(ctx context.Context, req resource.UpdateRequest, } result := convertResponseToProject(out, plan.coercedFields(), plan.Environment) - tflog.Info(ctx, "updated project", map[string]interface{}{ + tflog.Trace(ctx, "updated project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) @@ -465,7 +465,7 @@ func (r resourceProject) Delete(ctx context.Context, req resource.DeleteRequest, return } - tflog.Info(ctx, "deleted project", map[string]interface{}{ + tflog.Trace(ctx, "deleted project", map[string]interface{}{ "team_id": state.TeamID.Value, "project_id": state.ID.Value, }) @@ -517,7 +517,7 @@ func (r resourceProject) ImportState(ctx context.Context, req resource.ImportSta PublicSource: types.Bool{Null: true}, TeamID: types.String{Value: teamID, Null: teamID == ""}, }, types.Set{Null: true}) - tflog.Info(ctx, "imported project", map[string]interface{}{ + tflog.Trace(ctx, "imported project", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ID.Value, }) diff --git a/vercel/resource_project_domain.go b/vercel/resource_project_domain.go index bdcca3e3..042d14b4 100644 --- a/vercel/resource_project_domain.go +++ b/vercel/resource_project_domain.go @@ -126,7 +126,7 @@ func (r resourceProjectDomain) Create(ctx context.Context, req resource.CreateRe } result := convertResponseToProjectDomain(out, plan.TeamID) - tflog.Info(ctx, "added domain to project", map[string]interface{}{ + tflog.Trace(ctx, "added domain to project", map[string]interface{}{ "project_id": result.ProjectID.Value, "domain": result.Domain.Value, "team_id": result.TeamID.Value, @@ -167,7 +167,7 @@ func (r resourceProjectDomain) Read(ctx context.Context, req resource.ReadReques } result := convertResponseToProjectDomain(out, state.TeamID) - tflog.Info(ctx, "read project domain", map[string]interface{}{ + tflog.Trace(ctx, "read project domain", map[string]interface{}{ "project_id": result.ProjectID.Value, "domain": result.Domain.Value, "team_id": result.TeamID.Value, @@ -209,7 +209,7 @@ func (r resourceProjectDomain) Update(ctx context.Context, req resource.UpdateRe } result := convertResponseToProjectDomain(out, plan.TeamID) - tflog.Info(ctx, "update project domain", map[string]interface{}{ + tflog.Trace(ctx, "update project domain", map[string]interface{}{ "project_id": result.ProjectID.Value, "domain": result.Domain.Value, "team_id": result.TeamID.Value, @@ -251,7 +251,7 @@ func (r resourceProjectDomain) Delete(ctx context.Context, req resource.DeleteRe return } - tflog.Info(ctx, "delete project domain", map[string]interface{}{ + tflog.Trace(ctx, "delete project domain", map[string]interface{}{ "project_id": state.ProjectID.Value, "domain": state.Domain.Value, "team_id": state.TeamID.Value, @@ -302,7 +302,7 @@ func (r resourceProjectDomain) ImportState(ctx context.Context, req resource.Imp stringTypeTeamID.Null = true } result := convertResponseToProjectDomain(out, stringTypeTeamID) - tflog.Info(ctx, "imported project domain", map[string]interface{}{ + tflog.Trace(ctx, "imported project domain", map[string]interface{}{ "project_id": result.ProjectID.Value, "domain": result.Domain.Value, "team_id": result.TeamID.Value, diff --git a/vercel/resource_project_environment_variable.go b/vercel/resource_project_environment_variable.go index 03b3cce3..f96f30c6 100644 --- a/vercel/resource_project_environment_variable.go +++ b/vercel/resource_project_environment_variable.go @@ -126,7 +126,7 @@ func (r resourceProjectEnvironmentVariable) Create(ctx context.Context, req reso result := convertResponseToProjectEnvironmentVariable(response, plan.TeamID, plan.ProjectID) - tflog.Info(ctx, "created project environment variable", map[string]interface{}{ + tflog.Trace(ctx, "created project environment variable", map[string]interface{}{ "id": result.ID.Value, "team_id": result.TeamID.Value, "project_id": result.ProjectID.Value, @@ -168,7 +168,7 @@ func (r resourceProjectEnvironmentVariable) Read(ctx context.Context, req resour } result := convertResponseToProjectEnvironmentVariable(out, state.TeamID, state.ProjectID) - tflog.Info(ctx, "read project environment variable", map[string]interface{}{ + tflog.Trace(ctx, "read project environment variable", map[string]interface{}{ "id": result.ID.Value, "team_id": result.TeamID.Value, "project_id": result.ProjectID.Value, @@ -201,7 +201,7 @@ func (r resourceProjectEnvironmentVariable) Update(ctx context.Context, req reso result := convertResponseToProjectEnvironmentVariable(response, plan.TeamID, plan.ProjectID) - tflog.Info(ctx, "updated project environment variable", map[string]interface{}{ + tflog.Trace(ctx, "updated project environment variable", map[string]interface{}{ "id": result.ID.Value, "team_id": result.TeamID.Value, "project_id": result.ProjectID.Value, @@ -239,7 +239,7 @@ func (r resourceProjectEnvironmentVariable) Delete(ctx context.Context, req reso return } - tflog.Info(ctx, "deleted project environment variable", map[string]interface{}{ + tflog.Trace(ctx, "deleted project environment variable", map[string]interface{}{ "id": state.ID.Value, "team_id": state.TeamID.Value, "project_id": state.ProjectID.Value, @@ -286,7 +286,7 @@ func (r resourceProjectEnvironmentVariable) ImportState(ctx context.Context, req } result := convertResponseToProjectEnvironmentVariable(out, types.String{Value: teamID, Null: teamID == ""}, types.String{Value: projectID}) - tflog.Info(ctx, "imported project environment variable", map[string]interface{}{ + tflog.Trace(ctx, "imported project environment variable", map[string]interface{}{ "team_id": result.TeamID.Value, "project_id": result.ProjectID.Value, "env_id": result.ID.Value,