diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 81983ff..fc37ecf 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -13,12 +13,12 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
- go-version: 1.23.2
+ go-version: "1.24.1"
- run: go generate ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
- version: v1.60.2
+ version: v1.64.7
args: --verbose --timeout 20m --max-same-issues=30 --allow-parallel-runners
go-tidy:
runs-on: ubuntu-latest
@@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
- go-version: 1.23.2
+ go-version: "1.24.1"
- name: Verify tidy
run: |
go mod tidy
@@ -40,7 +40,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
- go-version: 1.23.2
+ go-version: "1.24.1"
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: "1.3.*"
diff --git a/README.md b/README.md
index 0512525..41d31df 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ using Terraform Bytebase Provider to prepare those instances ready for applicati
- [Go](https://golang.org/doc/install) (1.19 or later)
- [Terraform](https://developer.hashicorp.com/terraform/downloads?product_intent=terraform) (1.3.5 or later)
-- [Bytebase](https://github.com/bytebase/bytebase) (1.11.0 or later)
+- [Bytebase](https://github.com/bytebase/bytebase) (3.5.0 or later)
> If you have problems running `terraform` in MacOS with Apple Silicon, you can following https://stackoverflow.com/questions/66281882/how-can-i-get-terraform-init-to-run-on-my-apple-silicon-macbook-pro-for-the-go and use the `tfenv`.
diff --git a/VERSION b/VERSION
index 450f88e..ace256e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.0.20
\ No newline at end of file
+1.0.21
\ No newline at end of file
diff --git a/api/client.go b/api/client.go
index 08cdd3a..d5a88bf 100644
--- a/api/client.go
+++ b/api/client.go
@@ -69,8 +69,8 @@ type Client interface {
// Project
// GetProject gets the project by project full name.
GetProject(ctx context.Context, projectName string) (*v1pb.Project, error)
- // ListProject list the projects,
- ListProject(ctx context.Context, showDeleted bool) (*v1pb.ListProjectsResponse, error)
+ // ListProject list all projects,
+ ListProject(ctx context.Context, showDeleted bool) ([]*v1pb.Project, error)
// CreateProject creates the project.
CreateProject(ctx context.Context, projectID string, project *v1pb.Project) (*v1pb.Project, error)
// UpdateProject updates the project.
@@ -96,33 +96,9 @@ type Client interface {
// ParseExpression parse the expression string.
ParseExpression(ctx context.Context, expression string) (*v1alpha1.Expr, error)
- // VCS Provider
- // ListVCSProvider will returns all vcs providers.
- ListVCSProvider(ctx context.Context) (*v1pb.ListVCSProvidersResponse, error)
- // GetVCSProvider gets the vcs by full name.
- GetVCSProvider(ctx context.Context, name string) (*v1pb.VCSProvider, error)
- // CreateVCSProvider creates the vcs provider.
- CreateVCSProvider(ctx context.Context, vcsID string, vcs *v1pb.VCSProvider) (*v1pb.VCSProvider, error)
- // UpdateVCSProvider updates the vcs provider.
- UpdateVCSProvider(ctx context.Context, patch *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSProvider, error)
- // DeleteVCSProvider deletes the vcs provider.
- DeleteVCSProvider(ctx context.Context, name string) error
-
- // VCS Connector
- // ListVCSConnector will returns all vcs connector in a project.
- ListVCSConnector(ctx context.Context, projectName string) (*v1pb.ListVCSConnectorsResponse, error)
- // GetVCSConnector gets the vcs connector by full name.
- GetVCSConnector(ctx context.Context, name string) (*v1pb.VCSConnector, error)
- // CreateVCSConnector creates the vcs connector in a project.
- CreateVCSConnector(ctx context.Context, projectName, connectorID string, connector *v1pb.VCSConnector) (*v1pb.VCSConnector, error)
- // UpdateVCSConnector updates the vcs connector.
- UpdateVCSConnector(ctx context.Context, patch *v1pb.VCSConnector, updateMasks []string) (*v1pb.VCSConnector, error)
- // DeleteVCSConnector deletes the vcs provider.
- DeleteVCSConnector(ctx context.Context, name string) error
-
// User
// ListUser list all users.
- ListUser(ctx context.Context, showDeleted bool) (*v1pb.ListUsersResponse, error)
+ ListUser(ctx context.Context, showDeleted bool) ([]*v1pb.User, error)
// CreateUser creates the user.
CreateUser(ctx context.Context, user *v1pb.User) (*v1pb.User, error)
// GetUser gets the user by name.
diff --git a/api/setting.go b/api/setting.go
index b71ca0e..9cc1c36 100644
--- a/api/setting.go
+++ b/api/setting.go
@@ -50,6 +50,4 @@ const (
ApprovalNodeTypeGroup ApprovalNodeType = "GROUP"
// ApprovalNodeTypeRole means the approval node is a role, the value should be role fullname.
ApprovalNodeTypeRole ApprovalNodeType = "ROLE"
- // ApprovalNodeTypeExternalNodeID means the approval node is a external node, the value should be the node id.
- ApprovalNodeTypeExternalNodeID ApprovalNodeType = "EXTERNAL_NODE"
)
diff --git a/client/project.go b/client/project.go
index b7daa92..eaf2b3e 100644
--- a/client/project.go
+++ b/client/project.go
@@ -4,9 +4,12 @@ import (
"context"
"fmt"
"net/http"
+ "net/url"
"strings"
+ "time"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
+ "github.com/hashicorp/terraform-plugin-log/tflog"
"google.golang.org/protobuf/encoding/protojson"
)
@@ -66,9 +69,50 @@ func (c *client) SetProjectIAMPolicy(ctx context.Context, projectName string, up
return &res, nil
}
-// ListProject list the projects.
-func (c *client) ListProject(ctx context.Context, showDeleted bool) (*v1pb.ListProjectsResponse, error) {
- req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/projects?showDeleted=%v", c.url, c.version, showDeleted), nil)
+// ListProject list all projects.
+func (c *client) ListProject(ctx context.Context, showDeleted bool) ([]*v1pb.Project, error) {
+ res := []*v1pb.Project{}
+ pageToken := ""
+ startTime := time.Now()
+
+ for {
+ startTimePerPage := time.Now()
+ resp, err := c.listProjectPerPage(ctx, showDeleted, pageToken, 500)
+ if err != nil {
+ return nil, err
+ }
+ res = append(res, resp.Projects...)
+ tflog.Debug(ctx, "[list project per page]", map[string]interface{}{
+ "count": len(resp.Projects),
+ "ms": time.Since(startTimePerPage).Milliseconds(),
+ })
+
+ pageToken = resp.NextPageToken
+ if pageToken == "" {
+ break
+ }
+ }
+
+ tflog.Debug(ctx, "[list project]", map[string]interface{}{
+ "total": len(res),
+ "ms": time.Since(startTime).Milliseconds(),
+ })
+
+ return res, nil
+}
+
+// listProjectPerPage list the projects.
+func (c *client) listProjectPerPage(ctx context.Context, showDeleted bool, pageToken string, pageSize int) (*v1pb.ListProjectsResponse, error) {
+ requestURL := fmt.Sprintf(
+ "%s/%s/projects?showDeleted=%v&page_size=%d&page_token=%s",
+ c.url,
+ c.version,
+ showDeleted,
+ pageSize,
+ url.QueryEscape(pageToken),
+ )
+
+ req, err := http.NewRequestWithContext(ctx, "GET", requestURL, nil)
if err != nil {
return nil, err
}
diff --git a/client/user.go b/client/user.go
index 0b72705..acd3f76 100644
--- a/client/user.go
+++ b/client/user.go
@@ -4,15 +4,59 @@ import (
"context"
"fmt"
"net/http"
+ "net/url"
"strings"
+ "time"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
+ "github.com/hashicorp/terraform-plugin-log/tflog"
"google.golang.org/protobuf/encoding/protojson"
)
// ListUser list all users.
-func (c *client) ListUser(ctx context.Context, showDeleted bool) (*v1pb.ListUsersResponse, error) {
- req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/users?showDeleted=%v", c.url, c.version, showDeleted), nil)
+func (c *client) ListUser(ctx context.Context, showDeleted bool) ([]*v1pb.User, error) {
+ res := []*v1pb.User{}
+ pageToken := ""
+ startTime := time.Now()
+
+ for {
+ startTimePerPage := time.Now()
+ resp, err := c.listUserPerPage(ctx, showDeleted, pageToken, 500)
+ if err != nil {
+ return nil, err
+ }
+ res = append(res, resp.Users...)
+ tflog.Debug(ctx, "[list user per page]", map[string]interface{}{
+ "count": len(resp.Users),
+ "ms": time.Since(startTimePerPage).Milliseconds(),
+ })
+
+ pageToken = resp.NextPageToken
+ if pageToken == "" {
+ break
+ }
+ }
+
+ tflog.Debug(ctx, "[list user]", map[string]interface{}{
+ "total": len(res),
+ "ms": time.Since(startTime).Milliseconds(),
+ })
+
+ return res, nil
+}
+
+// listUserPerPage list the users.
+func (c *client) listUserPerPage(ctx context.Context, showDeleted bool, pageToken string, pageSize int) (*v1pb.ListUsersResponse, error) {
+ requestURL := fmt.Sprintf(
+ "%s/%s/users?showDeleted=%v&page_size=%d&page_token=%s",
+ c.url,
+ c.version,
+ showDeleted,
+ pageSize,
+ url.QueryEscape(pageToken),
+ )
+
+ req, err := http.NewRequestWithContext(ctx, "GET", requestURL, nil)
if err != nil {
return nil, err
}
diff --git a/client/vcs.go b/client/vcs.go
deleted file mode 100644
index 2edcfcd..0000000
--- a/client/vcs.go
+++ /dev/null
@@ -1,173 +0,0 @@
-package client
-
-import (
- "context"
- "fmt"
- "net/http"
- "strings"
-
- v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
- "google.golang.org/protobuf/encoding/protojson"
-)
-
-// ListVCSProvider will returns all vcs providers.
-func (c *client) ListVCSProvider(ctx context.Context) (*v1pb.ListVCSProvidersResponse, error) {
- req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/vcsProviders", c.url, c.version), nil)
- if err != nil {
- return nil, err
- }
-
- body, err := c.doRequest(req)
- if err != nil {
- return nil, err
- }
-
- var res v1pb.ListVCSProvidersResponse
- if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
- return nil, err
- }
-
- return &res, nil
-}
-
-// GetVCSProvider gets the vcs by full name.
-func (c *client) GetVCSProvider(ctx context.Context, name string) (*v1pb.VCSProvider, error) {
- body, err := c.getResource(ctx, name)
- if err != nil {
- return nil, err
- }
-
- var res v1pb.VCSProvider
- if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
- return nil, err
- }
-
- return &res, nil
-}
-
-// CreateVCSProvider creates the vcs provider.
-func (c *client) CreateVCSProvider(ctx context.Context, vcsID string, vcs *v1pb.VCSProvider) (*v1pb.VCSProvider, error) {
- payload, err := protojson.Marshal(vcs)
- if err != nil {
- return nil, err
- }
-
- req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/%s/vcsProviders?vcsProviderId=%s", c.url, c.version, vcsID), strings.NewReader(string(payload)))
-
- if err != nil {
- return nil, err
- }
-
- body, err := c.doRequest(req)
- if err != nil {
- return nil, err
- }
-
- var res v1pb.VCSProvider
- if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
- return nil, err
- }
-
- return &res, nil
-}
-
-// UpdateVCSProvider updates the vcs provider.
-func (c *client) UpdateVCSProvider(ctx context.Context, patch *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSProvider, error) {
- body, err := c.updateResource(ctx, patch.Name, patch, updateMasks, false /* allow missing = false*/)
- if err != nil {
- return nil, err
- }
-
- var res v1pb.VCSProvider
- if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
- return nil, err
- }
-
- return &res, nil
-}
-
-// DeleteVCSProvider deletes the vcs provider.
-func (c *client) DeleteVCSProvider(ctx context.Context, name string) error {
- return c.deleteResource(ctx, name)
-}
-
-// ListVCSConnector will returns all vcs connector in a project.
-func (c *client) ListVCSConnector(ctx context.Context, projectName string) (*v1pb.ListVCSConnectorsResponse, error) {
- req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s/vcsConnectors", c.url, c.version, projectName), nil)
- if err != nil {
- return nil, err
- }
-
- body, err := c.doRequest(req)
- if err != nil {
- return nil, err
- }
-
- var res v1pb.ListVCSConnectorsResponse
- if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
- return nil, err
- }
-
- return &res, nil
-}
-
-// GetVCSConnector gets the vcs connector by full name.
-func (c *client) GetVCSConnector(ctx context.Context, name string) (*v1pb.VCSConnector, error) {
- body, err := c.getResource(ctx, name)
- if err != nil {
- return nil, err
- }
-
- var res v1pb.VCSConnector
- if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
- return nil, err
- }
-
- return &res, nil
-}
-
-// CreateVCSConnector creates the vcs connector in a project.
-func (c *client) CreateVCSConnector(ctx context.Context, projectName, connectorID string, connector *v1pb.VCSConnector) (*v1pb.VCSConnector, error) {
- payload, err := protojson.Marshal(connector)
- if err != nil {
- return nil, err
- }
-
- req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/%s/%s/vcsConnectors?vcsConnectorId=%s", c.url, c.version, projectName, connectorID), strings.NewReader(string(payload)))
-
- if err != nil {
- return nil, err
- }
-
- body, err := c.doRequest(req)
- if err != nil {
- return nil, err
- }
-
- var res v1pb.VCSConnector
- if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
- return nil, err
- }
-
- return &res, nil
-}
-
-// UpdateVCSConnector updates the vcs connector.
-func (c *client) UpdateVCSConnector(ctx context.Context, patch *v1pb.VCSConnector, updateMasks []string) (*v1pb.VCSConnector, error) {
- body, err := c.updateResource(ctx, patch.Name, patch, updateMasks, false /* allow missing = false*/)
- if err != nil {
- return nil, err
- }
-
- var res v1pb.VCSConnector
- if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
- return nil, err
- }
-
- return &res, nil
-}
-
-// DeleteVCSConnector deletes the vcs provider.
-func (c *client) DeleteVCSConnector(ctx context.Context, name string) error {
- return c.deleteResource(ctx, name)
-}
diff --git a/docs/data-sources/database.md b/docs/data-sources/database.md
index f5fd373..45e545b 100644
--- a/docs/data-sources/database.md
+++ b/docs/data-sources/database.md
@@ -27,8 +27,8 @@ The database data source.
- `labels` (Map of String) The deployment and policy control labels.
- `project` (String) The project full name for the database in projects/{project} format.
- `schema_version` (String) The version of database schema.
+- `state` (String) The existence of a database.
- `successful_sync_time` (String) The latest synchronization time.
-- `sync_state` (String) The existence of a database on latest sync.
### Nested Schema for `catalog`
diff --git a/docs/data-sources/database_list.md b/docs/data-sources/database_list.md
index af3b540..6ffe69b 100644
--- a/docs/data-sources/database_list.md
+++ b/docs/data-sources/database_list.md
@@ -34,7 +34,7 @@ Read-Only:
- `name` (String)
- `project` (String)
- `schema_version` (String)
+- `state` (String)
- `successful_sync_time` (String)
-- `sync_state` (String)
diff --git a/docs/data-sources/project.md b/docs/data-sources/project.md
index 18b065d..4e07b32 100644
--- a/docs/data-sources/project.md
+++ b/docs/data-sources/project.md
@@ -32,7 +32,6 @@ The project data source.
- `postgres_database_tenant_mode` (Boolean) Whether to enable the database tenant mode for PostgreSQL. If enabled, the issue will be created with the pre-appended "set role " statement.
- `skip_backup_errors` (Boolean) Whether to skip backup errors and continue the data migration.
- `title` (String) The project title.
-- `workflow` (String) The project workflow.
### Nested Schema for `members`
diff --git a/docs/data-sources/project_list.md b/docs/data-sources/project_list.md
index 4c8701e..e1c9580 100644
--- a/docs/data-sources/project_list.md
+++ b/docs/data-sources/project_list.md
@@ -40,7 +40,6 @@ Read-Only:
- `resource_id` (String)
- `skip_backup_errors` (Boolean)
- `title` (String)
-- `workflow` (String)
### Nested Schema for `projects.members`
diff --git a/docs/data-sources/vcs_connector.md b/docs/data-sources/vcs_connector.md
deleted file mode 100644
index 9a69d65..0000000
--- a/docs/data-sources/vcs_connector.md
+++ /dev/null
@@ -1,39 +0,0 @@
----
-# generated by https://github.com/hashicorp/terraform-plugin-docs
-page_title: "bytebase_vcs_connector Data Source - terraform-provider-bytebase"
-subcategory: ""
-description: |-
- The vcs connector data source.
----
-
-# bytebase_vcs_connector (Data Source)
-
-The vcs connector data source.
-
-
-
-
-## Schema
-
-### Required
-
-- `project` (String) The project name in projects/{resource id} format.
-- `resource_id` (String) The vcs connector unique resource id.
-
-### Optional
-
-- `database_group` (String) Apply changes to the database group.
-
-### Read-Only
-
-- `id` (String) The ID of this resource.
-- `name` (String) The vcs connector full name in projects/{project}/vcsConnector/{resource id} format.
-- `repository_branch` (String) The connected repository branch in vcs provider.
-- `repository_directory` (String) The connected repository directory in vcs provider.
-- `repository_id` (String) The connected repository id in vcs provider.
-- `repository_path` (String) The connected repository path in vcs provider.
-- `repository_url` (String) The connected repository url in vcs provider.
-- `title` (String) The vcs connector title.
-- `vcs_provider` (String) The vcs provider full name in vcsProviders/{resource id} format.
-
-
diff --git a/docs/data-sources/vcs_connector_list.md b/docs/data-sources/vcs_connector_list.md
deleted file mode 100644
index 18afc40..0000000
--- a/docs/data-sources/vcs_connector_list.md
+++ /dev/null
@@ -1,44 +0,0 @@
----
-# generated by https://github.com/hashicorp/terraform-plugin-docs
-page_title: "bytebase_vcs_connector_list Data Source - terraform-provider-bytebase"
-subcategory: ""
-description: |-
- The vcs connector data source list.
----
-
-# bytebase_vcs_connector_list (Data Source)
-
-The vcs connector data source list.
-
-
-
-
-## Schema
-
-### Required
-
-- `project` (String) The project name in projects/{resource id} format.
-
-### Read-Only
-
-- `id` (String) The ID of this resource.
-- `vcs_connectors` (List of Object) (see [below for nested schema](#nestedatt--vcs_connectors))
-
-
-### Nested Schema for `vcs_connectors`
-
-Read-Only:
-
-- `database_group` (String)
-- `name` (String)
-- `project` (String)
-- `repository_branch` (String)
-- `repository_directory` (String)
-- `repository_id` (String)
-- `repository_path` (String)
-- `repository_url` (String)
-- `resource_id` (String)
-- `title` (String)
-- `vcs_provider` (String)
-
-
diff --git a/docs/data-sources/vcs_provider.md b/docs/data-sources/vcs_provider.md
deleted file mode 100644
index 808fef6..0000000
--- a/docs/data-sources/vcs_provider.md
+++ /dev/null
@@ -1,30 +0,0 @@
----
-# generated by https://github.com/hashicorp/terraform-plugin-docs
-page_title: "bytebase_vcs_provider Data Source - terraform-provider-bytebase"
-subcategory: ""
-description: |-
- The vcs provider data source.
----
-
-# bytebase_vcs_provider (Data Source)
-
-The vcs provider data source.
-
-
-
-
-## Schema
-
-### Required
-
-- `resource_id` (String) The vcs provider unique resource id.
-
-### Read-Only
-
-- `id` (String) The ID of this resource.
-- `name` (String) The vcs provider full name in vcsProviders/{resource id} format.
-- `title` (String) The vcs provider title.
-- `type` (String) The vcs provider type.
-- `url` (String) The vcs provider url.
-
-
diff --git a/docs/data-sources/vcs_provider_list.md b/docs/data-sources/vcs_provider_list.md
deleted file mode 100644
index fdaa0b7..0000000
--- a/docs/data-sources/vcs_provider_list.md
+++ /dev/null
@@ -1,34 +0,0 @@
----
-# generated by https://github.com/hashicorp/terraform-plugin-docs
-page_title: "bytebase_vcs_provider_list Data Source - terraform-provider-bytebase"
-subcategory: ""
-description: |-
- The vcs provider data source list.
----
-
-# bytebase_vcs_provider_list (Data Source)
-
-The vcs provider data source list.
-
-
-
-
-## Schema
-
-### Read-Only
-
-- `id` (String) The ID of this resource.
-- `vcs_providers` (List of Object) (see [below for nested schema](#nestedatt--vcs_providers))
-
-
-### Nested Schema for `vcs_providers`
-
-Read-Only:
-
-- `name` (String)
-- `resource_id` (String)
-- `title` (String)
-- `type` (String)
-- `url` (String)
-
-
diff --git a/docs/resources/database.md b/docs/resources/database.md
index ebb6e39..69ba710 100644
--- a/docs/resources/database.md
+++ b/docs/resources/database.md
@@ -30,8 +30,8 @@ The database resource.
- `id` (String) The ID of this resource.
- `schema_version` (String) The version of database schema.
+- `state` (String) The existence of a database.
- `successful_sync_time` (String) The latest synchronization time.
-- `sync_state` (String) The existence of a database on latest sync.
### Nested Schema for `catalog`
diff --git a/docs/resources/project.md b/docs/resources/project.md
index a21fdf1..5973d01 100644
--- a/docs/resources/project.md
+++ b/docs/resources/project.md
@@ -35,7 +35,6 @@ The project resource.
- `id` (String) The ID of this resource.
- `name` (String) The project full name in projects/{resource id} format.
-- `workflow` (String) The project workflow.
### Nested Schema for `members`
diff --git a/docs/resources/vcs_connector.md b/docs/resources/vcs_connector.md
deleted file mode 100644
index bad7875..0000000
--- a/docs/resources/vcs_connector.md
+++ /dev/null
@@ -1,39 +0,0 @@
----
-# generated by https://github.com/hashicorp/terraform-plugin-docs
-page_title: "bytebase_vcs_connector Resource - terraform-provider-bytebase"
-subcategory: ""
-description: |-
- The vcs connector resource.
----
-
-# bytebase_vcs_connector (Resource)
-
-The vcs connector resource.
-
-
-
-
-## Schema
-
-### Required
-
-- `project` (String) The project name in projects/{resource id} format.
-- `repository_branch` (String) The connected repository branch in vcs provider.
-- `repository_directory` (String) The connected repository directory in vcs provider.
-- `repository_id` (String) The connected repository id in vcs provider.
-- `repository_path` (String) The connected repository path in vcs provider.
-- `repository_url` (String) The connected repository url in vcs provider.
-- `resource_id` (String) The vcs connector unique resource id.
-- `title` (String) The vcs connector title.
-- `vcs_provider` (String) The vcs provider full name in vcsProviders/{resource id} format.
-
-### Optional
-
-- `database_group` (String) Apply changes to the database group.
-
-### Read-Only
-
-- `id` (String) The ID of this resource.
-- `name` (String) The vcs connector full name in projects/{project}/vcsConnector/{resource id} format.
-
-
diff --git a/docs/resources/vcs_provider.md b/docs/resources/vcs_provider.md
deleted file mode 100644
index 51bcab7..0000000
--- a/docs/resources/vcs_provider.md
+++ /dev/null
@@ -1,34 +0,0 @@
----
-# generated by https://github.com/hashicorp/terraform-plugin-docs
-page_title: "bytebase_vcs_provider Resource - terraform-provider-bytebase"
-subcategory: ""
-description: |-
- The vcs provider resource.
----
-
-# bytebase_vcs_provider (Resource)
-
-The vcs provider resource.
-
-
-
-
-## Schema
-
-### Required
-
-- `access_token` (String, Sensitive) The vcs provider token. Check the docs https://bytebase.cc/docs/vcs-integration/add-git-provider for details.
-- `resource_id` (String) The vcs provider unique resource id.
-- `title` (String) The vcs provider title.
-- `type` (String) The vcs provider type.
-
-### Optional
-
-- `url` (String) The vcs provider url. You need to provide the url if you're using the self-host GitLab or self-host GitHub.
-
-### Read-Only
-
-- `id` (String) The ID of this resource.
-- `name` (String) The vcs provider full name in vcsProviders/{resource id} format.
-
-
diff --git a/examples/environments/main.tf b/examples/environments/main.tf
index b7c07ea..543a8aa 100644
--- a/examples/environments/main.tf
+++ b/examples/environments/main.tf
@@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/groups/main.tf b/examples/groups/main.tf
index 2b88420..02c63f3 100644
--- a/examples/groups/main.tf
+++ b/examples/groups/main.tf
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/instances/main.tf b/examples/instances/main.tf
index 206ea08..32c980c 100644
--- a/examples/instances/main.tf
+++ b/examples/instances/main.tf
@@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/policies/main.tf b/examples/policies/main.tf
index bd39820..b4cd985 100644
--- a/examples/policies/main.tf
+++ b/examples/policies/main.tf
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/projects/main.tf b/examples/projects/main.tf
index cec7e85..a43388e 100644
--- a/examples/projects/main.tf
+++ b/examples/projects/main.tf
@@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/roles/main.tf b/examples/roles/main.tf
index f9112a2..e215ec1 100644
--- a/examples/roles/main.tf
+++ b/examples/roles/main.tf
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/settings/main.tf b/examples/settings/main.tf
index 614bceb..e78326e 100644
--- a/examples/settings/main.tf
+++ b/examples/settings/main.tf
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/setup/gitops.tf b/examples/setup/gitops.tf
deleted file mode 100644
index 1b91dc1..0000000
--- a/examples/setup/gitops.tf
+++ /dev/null
@@ -1,27 +0,0 @@
-# Create GitHub GitOps provider.
-resource "bytebase_vcs_provider" "github" {
- resource_id = "vcs-github"
- title = "GitHub GitOps"
- type = "GITHUB"
- access_token = ""
-}
-
-# Connect to the GitHub repository.
-resource "bytebase_vcs_connector" "github" {
- depends_on = [
- bytebase_project.sample_project,
- bytebase_vcs_provider.github,
- # vcs connector requires the external_url.
- bytebase_setting.workspace_profile
- ]
-
- resource_id = "connector-github"
- title = "GitHub Connector"
- project = bytebase_project.sample_project.name
- vcs_provider = bytebase_vcs_provider.github.name
- repository_id = "ed-bytebase/gitops"
- repository_path = "ed-bytebase/gitops"
- repository_directory = "/bytebase"
- repository_branch = "main"
- repository_url = "https://github.com/ed-bytebase/gitops"
-}
diff --git a/examples/setup/instance.tf b/examples/setup/instance.tf
index de0ba67..5494ef4 100644
--- a/examples/setup/instance.tf
+++ b/examples/setup/instance.tf
@@ -21,11 +21,11 @@ resource "bytebase_instance" "test" {
username = "bytebase"
external_secret {
vault {
- url = "http://127.0.0.1:8200"
- token = ""
- engine_name = "secret"
- secret_name = "bytebase"
- key_name = "database_pwd"
+ url = "http://127.0.0.1:8200"
+ token = ""
+ engine_name = "secret"
+ secret_name = "bytebase"
+ password_key_name = "database_pwd"
}
}
}
diff --git a/examples/setup/main.tf b/examples/setup/main.tf
index 6401533..84d503a 100644
--- a/examples/setup/main.tf
+++ b/examples/setup/main.tf
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/sql_review/main.tf b/examples/sql_review/main.tf
index aef9f8e..5579905 100644
--- a/examples/sql_review/main.tf
+++ b/examples/sql_review/main.tf
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/users/main.tf b/examples/users/main.tf
index 093b690..c92021f 100644
--- a/examples/users/main.tf
+++ b/examples/users/main.tf
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
- version = "1.0.20"
+ version = "1.0.21"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
diff --git a/examples/vcs/main.tf b/examples/vcs/main.tf
deleted file mode 100644
index cf2c1d4..0000000
--- a/examples/vcs/main.tf
+++ /dev/null
@@ -1,46 +0,0 @@
-terraform {
- required_providers {
- bytebase = {
- version = "1.0.20"
- # For local development, please use "terraform.local/bytebase/bytebase" instead
- source = "registry.terraform.io/bytebase/bytebase"
- }
- }
-}
-
-provider "bytebase" {
- # You need to replace the account and key with your Bytebase service account.
- service_account = "terraform@service.bytebase.com"
- service_key = "bbs_BxVIp7uQsARl8nR92ZZV"
- # The Bytebase service URL. You can use the external URL in production.
- # Check the docs about external URL: https://www.bytebase.com/docs/get-started/install/external-url
- url = "https://bytebase.example.com"
-}
-
-locals {
- project_id = "project-sample"
-}
-
-data "bytebase_vcs_provider" "github" {
- resource_id = "vcs-github"
-}
-
-data "bytebase_project" "sample_project" {
- resource_id = local.project_id
-}
-
-data "bytebase_vcs_connector" "github" {
- depends_on = [
- data.bytebase_project.sample_project
- ]
- resource_id = "connector-github"
- project = data.bytebase_project.sample_project.name
-}
-
-output "vcs_provider_github" {
- value = data.bytebase_vcs_provider.github
-}
-
-output "vcs_connector_github" {
- value = data.bytebase_vcs_connector.github
-}
diff --git a/go.mod b/go.mod
index 1b3e5f2..87066bd 100644
--- a/go.mod
+++ b/go.mod
@@ -1,17 +1,19 @@
module github.com/bytebase/terraform-provider-bytebase
-go 1.23.4
+go 1.24.0
+
+toolchain go1.24.1
require (
- github.com/bytebase/bytebase v0.0.0-20250214061108-7af51d424e81
+ github.com/bytebase/bytebase v0.0.0-20250313084449-2ed26990a507
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-docs v0.13.0
github.com/hashicorp/terraform-plugin-log v0.7.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0
github.com/pkg/errors v0.9.1
- google.golang.org/genproto v0.0.0-20250122153221-138b5a5a4fd4
- google.golang.org/genproto/googleapis/api v0.0.0-20250127172529-29210b9bc287
- google.golang.org/protobuf v1.36.4
+ google.golang.org/genproto v0.0.0-20250311190419-81fb87f6b8bf
+ google.golang.org/genproto/googleapis/api v0.0.0-20250311190419-81fb87f6b8bf
+ google.golang.org/protobuf v1.36.5
)
require (
@@ -25,9 +27,9 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
- github.com/google/go-cmp v0.6.0 // indirect
+ github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
- github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
+ github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // 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
@@ -35,7 +37,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // 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.6.0 // indirect
+ github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hc-install v0.4.0 // indirect
github.com/hashicorp/hcl/v2 v2.14.1 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
@@ -64,11 +66,11 @@ require (
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/zclconf/go-cty v1.11.0 // indirect
- golang.org/x/crypto v0.32.0 // indirect
- golang.org/x/net v0.34.0 // indirect
- golang.org/x/sys v0.29.0 // indirect
- golang.org/x/text v0.21.0 // indirect
+ golang.org/x/crypto v0.36.0 // indirect
+ golang.org/x/net v0.37.0 // indirect
+ golang.org/x/sys v0.31.0 // indirect
+ golang.org/x/text v0.23.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
- google.golang.org/genproto/googleapis/rpc v0.0.0-20250124145028-65684f501c47 // indirect
- google.golang.org/grpc v1.70.0 // indirect
+ google.golang.org/genproto/googleapis/rpc v0.0.0-20250311190419-81fb87f6b8bf // indirect
+ google.golang.org/grpc v1.71.0 // indirect
)
diff --git a/go.sum b/go.sum
index 0478716..cc30097 100644
--- a/go.sum
+++ b/go.sum
@@ -8,8 +8,9 @@ github.com/Masterminds/sprig/v3 v3.2.0/go.mod h1:tWhwTbUTndesPNeF0C900vKoq283u6z
github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8=
github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
-github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
+github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
+github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
@@ -29,8 +30,8 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
-github.com/bytebase/bytebase v0.0.0-20250214061108-7af51d424e81 h1:OBTxE1kfksQf6uWgMwnqQp4rsAngc7w7PIL5ovGNuio=
-github.com/bytebase/bytebase v0.0.0-20250214061108-7af51d424e81/go.mod h1:YgcCTK40kyXrUhDPbx1GkWLPiH59BTfcvKuVrNAbedo=
+github.com/bytebase/bytebase v0.0.0-20250313084449-2ed26990a507 h1:JMBYOPpRjoeWZt8QsFvzKe/JvelebOGhEkAJapkT1NM=
+github.com/bytebase/bytebase v0.0.0-20250313084449-2ed26990a507/go.mod h1:yGEPeD42x5lqzB5FwA2H87/eWPZKfU7vyMN8xF+HYC0=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -68,14 +69,14 @@ github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
-github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
-github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
+github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
-github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 h1:TmHmbvxPmaegwhDubVz0lICL0J5Ka2vwTzhoePEXsGE=
-github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0/go.mod h1:qztMSjm835F2bXf+5HKAPIS5qsmQDqZna/PgVt4rWtI=
+github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 h1:5ZPtiqj0JL5oKWmcsq4VMaAW5ukBEgSGXEN89zeH1Jo=
+github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3/go.mod h1:ndYquD05frm2vACXE1nsccT4oJzjhw2arTS2cpUD1PI=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@@ -99,8 +100,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
-github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
-github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
+github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
+github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hc-install v0.4.0 h1:cZkRFr1WVa0Ty6x5fTvL1TuO1flul231rWkGH92oYYk=
github.com/hashicorp/hc-install v0.4.0/go.mod h1:5d155H8EC5ewegao9A4PUTMNPZaq+TbOzkJJZ4vrXeI=
github.com/hashicorp/hcl/v2 v2.14.1 h1:x0BpjfZ+CYdbiz+8yZTQ+gdLO7IXvOut7Da+XJayx34=
@@ -236,16 +237,16 @@ github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeW
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
-go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
-go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
-go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
-go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
-go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
-go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=
-go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=
-go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
-go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
-go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
+go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
+go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
+go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
+go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
+go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
+go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
+go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o=
+go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
+go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
+go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -253,8 +254,8 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
-golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
+golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
+golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -265,8 +266,8 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
-golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
-golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
+golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
+golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -288,31 +289,31 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
-golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
+golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
-golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
+golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
+golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
-google.golang.org/genproto v0.0.0-20250122153221-138b5a5a4fd4 h1:Pw6WnI9W/LIdRxqK7T6XGugGbHIRl5Q7q3BssH6xk4s=
-google.golang.org/genproto v0.0.0-20250122153221-138b5a5a4fd4/go.mod h1:qbZzneIOXSq+KFAFut9krLfRLZiFLzZL5u2t8SV83EE=
-google.golang.org/genproto/googleapis/api v0.0.0-20250127172529-29210b9bc287 h1:A2ni10G3UlplFrWdCDJTl7D7mJ7GSRm37S+PDimaKRw=
-google.golang.org/genproto/googleapis/api v0.0.0-20250127172529-29210b9bc287/go.mod h1:iYONQfRdizDB8JJBybql13nArx91jcUk7zCXEsOofM4=
-google.golang.org/genproto/googleapis/rpc v0.0.0-20250124145028-65684f501c47 h1:91mG8dNTpkC0uChJUQ9zCiRqx3GEEFOWaRZ0mI6Oj2I=
-google.golang.org/genproto/googleapis/rpc v0.0.0-20250124145028-65684f501c47/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50=
-google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
-google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
-google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
-google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
+google.golang.org/genproto v0.0.0-20250311190419-81fb87f6b8bf h1:114fkUG+I9ba4UmaoNZt0UtiRmBng3KJIB/E0avfYII=
+google.golang.org/genproto v0.0.0-20250311190419-81fb87f6b8bf/go.mod h1:sAo5UzpjUwgFBCzupwhcLcxHVDK7vG5IqI30YnwX2eE=
+google.golang.org/genproto/googleapis/api v0.0.0-20250311190419-81fb87f6b8bf h1:BdIVRm+fyDUn8lrZLPSlBCfM/YKDwUBYgDoLv9+DYo0=
+google.golang.org/genproto/googleapis/api v0.0.0-20250311190419-81fb87f6b8bf/go.mod h1:jbe3Bkdp+Dh2IrslsFCklNhweNTBgSYanP1UXhJDhKg=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20250311190419-81fb87f6b8bf h1:dHDlF3CWxQkefK9IJx+O8ldY0gLygvrlYRBNbPqDWuY=
+google.golang.org/genproto/googleapis/rpc v0.0.0-20250311190419-81fb87f6b8bf/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I=
+google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=
+google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
+google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
+google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
diff --git a/provider/data_source_database.go b/provider/data_source_database.go
index d704a0b..36eb09e 100644
--- a/provider/data_source_database.go
+++ b/provider/data_source_database.go
@@ -32,10 +32,10 @@ func dataSourceDatabase() *schema.Resource {
Computed: true,
Description: "The database environment, will follow the instance environment by default",
},
- "sync_state": {
+ "state": {
Type: schema.TypeString,
Computed: true,
- Description: "The existence of a database on latest sync.",
+ Description: "The existence of a database.",
},
"successful_sync_time": {
Type: schema.TypeString,
diff --git a/provider/data_source_database_list.go b/provider/data_source_database_list.go
index d130d02..2f4023a 100644
--- a/provider/data_source_database_list.go
+++ b/provider/data_source_database_list.go
@@ -49,10 +49,10 @@ func dataSourceDatabaseList() *schema.Resource {
Computed: true,
Description: "The database environment, will follow the instance environment by default",
},
- "sync_state": {
+ "state": {
Type: schema.TypeString,
Computed: true,
- Description: "The existence of a database on latest sync.",
+ Description: "The existence of a database.",
},
"successful_sync_time": {
Type: schema.TypeString,
@@ -92,17 +92,11 @@ func dataSourceDatabaseListRead(ctx context.Context, d *schema.ResourceData, m i
db["name"] = database.Name
db["project"] = database.Project
db["environment"] = database.Environment
- db["sync_state"] = database.SyncState.String()
+ db["state"] = database.State.String()
db["successful_sync_time"] = database.SuccessfulSyncTime.AsTime().UTC().Format(time.RFC3339)
db["schema_version"] = database.SchemaVersion
db["labels"] = database.Labels
- // catalog, err := client.GetDatabaseCatalog(ctx, database.Name)
- // if err != nil {
- // return diag.Errorf("failed to get catalog for database %s with error: %v", database.Name, err.Error())
- // }
- // db["catalog"] = flattenDatabaseCatalog(catalog)
-
dbList = append(dbList, db)
}
diff --git a/provider/data_source_instance_list.go b/provider/data_source_instance_list.go
index cb5c2c8..113408a 100644
--- a/provider/data_source_instance_list.go
+++ b/provider/data_source_instance_list.go
@@ -176,11 +176,8 @@ func dataSourceInstanceListRead(ctx context.Context, d *schema.ResourceData, m i
ins["engine_version"] = instance.EngineVersion
ins["external_link"] = instance.ExternalLink
ins["environment"] = instance.Environment
-
- if op := instance.Options; op != nil {
- ins["sync_interval"] = op.GetSyncInterval().GetSeconds()
- ins["maximum_connections"] = op.GetMaximumConnections()
- }
+ ins["sync_interval"] = instance.GetSyncInterval().GetSeconds()
+ ins["maximum_connections"] = instance.GetMaximumConnections()
dataSources, err := flattenDataSourceList(d, instance.DataSources)
if err != nil {
diff --git a/provider/data_source_project.go b/provider/data_source_project.go
index cf92471..1969c3d 100644
--- a/provider/data_source_project.go
+++ b/provider/data_source_project.go
@@ -40,11 +40,6 @@ func dataSourceProject() *schema.Resource {
Computed: true,
Description: "The project full name in projects/{resource id} format.",
},
- "workflow": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The project workflow.",
- },
"allow_modify_statement": {
Type: schema.TypeBool,
Computed: true,
@@ -285,9 +280,6 @@ func setProject(
if err := d.Set("title", project.Title); err != nil {
return diag.Errorf("cannot set title for project: %s", err.Error())
}
- if err := d.Set("workflow", project.Workflow.String()); err != nil {
- return diag.Errorf("cannot set workflow for project: %s", err.Error())
- }
if err := d.Set("allow_modify_statement", project.AllowModifyStatement); err != nil {
return diag.Errorf("cannot set allow_modify_statement for project: %s", err.Error())
}
diff --git a/provider/data_source_project_list.go b/provider/data_source_project_list.go
index 64415d4..9230433 100644
--- a/provider/data_source_project_list.go
+++ b/provider/data_source_project_list.go
@@ -43,11 +43,6 @@ func dataSourceProjectList() *schema.Resource {
Computed: true,
Description: "The project title.",
},
- "workflow": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The project workflow.",
- },
"allow_modify_statement": {
Type: schema.TypeBool,
Computed: true,
@@ -93,13 +88,13 @@ func dataSourceProjectListRead(ctx context.Context, d *schema.ResourceData, m in
// Warning or errors can be collected in a slice type
var diags diag.Diagnostics
- response, err := c.ListProject(ctx, d.Get("show_deleted").(bool))
+ allProjects, err := c.ListProject(ctx, d.Get("show_deleted").(bool))
if err != nil {
return diag.FromErr(err)
}
projects := make([]map[string]interface{}, 0)
- for _, project := range response.Projects {
+ for _, project := range allProjects {
projectID, err := internal.GetProjectID(project.Name)
if err != nil {
return diag.FromErr(err)
@@ -109,7 +104,6 @@ func dataSourceProjectListRead(ctx context.Context, d *schema.ResourceData, m in
proj["resource_id"] = projectID
proj["name"] = project.Name
proj["title"] = project.Title
- proj["workflow"] = project.Workflow.String()
proj["allow_modify_statement"] = project.AllowModifyStatement
proj["auto_resolve_issue"] = project.AutoResolveIssue
proj["enforce_issue_title"] = project.EnforceIssueTitle
diff --git a/provider/data_source_setting.go b/provider/data_source_setting.go
index 8b5f90d..b5e6b62 100644
--- a/provider/data_source_setting.go
+++ b/provider/data_source_setting.go
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
- "github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -390,7 +389,6 @@ func getWorkspaceApprovalSetting(computed bool) *schema.Schema {
ValidateFunc: validation.StringInSlice([]string{
string(api.ApprovalNodeTypeGroup),
string(api.ApprovalNodeTypeRole),
- string(api.ApprovalNodeTypeExternalNodeID),
}, false),
},
"node": {
@@ -485,13 +483,6 @@ func setSettingMessage(ctx context.Context, d *schema.ResourceData, client api.C
}
if value := setting.Value.GetSemanticTypeSettingValue(); value != nil {
settingVal := flattenSemanticTypesSetting(value)
- tflog.Debug(ctx, "flatten semantic types", map[string]interface{}{
- "count": len(settingVal),
- })
- // semanticTypeSetting := map[string]interface{}{
- // "semantic_types": schema.NewSet(itemIDHash, settingVal),
- // }
- // return []interface{}{approvalSetting}
if err := d.Set("semantic_types", schema.NewSet(itemIDHash, settingVal)); err != nil {
return diag.Errorf("cannot set semantic_types: %s", err.Error())
}
@@ -573,9 +564,6 @@ func flattenWorkspaceApprovalSetting(ctx context.Context, client api.Client, set
case *v1pb.ApprovalNode_Role:
rawNode["type"] = string(api.ApprovalNodeTypeRole)
rawNode["node"] = payload.Role
- case *v1pb.ApprovalNode_ExternalNodeId:
- rawNode["type"] = string(api.ApprovalNodeTypeExternalNodeID)
- rawNode["node"] = payload.ExternalNodeId
case *v1pb.ApprovalNode_GroupValue_:
rawNode["type"] = string(api.ApprovalNodeTypeGroup)
rawNode["node"] = payload.GroupValue.String()
diff --git a/provider/data_source_user_list.go b/provider/data_source_user_list.go
index be88fcc..34cb71f 100644
--- a/provider/data_source_user_list.go
+++ b/provider/data_source_user_list.go
@@ -96,7 +96,7 @@ func dataSourceUserList() *schema.Resource {
func dataSourceUserListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(api.Client)
- response, err := c.ListUser(ctx, d.Get("show_deleted").(bool))
+ allUsers, err := c.ListUser(ctx, d.Get("show_deleted").(bool))
if err != nil {
return diag.FromErr(err)
}
@@ -107,7 +107,7 @@ func dataSourceUserListRead(ctx context.Context, d *schema.ResourceData, m inter
}
users := make([]map[string]interface{}, 0)
- for _, user := range response.Users {
+ for _, user := range allUsers {
raw := make(map[string]interface{})
raw["name"] = user.Name
raw["email"] = user.Email
diff --git a/provider/data_source_vcs_connector.go b/provider/data_source_vcs_connector.go
deleted file mode 100644
index 390741e..0000000
--- a/provider/data_source_vcs_connector.go
+++ /dev/null
@@ -1,140 +0,0 @@
-package provider
-
-import (
- "context"
- "fmt"
- "regexp"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
-
- v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
-
- "github.com/bytebase/terraform-provider-bytebase/api"
- "github.com/bytebase/terraform-provider-bytebase/provider/internal"
-)
-
-func dataSourceVCSConnector() *schema.Resource {
- return &schema.Resource{
- Description: "The vcs connector data source.",
- ReadContext: dataSourceVCSConnectorRead,
- Schema: map[string]*schema.Schema{
- "resource_id": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: internal.ResourceIDValidation,
- Description: "The vcs connector unique resource id.",
- },
- "project": {
- Type: schema.TypeString,
- Required: true,
- ValidateDiagFunc: internal.ResourceNameValidation(regexp.MustCompile(fmt.Sprintf("^%s%s$", internal.ProjectNamePrefix, internal.ResourceIDPattern))),
- Description: "The project name in projects/{resource id} format.",
- },
- "name": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs connector full name in projects/{project}/vcsConnector/{resource id} format.",
- },
- "title": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs connector title.",
- },
- "vcs_provider": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider full name in vcsProviders/{resource id} format.",
- },
- "database_group": {
- Type: schema.TypeString,
- Computed: true,
- Optional: true,
- Description: "Apply changes to the database group.",
- },
- "repository_id": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository id in vcs provider.",
- },
- "repository_path": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository path in vcs provider.",
- },
- "repository_directory": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository directory in vcs provider.",
- },
- "repository_branch": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository branch in vcs provider.",
- },
- "repository_url": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository url in vcs provider.",
- },
- },
- }
-}
-
-func dataSourceVCSConnectorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
- project := d.Get("project").(string)
- connectorName := fmt.Sprintf("%s/%s%s", project, internal.VCSConnectorNamePrefix, d.Get("resource_id").(string))
-
- connector, err := c.GetVCSConnector(ctx, connectorName)
- if err != nil {
- return diag.FromErr(err)
- }
-
- d.SetId(connector.Name)
-
- return setVCSConnector(d, connector)
-}
-
-func setVCSConnector(d *schema.ResourceData, connector *v1pb.VCSConnector) diag.Diagnostics {
- projectID, connectorID, err := internal.GetVCSConnectorID(connector.Name)
- if err != nil {
- return diag.FromErr(err)
- }
-
- if err := d.Set("resource_id", connectorID); err != nil {
- return diag.Errorf("cannot set resource_id for vcs connector: %s", err.Error())
- }
- if err := d.Set("project", fmt.Sprintf("%s%s", internal.ProjectNamePrefix, projectID)); err != nil {
- return diag.Errorf("cannot set project for vcs connector: %s", err.Error())
- }
- if err := d.Set("title", connector.Title); err != nil {
- return diag.Errorf("cannot set title for vcs connector: %s", err.Error())
- }
- if err := d.Set("name", connector.Name); err != nil {
- return diag.Errorf("cannot set name for vcs connector: %s", err.Error())
- }
- if err := d.Set("vcs_provider", connector.VcsProvider); err != nil {
- return diag.Errorf("cannot set vcs_provider for vcs connector: %s", err.Error())
- }
- if err := d.Set("database_group", connector.DatabaseGroup); err != nil {
- return diag.Errorf("cannot set database_group for vcs connector: %s", err.Error())
- }
- if err := d.Set("repository_id", connector.ExternalId); err != nil {
- return diag.Errorf("cannot set repository_id for vcs connector: %s", err.Error())
- }
- if err := d.Set("repository_path", connector.FullPath); err != nil {
- return diag.Errorf("cannot set repository_path for vcs connector: %s", err.Error())
- }
- if err := d.Set("repository_directory", connector.BaseDirectory); err != nil {
- return diag.Errorf("cannot set repository_directory for vcs connector: %s", err.Error())
- }
- if err := d.Set("repository_branch", connector.Branch); err != nil {
- return diag.Errorf("cannot set repository_branch for vcs connector: %s", err.Error())
- }
- if err := d.Set("repository_url", connector.WebUrl); err != nil {
- return diag.Errorf("cannot set repository_url for vcs connector: %s", err.Error())
- }
-
- return nil
-}
diff --git a/provider/data_source_vcs_connector_list.go b/provider/data_source_vcs_connector_list.go
deleted file mode 100644
index 8bcfbe1..0000000
--- a/provider/data_source_vcs_connector_list.go
+++ /dev/null
@@ -1,136 +0,0 @@
-package provider
-
-import (
- "context"
- "fmt"
- "regexp"
- "strconv"
- "time"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
-
- "github.com/bytebase/terraform-provider-bytebase/api"
- "github.com/bytebase/terraform-provider-bytebase/provider/internal"
-)
-
-func dataSourceVCSConnectorList() *schema.Resource {
- return &schema.Resource{
- Description: "The vcs connector data source list.",
- ReadContext: dataSourceVCSConnectorListRead,
- Schema: map[string]*schema.Schema{
- "project": {
- Type: schema.TypeString,
- Required: true,
- ValidateDiagFunc: internal.ResourceNameValidation(regexp.MustCompile(fmt.Sprintf("^%s%s$", internal.ProjectNamePrefix, internal.ResourceIDPattern))),
- Description: "The project name in projects/{resource id} format.",
- },
- "vcs_connectors": {
- Type: schema.TypeList,
- Computed: true,
- Elem: &schema.Resource{
- Schema: map[string]*schema.Schema{
- "resource_id": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs connector unique resource id.",
- },
- "project": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The project name in projects/{resource id} format.",
- },
- "name": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs connector full name in projects/{project}/vcsConnector/{resource id} format.",
- },
- "title": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs connector title.",
- },
- "vcs_provider": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider full name in vcsProviders/{resource id} format.",
- },
- "database_group": {
- Type: schema.TypeString,
- Computed: true,
- Optional: true,
- Description: "Apply changes to the database group.",
- },
- "repository_id": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository id in vcs provider.",
- },
- "repository_path": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository path in vcs provider.",
- },
- "repository_directory": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository directory in vcs provider.",
- },
- "repository_branch": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository branch in vcs provider.",
- },
- "repository_url": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The connected repository url in vcs provider.",
- },
- },
- },
- },
- },
- }
-}
-
-func dataSourceVCSConnectorListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
- project := d.Get("project").(string)
-
- response, err := c.ListVCSConnector(ctx, project)
- if err != nil {
- return diag.FromErr(err)
- }
-
- connectors := []map[string]interface{}{}
- for _, connector := range response.VcsConnectors {
- projectID, connectorID, err := internal.GetVCSConnectorID(connector.Name)
- if err != nil {
- return diag.FromErr(err)
- }
-
- rawConnector := make(map[string]interface{})
- rawConnector["resource_id"] = connectorID
- rawConnector["project"] = fmt.Sprintf("%s%s", internal.ProjectNamePrefix, projectID)
- rawConnector["title"] = connector.Title
- rawConnector["name"] = connector.Name
- rawConnector["vcs_provider"] = connector.VcsProvider
- rawConnector["database_group"] = connector.DatabaseGroup
- rawConnector["repository_id"] = connector.ExternalId
- rawConnector["repository_path"] = connector.FullPath
- rawConnector["repository_directory"] = connector.BaseDirectory
- rawConnector["repository_branch"] = connector.Branch
- rawConnector["repository_url"] = connector.WebUrl
-
- connectors = append(connectors, rawConnector)
- }
-
- if err := d.Set("vcs_connectors", connectors); err != nil {
- return diag.FromErr(err)
- }
-
- // always refresh
- d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
-
- return nil
-}
diff --git a/provider/data_source_vcs_provider.go b/provider/data_source_vcs_provider.go
deleted file mode 100644
index 660870c..0000000
--- a/provider/data_source_vcs_provider.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package provider
-
-import (
- "context"
- "fmt"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
-
- v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
-
- "github.com/bytebase/terraform-provider-bytebase/api"
- "github.com/bytebase/terraform-provider-bytebase/provider/internal"
-)
-
-func dataSourceVCSProvider() *schema.Resource {
- return &schema.Resource{
- Description: "The vcs provider data source.",
- ReadContext: dataSourceVCSProviderRead,
- Schema: map[string]*schema.Schema{
- "resource_id": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: internal.ResourceIDValidation,
- Description: "The vcs provider unique resource id.",
- },
- "title": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider title.",
- },
- "name": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider full name in vcsProviders/{resource id} format.",
- },
- "type": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider type.",
- },
- "url": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider url.",
- },
- },
- }
-}
-
-func dataSourceVCSProviderRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
- providerName := fmt.Sprintf("%s%s", internal.VCSProviderNamePrefix, d.Get("resource_id").(string))
-
- provider, err := c.GetVCSProvider(ctx, providerName)
- if err != nil {
- return diag.FromErr(err)
- }
-
- d.SetId(provider.Name)
-
- return setVCSProvider(d, provider)
-}
-
-func setVCSProvider(d *schema.ResourceData, provider *v1pb.VCSProvider) diag.Diagnostics {
- providerID, err := internal.GetVCSProviderID(provider.Name)
- if err != nil {
- return diag.FromErr(err)
- }
-
- if err := d.Set("resource_id", providerID); err != nil {
- return diag.Errorf("cannot set resource_id for vcs provider: %s", err.Error())
- }
- if err := d.Set("title", provider.Title); err != nil {
- return diag.Errorf("cannot set title for vcs provider: %s", err.Error())
- }
- if err := d.Set("name", provider.Name); err != nil {
- return diag.Errorf("cannot set name for vcs provider: %s", err.Error())
- }
- if err := d.Set("type", provider.Type.String()); err != nil {
- return diag.Errorf("cannot set type for vcs provider: %s", err.Error())
- }
- if err := d.Set("url", provider.Url); err != nil {
- return diag.Errorf("cannot set url for vcs provider: %s", err.Error())
- }
-
- return nil
-}
diff --git a/provider/data_source_vcs_provider_list.go b/provider/data_source_vcs_provider_list.go
deleted file mode 100644
index 8f4ecf4..0000000
--- a/provider/data_source_vcs_provider_list.go
+++ /dev/null
@@ -1,93 +0,0 @@
-package provider
-
-import (
- "context"
- "strconv"
- "time"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
-
- "github.com/bytebase/terraform-provider-bytebase/api"
- "github.com/bytebase/terraform-provider-bytebase/provider/internal"
-)
-
-func dataSourceVCSProviderList() *schema.Resource {
- return &schema.Resource{
- Description: "The vcs provider data source list.",
- ReadContext: dataSourceVCSProviderListRead,
- Schema: map[string]*schema.Schema{
- "vcs_providers": {
- Type: schema.TypeList,
- Computed: true,
- Elem: &schema.Resource{
- Schema: map[string]*schema.Schema{
- "resource_id": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider unique resource id.",
- },
- "title": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider title.",
- },
- "name": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider full name in vcsProviders/{resource id} format.",
- },
- "type": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider type.",
- },
- "url": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider url.",
- },
- },
- },
- },
- },
- }
-}
-
-func dataSourceVCSProviderListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
-
- // Warning or errors can be collected in a slice type
- var diags diag.Diagnostics
-
- response, err := c.ListVCSProvider(ctx)
- if err != nil {
- return diag.FromErr(err)
- }
-
- providers := []map[string]interface{}{}
- for _, provider := range response.VcsProviders {
- providerID, err := internal.GetVCSProviderID(provider.Name)
- if err != nil {
- return diag.FromErr(err)
- }
-
- rawProvider := make(map[string]interface{})
- rawProvider["resource_id"] = providerID
- rawProvider["title"] = provider.Title
- rawProvider["name"] = provider.Name
- rawProvider["type"] = provider.Type.String()
- rawProvider["url"] = provider.Url
-
- providers = append(providers, rawProvider)
- }
-
- if err := d.Set("vcs_providers", providers); err != nil {
- return diag.FromErr(err)
- }
-
- // always refresh
- d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
-
- return diags
-}
diff --git a/provider/internal/mock_client.go b/provider/internal/mock_client.go
index b16ad51..534a8ef 100644
--- a/provider/internal/mock_client.go
+++ b/provider/internal/mock_client.go
@@ -22,8 +22,6 @@ var projectIAMMap map[string]*v1pb.IamPolicy
var databaseMap map[string]*v1pb.Database
var databaseCatalogMap map[string]*v1pb.DatabaseCatalog
var settingMap map[string]*v1pb.Setting
-var vcsProviderMap map[string]*v1pb.VCSProvider
-var vcsConnectorMap map[string]*v1pb.VCSConnector
var userMap map[string]*v1pb.User
var roleMap map[string]*v1pb.Role
var groupMap map[string]*v1pb.Group
@@ -37,8 +35,6 @@ func init() {
databaseMap = map[string]*v1pb.Database{}
databaseCatalogMap = map[string]*v1pb.DatabaseCatalog{}
settingMap = map[string]*v1pb.Setting{}
- vcsProviderMap = map[string]*v1pb.VCSProvider{}
- vcsConnectorMap = map[string]*v1pb.VCSConnector{}
userMap = map[string]*v1pb.User{}
roleMap = map[string]*v1pb.Role{}
groupMap = map[string]*v1pb.Group{}
@@ -53,8 +49,6 @@ type mockClient struct {
databaseMap map[string]*v1pb.Database
databaseCatalogMap map[string]*v1pb.DatabaseCatalog
settingMap map[string]*v1pb.Setting
- vcsProviderMap map[string]*v1pb.VCSProvider
- vcsConnectorMap map[string]*v1pb.VCSConnector
userMap map[string]*v1pb.User
roleMap map[string]*v1pb.Role
groupMap map[string]*v1pb.Group
@@ -72,8 +66,6 @@ func newMockClient(_, _, _ string) (api.Client, error) {
databaseMap: databaseMap,
databaseCatalogMap: databaseCatalogMap,
settingMap: settingMap,
- vcsProviderMap: vcsProviderMap,
- vcsConnectorMap: vcsConnectorMap,
userMap: userMap,
roleMap: roleMap,
groupMap: groupMap,
@@ -214,7 +206,6 @@ func (c *mockClient) CreateInstance(_ context.Context, instanceID string, instan
ExternalLink: instance.ExternalLink,
DataSources: instance.DataSources,
Environment: instance.Environment,
- Options: &v1pb.InstanceOptions{},
}
envID, err := GetEnvironmentID(ins.Environment)
@@ -223,8 +214,8 @@ func (c *mockClient) CreateInstance(_ context.Context, instanceID string, instan
}
database := &v1pb.Database{
- Name: fmt.Sprintf("%s/%sdefault", ins.Name, DatabaseIDPrefix),
- SyncState: v1pb.State_ACTIVE,
+ Name: fmt.Sprintf("%s/%sdefault", ins.Name, DatabaseIDPrefix),
+ State: v1pb.State_ACTIVE,
Labels: map[string]string{
"bb.environment": envID,
},
@@ -251,11 +242,11 @@ func (c *mockClient) UpdateInstance(ctx context.Context, patch *v1pb.Instance, u
if slices.Contains(updateMasks, "data_sources") {
ins.DataSources = patch.DataSources
}
- if slices.Contains(updateMasks, "options.sync_interval") {
- ins.Options.SyncInterval = patch.Options.SyncInterval
+ if slices.Contains(updateMasks, "sync_interval") {
+ ins.SyncInterval = patch.SyncInterval
}
- if slices.Contains(updateMasks, "options.maximum_connections") {
- ins.Options.MaximumConnections = patch.Options.MaximumConnections
+ if slices.Contains(updateMasks, "maximum_connections") {
+ ins.MaximumConnections = patch.MaximumConnections
}
c.instanceMap[ins.Name] = ins
@@ -468,7 +459,7 @@ func (c *mockClient) GetProject(_ context.Context, projectName string) (*v1pb.Pr
}
// ListProject list the projects.
-func (c *mockClient) ListProject(_ context.Context, showDeleted bool) (*v1pb.ListProjectsResponse, error) {
+func (c *mockClient) ListProject(_ context.Context, showDeleted bool) ([]*v1pb.Project, error) {
projects := make([]*v1pb.Project, 0)
for _, proj := range c.projectMap {
if proj.State == v1pb.State_DELETED && !showDeleted {
@@ -477,18 +468,15 @@ func (c *mockClient) ListProject(_ context.Context, showDeleted bool) (*v1pb.Lis
projects = append(projects, proj)
}
- return &v1pb.ListProjectsResponse{
- Projects: projects,
- }, nil
+ return projects, nil
}
// CreateProject creates the project.
func (c *mockClient) CreateProject(_ context.Context, projectID string, project *v1pb.Project) (*v1pb.Project, error) {
proj := &v1pb.Project{
- Name: fmt.Sprintf("%s%s", ProjectNamePrefix, projectID),
- State: v1pb.State_ACTIVE,
- Title: project.Title,
- Workflow: v1pb.Workflow_UI,
+ Name: fmt.Sprintf("%s%s", ProjectNamePrefix, projectID),
+ State: v1pb.State_ACTIVE,
+ Title: project.Title,
}
c.projectMap[proj.Name] = proj
@@ -590,117 +578,8 @@ func (*mockClient) ParseExpression(_ context.Context, _ string) (*v1alpha1.Expr,
return &v1alpha1.Expr{}, nil
}
-// ListVCSProvider will returns all vcs providers.
-func (c *mockClient) ListVCSProvider(_ context.Context) (*v1pb.ListVCSProvidersResponse, error) {
- providers := make([]*v1pb.VCSProvider, 0)
- for _, provider := range c.vcsProviderMap {
- providers = append(providers, provider)
- }
-
- return &v1pb.ListVCSProvidersResponse{
- VcsProviders: providers,
- }, nil
-}
-
-// GetVCSProvider gets the vcs by id.
-func (c *mockClient) GetVCSProvider(_ context.Context, providerName string) (*v1pb.VCSProvider, error) {
- provider, ok := c.vcsProviderMap[providerName]
- if !ok {
- return nil, errors.Errorf("Cannot found provider %s", providerName)
- }
-
- return provider, nil
-}
-
-// CreateVCSProvider creates the vcs provider.
-func (c *mockClient) CreateVCSProvider(_ context.Context, providerID string, provider *v1pb.VCSProvider) (*v1pb.VCSProvider, error) {
- providerName := fmt.Sprintf("%s%s", VCSProviderNamePrefix, providerID)
- provider.Name = providerName
- c.vcsProviderMap[providerName] = provider
- return provider, nil
-}
-
-// UpdateVCSProvider updates the vcs provider.
-func (c *mockClient) UpdateVCSProvider(ctx context.Context, provider *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSProvider, error) {
- existed, err := c.GetVCSProvider(ctx, provider.Name)
- if err != nil {
- return nil, err
- }
- if slices.Contains(updateMasks, "title") {
- existed.Title = provider.Title
- }
- if slices.Contains(updateMasks, "access_token") {
- existed.AccessToken = provider.AccessToken
- }
- c.vcsProviderMap[provider.Name] = existed
- return c.vcsProviderMap[provider.Name], nil
-}
-
-// DeleteVCSProvider deletes the vcs provider.
-func (c *mockClient) DeleteVCSProvider(_ context.Context, provider string) error {
- delete(c.vcsProviderMap, provider)
- return nil
-}
-
-// ListVCSConnector will returns all vcs connector in a project.
-func (c *mockClient) ListVCSConnector(_ context.Context, projectName string) (*v1pb.ListVCSConnectorsResponse, error) {
- connectors := make([]*v1pb.VCSConnector, 0)
- for _, connector := range c.vcsConnectorMap {
- if strings.HasPrefix(connector.Name, fmt.Sprintf("%s/%s", projectName, VCSConnectorNamePrefix)) {
- connectors = append(connectors, connector)
- }
- }
-
- return &v1pb.ListVCSConnectorsResponse{
- VcsConnectors: connectors,
- }, nil
-}
-
-// GetVCSConnector gets the vcs connector by id.
-func (c *mockClient) GetVCSConnector(_ context.Context, connectorName string) (*v1pb.VCSConnector, error) {
- connector, ok := c.vcsConnectorMap[connectorName]
- if !ok {
- return nil, errors.Errorf("Cannot found connector %s", connectorName)
- }
-
- return connector, nil
-}
-
-// CreateVCSConnector creates the vcs connector in a project.
-func (c *mockClient) CreateVCSConnector(_ context.Context, projectName, connectorID string, connector *v1pb.VCSConnector) (*v1pb.VCSConnector, error) {
- connectorName := fmt.Sprintf("%s/%s%s", projectName, VCSProviderNamePrefix, connectorID)
- connector.Name = connectorName
- c.vcsConnectorMap[connectorName] = connector
- return connector, nil
-}
-
-// UpdateVCSConnector updates the vcs connector.
-func (c *mockClient) UpdateVCSConnector(ctx context.Context, connector *v1pb.VCSConnector, updateMasks []string) (*v1pb.VCSConnector, error) {
- existed, err := c.GetVCSConnector(ctx, connector.Name)
- if err != nil {
- return nil, err
- }
- if slices.Contains(updateMasks, "branch") {
- existed.Branch = connector.Branch
- }
- if slices.Contains(updateMasks, "base_directory") {
- existed.BaseDirectory = connector.BaseDirectory
- }
- if slices.Contains(updateMasks, "database_group") {
- existed.DatabaseGroup = connector.DatabaseGroup
- }
- c.vcsConnectorMap[connector.Name] = existed
- return c.vcsConnectorMap[connector.Name], nil
-}
-
-// DeleteVCSConnector deletes the vcs provider.
-func (c *mockClient) DeleteVCSConnector(_ context.Context, connectorName string) error {
- delete(c.vcsConnectorMap, connectorName)
- return nil
-}
-
// ListUser list all users.
-func (c *mockClient) ListUser(_ context.Context, showDeleted bool) (*v1pb.ListUsersResponse, error) {
+func (c *mockClient) ListUser(_ context.Context, showDeleted bool) ([]*v1pb.User, error) {
users := make([]*v1pb.User, 0)
for _, user := range c.userMap {
if user.State == v1pb.State_DELETED && !showDeleted {
@@ -709,9 +588,7 @@ func (c *mockClient) ListUser(_ context.Context, showDeleted bool) (*v1pb.ListUs
users = append(users, user)
}
- return &v1pb.ListUsersResponse{
- Users: users,
- }, nil
+ return users, nil
}
// GetUser gets the user by name.
diff --git a/provider/provider.go b/provider/provider.go
index 9136a1b..dc49d1c 100644
--- a/provider/provider.go
+++ b/provider/provider.go
@@ -58,10 +58,6 @@ func NewProvider() *schema.Provider {
"bytebase_project": dataSourceProject(),
"bytebase_project_list": dataSourceProjectList(),
"bytebase_setting": dataSourceSetting(),
- "bytebase_vcs_provider": dataSourceVCSProvider(),
- "bytebase_vcs_provider_list": dataSourceVCSProviderList(),
- "bytebase_vcs_connector": dataSourceVCSConnector(),
- "bytebase_vcs_connector_list": dataSourceVCSConnectorList(),
"bytebase_user": dataSourceUser(),
"bytebase_user_list": dataSourceUserList(),
"bytebase_role": dataSourceRole(),
@@ -79,8 +75,6 @@ func NewProvider() *schema.Provider {
"bytebase_policy": resourcePolicy(),
"bytebase_project": resourceProjct(),
"bytebase_setting": resourceSetting(),
- "bytebase_vcs_provider": resourceVCSProvider(),
- "bytebase_vcs_connector": resourceVCSConnector(),
"bytebase_user": resourceUser(),
"bytebase_role": resourceRole(),
"bytebase_group": resourceGroup(),
@@ -122,8 +116,8 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{},
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
- Summary: "Unable to create Bytebase client",
- Detail: err.Error(),
+ Summary: "Unable to create the Bytebase client",
+ Detail: fmt.Sprintf("failed to login with error: %v", err.Error()),
})
return nil, diags
diff --git a/provider/resource_database.go b/provider/resource_database.go
index 6fcf4ea..9bb0f35 100644
--- a/provider/resource_database.go
+++ b/provider/resource_database.go
@@ -43,10 +43,10 @@ func resourceDatabase() *schema.Resource {
Computed: true,
Description: "The database environment, will follow the instance environment by default",
},
- "sync_state": {
+ "state": {
Type: schema.TypeString,
Computed: true,
- Description: "The existence of a database on latest sync.",
+ Description: "The existence of a database.",
},
"successful_sync_time": {
Type: schema.TypeString,
@@ -251,8 +251,8 @@ func setDatabase(
if err := d.Set("environment", database.EffectiveEnvironment); err != nil {
return diag.Errorf("cannot set environment for database: %s", err.Error())
}
- if err := d.Set("sync_state", database.SyncState.String()); err != nil {
- return diag.Errorf("cannot set sync_state for database: %s", err.Error())
+ if err := d.Set("state", database.State.String()); err != nil {
+ return diag.Errorf("cannot set state for database: %s", err.Error())
}
if err := d.Set("successful_sync_time", database.SuccessfulSyncTime.AsTime().UTC().Format(time.RFC3339)); err != nil {
return diag.Errorf("cannot set successful_sync_time for database: %s", err.Error())
diff --git a/provider/resource_instance.go b/provider/resource_instance.go
index 739f3d0..99958bc 100644
--- a/provider/resource_instance.go
+++ b/provider/resource_instance.go
@@ -302,12 +302,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
externalLink := d.Get("external_link").(string)
environment := d.Get("environment").(string)
activation := d.Get("activation").(bool)
- instanceOptions := &v1pb.InstanceOptions{
- SyncInterval: &durationpb.Duration{
- Seconds: int64(d.Get("sync_interval").(int)),
- },
- MaximumConnections: int32(d.Get("maximum_connections").(int)),
+ syncInterval := &durationpb.Duration{
+ Seconds: int64(d.Get("sync_interval").(int)),
}
+ maximumConnections := int32(d.Get("maximum_connections").(int))
engineString := d.Get("engine").(string)
engineValue, ok := v1pb.Engine_value[engineString]
@@ -367,13 +365,11 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
if activation != existedInstance.Activation {
updateMasks = append(updateMasks, "activation")
}
- if op := existedInstance.Options; op != nil {
- if instanceOptions.SyncInterval.GetSeconds() != op.SyncInterval.GetSeconds() {
- updateMasks = append(updateMasks, "options.sync_interval")
- }
- if instanceOptions.MaximumConnections != op.MaximumConnections {
- updateMasks = append(updateMasks, "options.maximum_connections")
- }
+ if syncInterval.GetSeconds() != existedInstance.GetSyncInterval().GetSeconds() {
+ updateMasks = append(updateMasks, "sync_interval")
+ }
+ if maximumConnections != existedInstance.GetMaximumConnections() {
+ updateMasks = append(updateMasks, "maximum_connections")
}
if len(dataSourceList) > 0 {
updateMasks = append(updateMasks, "data_sources")
@@ -381,14 +377,15 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
if len(updateMasks) > 0 {
if _, err := c.UpdateInstance(ctx, &v1pb.Instance{
- Name: instanceName,
- Title: title,
- ExternalLink: externalLink,
- DataSources: dataSourceList,
- Environment: environment,
- Activation: activation,
- State: v1pb.State_ACTIVE,
- Options: instanceOptions,
+ Name: instanceName,
+ Title: title,
+ ExternalLink: externalLink,
+ DataSources: dataSourceList,
+ Environment: environment,
+ Activation: activation,
+ State: v1pb.State_ACTIVE,
+ SyncInterval: syncInterval,
+ MaximumConnections: maximumConnections,
}, updateMasks); err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
@@ -400,15 +397,16 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
}
} else {
if _, err := c.CreateInstance(ctx, instanceID, &v1pb.Instance{
- Name: instanceName,
- Title: title,
- Engine: engine,
- ExternalLink: externalLink,
- State: v1pb.State_ACTIVE,
- DataSources: dataSourceList,
- Environment: environment,
- Activation: activation,
- Options: instanceOptions,
+ Name: instanceName,
+ Title: title,
+ Engine: engine,
+ ExternalLink: externalLink,
+ State: v1pb.State_ACTIVE,
+ DataSources: dataSourceList,
+ Environment: environment,
+ Activation: activation,
+ SyncInterval: syncInterval,
+ MaximumConnections: maximumConnections,
}); err != nil {
return diag.FromErr(err)
}
@@ -514,10 +512,10 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
paths = append(paths, "data_sources")
}
if d.HasChange("sync_interval") {
- paths = append(paths, "options.sync_interval")
+ paths = append(paths, "sync_interval")
}
if d.HasChange("maximum_connections") {
- paths = append(paths, "options.maximum_connections")
+ paths = append(paths, "maximum_connections")
}
if len(paths) > 0 {
@@ -529,12 +527,10 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
Activation: d.Get("activation").(bool),
DataSources: dataSourceList,
State: v1pb.State_ACTIVE,
- Options: &v1pb.InstanceOptions{
- SyncInterval: &durationpb.Duration{
- Seconds: int64(d.Get("sync_interval").(int)),
- },
- MaximumConnections: int32(d.Get("maximum_connections").(int)),
+ SyncInterval: &durationpb.Duration{
+ Seconds: int64(d.Get("sync_interval").(int)),
},
+ MaximumConnections: int32(d.Get("maximum_connections").(int)),
}, paths); err != nil {
return diag.FromErr(err)
}
@@ -609,13 +605,11 @@ func setInstanceMessage(
if err := d.Set("external_link", instance.ExternalLink); err != nil {
return diag.Errorf("cannot set external_link for instance: %s", err.Error())
}
- if op := instance.Options; op != nil {
- if err := d.Set("sync_interval", op.GetSyncInterval().GetSeconds()); err != nil {
- return diag.Errorf("cannot set sync_interval for instance: %s", err.Error())
- }
- if err := d.Set("maximum_connections", op.GetMaximumConnections()); err != nil {
- return diag.Errorf("cannot set maximum_connections for instance: %s", err.Error())
- }
+ if err := d.Set("sync_interval", instance.GetSyncInterval().GetSeconds()); err != nil {
+ return diag.Errorf("cannot set sync_interval for instance: %s", err.Error())
+ }
+ if err := d.Set("maximum_connections", instance.GetMaximumConnections()); err != nil {
+ return diag.Errorf("cannot set maximum_connections for instance: %s", err.Error())
}
dataSources, err := flattenDataSourceList(d, instance.DataSources)
diff --git a/provider/resource_project.go b/provider/resource_project.go
index 3241d4b..ecb3bb0 100644
--- a/provider/resource_project.go
+++ b/provider/resource_project.go
@@ -51,11 +51,6 @@ func resourceProjct() *schema.Resource {
Computed: true,
Description: "The project full name in projects/{resource id} format.",
},
- "workflow": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The project workflow.",
- },
"allow_modify_statement": {
Type: schema.TypeBool,
Optional: true,
@@ -169,7 +164,6 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, m interf
Name: projectName,
Title: title,
State: v1pb.State_ACTIVE,
- Workflow: existedProject.Workflow,
AllowModifyStatement: allowModifyStatement,
AutoResolveIssue: autoResolveIssue,
EnforceIssueTitle: enforceIssueTitle,
@@ -190,7 +184,6 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, m interf
Name: projectName,
Title: title,
State: v1pb.State_ACTIVE,
- Workflow: v1pb.Workflow_UI,
AllowModifyStatement: allowModifyStatement,
AutoResolveIssue: autoResolveIssue,
EnforceIssueTitle: enforceIssueTitle,
@@ -295,7 +288,6 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, m interf
Name: projectName,
Title: d.Get("title").(string),
State: v1pb.State_ACTIVE,
- Workflow: existedProject.Workflow,
AllowModifyStatement: allowModifyStatement,
AutoResolveIssue: autoResolveIssue,
EnforceIssueTitle: enforceIssueTitle,
diff --git a/provider/resource_setting.go b/provider/resource_setting.go
index d008baf..2bd22cc 100644
--- a/provider/resource_setting.go
+++ b/provider/resource_setting.go
@@ -310,10 +310,6 @@ func convertToV1ApprovalSetting(d *schema.ResourceData) (*v1pb.WorkspaceApproval
approvalNode.Payload = &v1pb.ApprovalNode_GroupValue_{
GroupValue: v1pb.ApprovalNode_GroupValue(group),
}
- case api.ApprovalNodeTypeExternalNodeID:
- approvalNode.Payload = &v1pb.ApprovalNode_ExternalNodeId{
- ExternalNodeId: node,
- }
}
approvalStep := &v1pb.ApprovalStep{
diff --git a/provider/resource_vcs_connector.go b/provider/resource_vcs_connector.go
deleted file mode 100644
index 96eb7da..0000000
--- a/provider/resource_vcs_connector.go
+++ /dev/null
@@ -1,277 +0,0 @@
-package provider
-
-import (
- "context"
- "fmt"
- "regexp"
-
- "github.com/hashicorp/terraform-plugin-log/tflog"
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
-
- v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
-
- "github.com/bytebase/terraform-provider-bytebase/api"
- "github.com/bytebase/terraform-provider-bytebase/provider/internal"
-)
-
-func resourceVCSConnector() *schema.Resource {
- return &schema.Resource{
- Description: "The vcs connector resource.",
- CreateContext: resourceVCSConnectorCreate,
- ReadContext: resourceVCSConnectorRead,
- UpdateContext: resourceVCSConnectorUpdate,
- DeleteContext: resourceVCSConnectorDelete,
- Importer: &schema.ResourceImporter{
- StateContext: schema.ImportStatePassthroughContext,
- },
- Schema: map[string]*schema.Schema{
- "resource_id": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: internal.ResourceIDValidation,
- Description: "The vcs connector unique resource id.",
- },
- "project": {
- Type: schema.TypeString,
- Required: true,
- ValidateDiagFunc: internal.ResourceNameValidation(regexp.MustCompile(fmt.Sprintf("^%s%s$", internal.ProjectNamePrefix, internal.ResourceIDPattern))),
- Description: "The project name in projects/{resource id} format.",
- },
- "name": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs connector full name in projects/{project}/vcsConnector/{resource id} format.",
- },
- "title": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: validation.StringIsNotEmpty,
- Description: "The vcs connector title.",
- },
- "vcs_provider": {
- Type: schema.TypeString,
- Required: true,
- ValidateDiagFunc: internal.ResourceNameValidation(regexp.MustCompile(fmt.Sprintf("^%s%s$", internal.VCSProviderNamePrefix, internal.ResourceIDPattern))),
- Description: "The vcs provider full name in vcsProviders/{resource id} format.",
- },
- "database_group": {
- Type: schema.TypeString,
- Optional: true,
- Default: nil,
- Description: "Apply changes to the database group.",
- },
- "repository_id": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: validation.StringIsNotEmpty,
- Description: "The connected repository id in vcs provider.",
- },
- "repository_path": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: validation.StringIsNotEmpty,
- Description: "The connected repository path in vcs provider.",
- },
- "repository_directory": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: validation.StringIsNotEmpty,
- Description: "The connected repository directory in vcs provider.",
- },
- "repository_branch": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: validation.StringIsNotEmpty,
- Description: "The connected repository branch in vcs provider.",
- },
- "repository_url": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: validation.StringIsNotEmpty,
- Description: "The connected repository url in vcs provider.",
- },
- },
- }
-}
-
-func resourceVCSConnectorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
-
- fullName := d.Id()
- connector, err := c.GetVCSConnector(ctx, fullName)
- if err != nil {
- return diag.FromErr(err)
- }
-
- return setVCSConnector(d, connector)
-}
-
-func resourceVCSConnectorDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
- fullName := d.Id()
-
- // Warning or errors can be collected in a slice type
- var diags diag.Diagnostics
-
- if err := c.DeleteVCSConnector(ctx, fullName); err != nil {
- return diag.FromErr(err)
- }
-
- d.SetId("")
-
- return diags
-}
-
-func resourceVCSConnectorCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
-
- connectorID := d.Get("resource_id").(string)
- projectName := d.Get("project").(string)
- connectorName := fmt.Sprintf("%s/%s%s", projectName, internal.VCSConnectorNamePrefix, connectorID)
-
- existedConnector, err := c.GetVCSConnector(ctx, connectorName)
- if err != nil {
- tflog.Debug(ctx, fmt.Sprintf("get vcs connector %s failed with error: %v", connectorName, err))
- }
-
- title := d.Get("title").(string)
- vcsProviderName := d.Get("vcs_provider").(string)
- databaseGroup := d.Get("database_group").(string)
- repositoryID := d.Get("repository_id").(string)
- repositoryPath := d.Get("repository_path").(string)
- repositoryDirectory := d.Get("repository_directory").(string)
- repositoryBranch := d.Get("repository_branch").(string)
- repositoryURL := d.Get("repository_url").(string)
-
- var diags diag.Diagnostics
- if existedConnector != nil && err == nil {
- diags = append(diags, diag.Diagnostic{
- Severity: diag.Warning,
- Summary: "VCS connector already exists",
- Detail: fmt.Sprintf("VCS connector %s already exists, try to exec the update operation", connectorName),
- })
-
- updateMasks := []string{}
- if repositoryBranch != "" && repositoryBranch != existedConnector.Branch {
- updateMasks = append(updateMasks, "branch")
- }
- if repositoryDirectory != "" && repositoryDirectory != existedConnector.BaseDirectory {
- updateMasks = append(updateMasks, "base_directory")
- }
- if databaseGroup != "" && databaseGroup != existedConnector.DatabaseGroup {
- updateMasks = append(updateMasks, "database_group")
- }
-
- if len(updateMasks) > 0 {
- if _, err := c.UpdateVCSConnector(ctx, &v1pb.VCSConnector{
- Name: connectorName,
- Title: title,
- VcsProvider: existedConnector.VcsProvider,
- DatabaseGroup: databaseGroup,
- ExternalId: existedConnector.ExternalId,
- FullPath: existedConnector.FullPath,
- BaseDirectory: repositoryDirectory,
- Branch: repositoryBranch,
- WebUrl: existedConnector.WebUrl,
- }, updateMasks); err != nil {
- diags = append(diags, diag.Diagnostic{
- Severity: diag.Error,
- Summary: "Failed to update vcs connector",
- Detail: fmt.Sprintf("Update vcs connector %s failed, error: %v", connectorName, err),
- })
- return diags
- }
- }
- } else {
- if _, err := c.CreateVCSConnector(ctx, projectName, connectorID, &v1pb.VCSConnector{
- Name: connectorName,
- Title: title,
- VcsProvider: vcsProviderName,
- DatabaseGroup: databaseGroup,
- ExternalId: repositoryID,
- FullPath: repositoryPath,
- BaseDirectory: repositoryDirectory,
- Branch: repositoryBranch,
- WebUrl: repositoryURL,
- }); err != nil {
- return diag.FromErr(err)
- }
- }
-
- d.SetId(connectorName)
-
- diag := resourceVCSConnectorRead(ctx, d, m)
- if diag != nil {
- diags = append(diags, diag...)
- }
-
- return diags
-}
-
-func resourceVCSConnectorUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- if d.HasChange("resource_id") {
- return diag.Errorf("cannot change the resource id")
- }
- if d.HasChange("project") {
- return diag.Errorf("cannot change the project")
- }
- if d.HasChange("repository_id") {
- return diag.Errorf("cannot change the repository_id")
- }
- if d.HasChange("repository_path") {
- return diag.Errorf("cannot change the repository_path")
- }
- if d.HasChange("repository_url") {
- return diag.Errorf("cannot change the repository_url")
- }
-
- c := m.(api.Client)
- connectorName := d.Id()
-
- existedConnector, err := c.GetVCSConnector(ctx, connectorName)
- if err != nil {
- return diag.Errorf("get vcs connector %s failed with error: %v", connectorName, err)
- }
-
- paths := []string{}
- if d.HasChange("database_group") {
- paths = append(paths, "database_group")
- }
- if d.HasChange("repository_directory") {
- paths = append(paths, "base_directory")
- }
- if d.HasChange("repository_branch") {
- paths = append(paths, "branch")
- }
-
- var diags diag.Diagnostics
- if len(paths) > 0 {
- if _, err := c.UpdateVCSConnector(ctx, &v1pb.VCSConnector{
- Name: connectorName,
- Title: existedConnector.Title,
- VcsProvider: existedConnector.VcsProvider,
- DatabaseGroup: d.Get("database_group").(string),
- ExternalId: existedConnector.ExternalId,
- FullPath: existedConnector.FullPath,
- BaseDirectory: d.Get("repository_directory").(string),
- Branch: d.Get("repository_branch").(string),
- WebUrl: existedConnector.WebUrl,
- }, paths); err != nil {
- diags = append(diags, diag.Diagnostic{
- Severity: diag.Error,
- Summary: "Failed to update vcs connector",
- Detail: fmt.Sprintf("Update vcs connector %s failed, error: %v", connectorName, err),
- })
- return diags
- }
- }
-
- diag := resourceVCSConnectorRead(ctx, d, m)
- if diag != nil {
- diags = append(diags, diag...)
- }
-
- return diags
-}
diff --git a/provider/resource_vcs_provider.go b/provider/resource_vcs_provider.go
deleted file mode 100644
index de8e035..0000000
--- a/provider/resource_vcs_provider.go
+++ /dev/null
@@ -1,236 +0,0 @@
-package provider
-
-import (
- "context"
- "fmt"
-
- "github.com/hashicorp/terraform-plugin-log/tflog"
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
-
- v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
-
- "github.com/bytebase/terraform-provider-bytebase/api"
- "github.com/bytebase/terraform-provider-bytebase/provider/internal"
-)
-
-func resourceVCSProvider() *schema.Resource {
- return &schema.Resource{
- Description: "The vcs provider resource.",
- CreateContext: resourceVCSProviderCreate,
- ReadContext: resourceVCSProviderRead,
- UpdateContext: resourceVCSProviderUpdate,
- DeleteContext: resourceVCSProviderDelete,
- Importer: &schema.ResourceImporter{
- StateContext: schema.ImportStatePassthroughContext,
- },
- Schema: map[string]*schema.Schema{
- "resource_id": {
- Type: schema.TypeString,
- Required: true,
- ValidateFunc: internal.ResourceIDValidation,
- Description: "The vcs provider unique resource id.",
- },
- "title": {
- Type: schema.TypeString,
- Required: true,
- Description: "The vcs provider title.",
- ValidateFunc: validation.StringIsNotEmpty,
- },
- "name": {
- Type: schema.TypeString,
- Computed: true,
- Description: "The vcs provider full name in vcsProviders/{resource id} format.",
- },
- "url": {
- Type: schema.TypeString,
- Optional: true,
- Description: "The vcs provider url. You need to provide the url if you're using the self-host GitLab or self-host GitHub.",
- },
- "type": {
- Type: schema.TypeString,
- Required: true,
- Description: "The vcs provider type.",
- ValidateFunc: validation.StringInSlice([]string{
- v1pb.VCSType_GITHUB.String(),
- v1pb.VCSType_GITLAB.String(),
- v1pb.VCSType_BITBUCKET.String(),
- v1pb.VCSType_AZURE_DEVOPS.String(),
- }, false),
- },
- "access_token": {
- Type: schema.TypeString,
- Required: true,
- Sensitive: true,
- ValidateFunc: validation.StringIsNotEmpty,
- Description: "The vcs provider token. Check the docs https://bytebase.cc/docs/vcs-integration/add-git-provider for details.",
- },
- },
- }
-}
-
-func resourceVCSProviderRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
-
- fullName := d.Id()
- provider, err := c.GetVCSProvider(ctx, fullName)
- if err != nil {
- return diag.FromErr(err)
- }
-
- return setVCSProvider(d, provider)
-}
-
-func resourceVCSProviderDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
- fullName := d.Id()
-
- // Warning or errors can be collected in a slice type
- var diags diag.Diagnostics
-
- if err := c.DeleteVCSProvider(ctx, fullName); err != nil {
- return diag.FromErr(err)
- }
-
- d.SetId("")
-
- return diags
-}
-
-func resourceVCSProviderCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- c := m.(api.Client)
-
- providerID := d.Get("resource_id").(string)
- providerName := fmt.Sprintf("%s%s", internal.VCSProviderNamePrefix, providerID)
-
- existedProvider, err := c.GetVCSProvider(ctx, providerName)
- if err != nil {
- tflog.Debug(ctx, fmt.Sprintf("get vcs provider %s failed with error: %v", providerName, err))
- }
-
- title := d.Get("title").(string)
- url := d.Get("url").(string)
- vcsType := v1pb.VCSType(v1pb.VCSType_value[d.Get("type").(string)])
- token := d.Get("access_token").(string)
-
- var diags diag.Diagnostics
- if existedProvider != nil && err == nil {
- diags = append(diags, diag.Diagnostic{
- Severity: diag.Warning,
- Summary: "VCS provider already exists",
- Detail: fmt.Sprintf("VCS provider %s already exists, try to exec the update operation", providerName),
- })
-
- updateMasks := []string{}
- if token != "" {
- updateMasks = append(updateMasks, "access_token")
- }
- if title != "" && title != existedProvider.Title {
- updateMasks = append(updateMasks, "title")
- }
-
- if len(updateMasks) > 0 {
- if _, err := c.UpdateVCSProvider(ctx, &v1pb.VCSProvider{
- Name: providerName,
- Title: title,
- Url: existedProvider.Url,
- Type: existedProvider.Type,
- AccessToken: token,
- }, updateMasks); err != nil {
- diags = append(diags, diag.Diagnostic{
- Severity: diag.Error,
- Summary: "Failed to update vcs provider",
- Detail: fmt.Sprintf("Update vcs provider %s failed, error: %v", providerName, err),
- })
- return diags
- }
- }
- } else {
- switch vcsType {
- case v1pb.VCSType_GITHUB:
- if url == "" {
- url = "https://github.com"
- }
- case v1pb.VCSType_AZURE_DEVOPS:
- url = "https://dev.azure.com"
- case v1pb.VCSType_GITLAB:
- if url == "" {
- url = "https://gitlab.com"
- }
- case v1pb.VCSType_BITBUCKET:
- url = "https://bitbucket.org"
- }
- if url == "" {
- return diag.Errorf("missing url")
- }
- if _, err := c.CreateVCSProvider(ctx, providerID, &v1pb.VCSProvider{
- Name: providerName,
- Title: title,
- Url: url,
- Type: vcsType,
- AccessToken: token,
- }); err != nil {
- return diag.FromErr(err)
- }
- }
-
- d.SetId(providerName)
-
- diag := resourceVCSProviderRead(ctx, d, m)
- if diag != nil {
- diags = append(diags, diag...)
- }
-
- return diags
-}
-
-func resourceVCSProviderUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- if d.HasChange("resource_id") {
- return diag.Errorf("cannot change the resource id")
- }
-
- c := m.(api.Client)
- providerName := d.Id()
-
- existedProvider, err := c.GetVCSProvider(ctx, providerName)
- if err != nil {
- return diag.Errorf("get vcs provider %s failed with error: %v", providerName, err)
- }
-
- paths := []string{}
- if d.HasChange("type") {
- return diag.Errorf("cannot change the vcs provider type")
- }
- if d.HasChange("title") {
- paths = append(paths, "title")
- }
- if d.HasChange("access_token") {
- paths = append(paths, "access_token")
- }
-
- var diags diag.Diagnostics
- if len(paths) > 0 {
- if _, err := c.UpdateVCSProvider(ctx, &v1pb.VCSProvider{
- Name: providerName,
- Title: d.Get("title").(string),
- Url: existedProvider.Url,
- Type: existedProvider.Type,
- AccessToken: d.Get("access_token").(string),
- }, paths); err != nil {
- diags = append(diags, diag.Diagnostic{
- Severity: diag.Error,
- Summary: "Failed to update vcs provider",
- Detail: fmt.Sprintf("Update vcs provider %s failed, error: %v", providerName, err),
- })
- return diags
- }
- }
-
- diag := resourceVCSProviderRead(ctx, d, m)
- if diag != nil {
- diags = append(diags, diag...)
- }
-
- return diags
-}