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

Don't fetch env variables on project import #73

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 3 commits into from
Sep 9, 2022
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
2 changes: 1 addition & 1 deletion vercel/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (r resourceProject) ImportState(ctx context.Context, req resource.ImportSta
)
}

out, err := r.p.client.GetProject(ctx, projectID, teamID, true)
out, err := r.p.client.GetProject(ctx, projectID, teamID, false)
if err != nil {
resp.Diagnostics.AddError(
"Error reading project",
Expand Down
41 changes: 39 additions & 2 deletions vercel/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ func TestAcc_ProjectWithGitRepository(t *testing.T) {
})
}

func getProjectImportID(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 rs.Primary.ID, nil
}
return fmt.Sprintf("%s/%s", rs.Primary.Attributes["team_id"], rs.Primary.ID), nil
}
}

func TestAcc_ProjectImport(t *testing.T) {
projectSuffix := acctest.RandString(16)
resource.Test(t, resource.TestCase{
Expand All @@ -148,15 +166,16 @@ func TestAcc_ProjectImport(t *testing.T) {
CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()),
Steps: []resource.TestStep{
{
Config: testAccProjectConfig(projectSuffix, ""),
Config: projectConfigWithoutEnv(projectSuffix, teamIDConfig()),
Check: resource.ComposeAggregateTestCheckFunc(
testAccProjectExists("vercel_project.test", ""),
testAccProjectExists("vercel_project.test", testTeam()),
),
},
{
ResourceName: "vercel_project.test",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: getProjectImportID("vercel_project.test"),
},
},
})
Expand Down Expand Up @@ -294,6 +313,24 @@ resource "vercel_project" "test_git" {
`, projectSuffix, teamID, testGithubRepo())
}

func projectConfigWithoutEnv(projectSuffix, teamID string) string {
return fmt.Sprintf(`
resource "vercel_project" "test" {
name = "test-acc-project-%s"
%s
build_command = "npm run build"
dev_command = "npm run serve"
ignore_command = "echo 'wat'"
serverless_function_region = "syd1"
framework = "nextjs"
install_command = "npm install"
output_directory = ".output"
public_source = true
root_directory = "ui/src"
}
`, projectSuffix, teamID)
}

func testAccProjectConfig(projectSuffix, teamID string) string {
return fmt.Sprintf(`
resource "vercel_project" "test" {
Expand Down