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

Upgrade terraform framework to v0.8.0 #31

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 2 commits into from
May 12, 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
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/vercel/terraform-provider-vercel
go 1.17

require (
github.com/hashicorp/terraform-plugin-framework v0.6.1-0.20220311205704-e0e806bddeca
github.com/hashicorp/terraform-plugin-go v0.8.0
github.com/hashicorp/terraform-plugin-log v0.3.0
github.com/hashicorp/terraform-plugin-framework v0.8.0
github.com/hashicorp/terraform-plugin-go v0.9.0
github.com/hashicorp/terraform-plugin-log v0.4.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
)
Expand All @@ -17,22 +17,22 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.3 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/go-plugin v1.4.4 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.4.0 // indirect
github.com/hashicorp/hc-install v0.3.1 // indirect
github.com/hashicorp/hcl/v2 v2.11.1 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.15.0 // indirect
github.com/hashicorp/terraform-json v0.13.0 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20210816115301-cb2034eba045 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20220422185603-6772e136ec01 // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
Expand All @@ -45,14 +45,14 @@ require (
github.com/oklog/run v1.1.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
golang.org/x/net v0.0.0-20220111093109-d55c255bac03 // indirect
golang.org/x/sys v0.0.0-20220111092808-5a964db01320 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3 // indirect
google.golang.org/grpc v1.46.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)
65 changes: 35 additions & 30 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/vercel/terraform-provider-vercel/vercel"
)

