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

Omit null environment variables in vercel_deployment #96

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions vercel/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ func getPrebuiltBuildsFile(files []client.DeploymentFile) (string, bool) {
return "", false
}

func filterNullFromMap(m map[string]types.String) map[string]string {
out := map[string]string{}
for k, v := range m {
if !v.IsNull() {
out[k] = v.ValueString()
}
}
return out
}

// Create will create a deployment within Vercel. This is done by first attempting to trigger a deployment, seeing what
// files are required, uploading those files, and then attempting to create a deployment again.
// This is called automatically by the provider when a new resource should be created.
Expand Down Expand Up @@ -281,7 +291,7 @@ func (r *deploymentResource) Create(ctx context.Context, req resource.CreateRequ
return
}

var environment map[string]string
var environment map[string]types.String
diags = plan.Environment.ElementsAs(ctx, &environment, false)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
Expand All @@ -294,7 +304,7 @@ func (r *deploymentResource) Create(ctx context.Context, req resource.CreateRequ
}
cdr := client.CreateDeploymentRequest{
Files: files,
Environment: environment,
Environment: filterNullFromMap(environment),
ProjectID: plan.ProjectID.ValueString(),
ProjectSettings: plan.ProjectSettings.toRequest(),
Target: target,
Expand Down
5 changes: 3 additions & 2 deletions vercel/resource_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func TestAcc_DeploymentWithEnvironment(t *testing.T) {
{
Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(), `environment = {
FOO = "baz",
BAR = "qux"
BAR = "qux",
BAZ = null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check that BAZ is not present on the output? I suppose this test would fail otherwise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test failed before the changes b/c of the deserialization issue. It's a bit rubbish but the test helpers don't give a nice way to check for a null value on the output. I think just checking that it doesn't cause the provider to panic is as good as we can do (which is the purpose of this).

}`),
Check: resource.ComposeAggregateTestCheckFunc(
testAccDeploymentExists("vercel_deployment.test", ""),
Expand Down Expand Up @@ -286,7 +287,7 @@ resource "vercel_deployment" "test" {
project_id = vercel_project.test.id
%[2]s

files = data.vercel_prebuilt_project.test.output
files = data.vercel_prebuilt_project.test.output
path_prefix = data.vercel_prebuilt_project.test.path
}
`, projectSuffix, teamID)
Expand Down