func main() {
err := tfsdk.Serve(context.Background(), vercel.New, tfsdk.ServeOpts{
Name: "registry.terraform.io/vercel/vercel",
err := providerserver.Serve(context.Background(), vercel.New, providerserver.ServeOpts{
Address: "registry.terraform.io/vercel/vercel",
})
if err != nil {
log.Fatalf("unable to serve provider: %s", err)
Expand Down
6 changes: 2 additions & 4 deletions vercel/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/vercel/terraform-provider-vercel/client"
"github.com/vercel/terraform-provider-vercel/vercel"
)

var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"vercel": func() (tfprotov6.ProviderServer, error) {
return tfsdk.NewProtocol6Server(vercel.New()), nil
},
"vercel": providerserver.NewProtocol6WithError(vercel.New()),
}

func testAccPreCheck(t *testing.T) {
Expand Down
9 changes: 0 additions & 9 deletions vercel/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,5 @@ func (r resourceDeployment) Delete(ctx context.Context, req tfsdk.DeleteResource
return
}
tflog.Trace(ctx, fmt.Sprintf("deleted deployment %s", dResp.UID))
} else {
tflog.Trace(ctx, fmt.Sprintf("deployment %s deleted from the Terraform state", state.ID.Value))
}
resp.State.RemoveResource(ctx)
}

// ImportState is not implemented as it is not possible to get all the required information for a
// Deployment resource from the vercel API.
func (r resourceDeployment) ImportState(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) {
tfsdk.ResourceImportStateNotImplemented(ctx, "", resp)
}
8 changes: 4 additions & 4 deletions vercel/resource_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestAcc_DeploymentWithDeleteOnDestroy(t *testing.T) {
t.Parallel()
projectSuffix := acctest.RandString(16)
extraConfig := "delete_on_destroy = true"
deploymentId := ""
deploymentID := ""
storeDeploymentId := func(n string, did *string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand All @@ -176,7 +176,7 @@ func TestAcc_DeploymentWithDeleteOnDestroy(t *testing.T) {
}
testDeploymentGone := func() resource.TestCheckFunc {
return func(*terraform.State) error {
_, err := testClient().GetDeployment(context.TODO(), deploymentId, "")
_, err := testClient().GetDeployment(context.TODO(), deploymentID, "")
if err == nil {
return fmt.Errorf("expected not_found error, but got no error")
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestAcc_DeploymentWithDeleteOnDestroy(t *testing.T) {
Config: testAccDeploymentConfig(projectSuffix, "", extraConfig),
Check: resource.ComposeAggregateTestCheckFunc(
testAccDeploymentExists("vercel_deployment.test", ""),
storeDeploymentId("vercel_deployment.test", &deploymentId),
storeDeploymentId("vercel_deployment.test", &deploymentID),
),
},
{
Expand Down Expand Up @@ -332,7 +332,7 @@ data "vercel_file" "index" {

resource "vercel_deployment" "test" {
project_id = vercel_project.test.id
files = data.vercel_file.index.file
files = data.vercel_file.index.file
production = true
project_settings = {
root_directory = "vercel/example"
Expand Down
2 changes: 0 additions & 2 deletions vercel/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ func (r resourceProject) Delete(ctx context.Context, req tfsdk.DeleteResourceReq
err := r.p.client.DeleteProject(ctx, state.ID.Value, state.TeamID.Value)
var apiErr client.APIError
if err != nil && errors.As(err, &apiErr) && apiErr.StatusCode == 404 {
resp.State.RemoveResource(ctx)
return
}
if err != nil {
Expand All @@ -408,7 +407,6 @@ func (r resourceProject) Delete(ctx context.Context, req tfsdk.DeleteResourceReq
"team_id": state.TeamID.Value,
"project_id": state.ID.Value,
})
resp.State.RemoveResource(ctx)
}

// splitID is a helper function for splitting an import ID into the corresponding parts.
Expand Down
1 change: 0 additions & 1 deletion vercel/resource_project_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ func (r resourceProjectDomain) Delete(ctx context.Context, req tfsdk.DeleteResou
"domain": state.Domain.Value,
"team_id": state.TeamID.Value,
})
resp.State.RemoveResource(ctx)
}

// splitProjectDomainID is a helper function for splitting an import ID into the corresponding parts.
Expand Down
113 changes: 56 additions & 57 deletions vercel/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,63 @@ import (
)

func TestAcc_Project(t *testing.T) {
t.Parallel()
testAccProject(t, "")
}
tests := map[string]string{
"personal scope": "",
"team scope": os.Getenv("VERCEL_TERRAFORM_TESTING_TEAM"),
}

func TestAcc_ProjectWithTeamID(t *testing.T) {
t.Parallel()
testAccProject(t, os.Getenv("VERCEL_TERRAFORM_TESTING_TEAM"))
for name, teamID := range tests {
t.Run(name, func(t *testing.T) {
extraConfig := ""
testTeamID := resource.TestCheckNoResourceAttr("vercel_project.test", "team_id")
if teamID != "" {
extraConfig = fmt.Sprintf(`team_id = "%s"`, teamID)
testTeamID = resource.TestCheckResourceAttr("vercel_project.test", "team_id", teamID)
}
projectSuffix := acctest.RandString(16)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
CheckDestroy: testAccProjectDestroy("vercel_project.test", teamID),
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccProjectConfig(projectSuffix, extraConfig),
Check: resource.ComposeAggregateTestCheckFunc(
testAccProjectExists("vercel_project.test", teamID),
testTeamID,
resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-project-%s", projectSuffix)),
resource.TestCheckResourceAttr("vercel_project.test", "build_command", "npm run build"),
resource.TestCheckResourceAttr("vercel_project.test", "dev_command", "npm run serve"),
resource.TestCheckResourceAttr("vercel_project.test", "framework", "nextjs"),
resource.TestCheckResourceAttr("vercel_project.test", "install_command", "npm install"),
resource.TestCheckResourceAttr("vercel_project.test", "output_directory", ".output"),
resource.TestCheckResourceAttr("vercel_project.test", "public_source", "true"),
resource.TestCheckResourceAttr("vercel_project.test", "root_directory", "ui/src"),
resource.TestCheckTypeSetElemNestedAttrs("vercel_project.test", "environment.*", map[string]string{
"key": "foo",
"value": "bar",
}),
resource.TestCheckTypeSetElemAttr("vercel_project.test", "environment.0.target.*", "production"),
),
},
// Update testing
{
Config: testAccProjectConfigUpdated(projectSuffix, extraConfig),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-two-%s", projectSuffix)),
resource.TestCheckNoResourceAttr("vercel_project.test", "build_command"),
resource.TestCheckTypeSetElemNestedAttrs("vercel_project.test", "environment.*", map[string]string{
"key": "bar",
"value": "baz",
}),
),
},
},
})
})
}
}

func TestAcc_ProjectAddingEnvAfterInitialCreation(t *testing.T) {
Expand Down Expand Up @@ -150,57 +200,6 @@ func testAccProjectDestroy(n, teamID string) resource.TestCheckFunc {
}
}

func testAccProject(t *testing.T, tid string) {
extraConfig := ""
testTeamID := resource.TestCheckNoResourceAttr("vercel_project.test", "team_id")
if tid != "" {
extraConfig = fmt.Sprintf(`team_id = "%s"`, tid)
testTeamID = resource.TestCheckResourceAttr("vercel_project.test", "team_id", tid)
}
projectSuffix := acctest.RandString(16)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
CheckDestroy: testAccProjectDestroy("vercel_project.test", tid),
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccProjectConfig(projectSuffix, extraConfig),
Check: resource.ComposeAggregateTestCheckFunc(
testAccProjectExists("vercel_project.test", tid),
testTeamID,
resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-project-%s", projectSuffix)),
resource.TestCheckResourceAttr("vercel_project.test", "build_command", "npm run build"),
resource.TestCheckResourceAttr("vercel_project.test", "dev_command", "npm run serve"),
resource.TestCheckResourceAttr("vercel_project.test", "framework", "nextjs"),
resource.TestCheckResourceAttr("vercel_project.test", "install_command", "npm install"),
resource.TestCheckResourceAttr("vercel_project.test", "output_directory", ".output"),
resource.TestCheckResourceAttr("vercel_project.test", "public_source", "true"),
resource.TestCheckResourceAttr("vercel_project.test", "root_directory", "ui/src"),
resource.TestCheckTypeSetElemNestedAttrs("vercel_project.test", "environment.*", map[string]string{
"key": "foo",
"value": "bar",
}),
resource.TestCheckTypeSetElemAttr("vercel_project.test", "environment.0.target.*", "production"),
),
},
// Update testing
{
Config: testAccProjectConfigUpdated(projectSuffix, extraConfig),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-two-%s", projectSuffix)),
resource.TestCheckNoResourceAttr("vercel_project.test", "build_command"),
resource.TestCheckTypeSetElemNestedAttrs("vercel_project.test", "environment.*", map[string]string{
"key": "bar",
"value": "baz",
}),
),
},
},
})
}

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