From 143734b16ade2bc9ef176c80c2215ae381fb656e Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Mon, 26 Apr 2021 10:51:47 -0400 Subject: [PATCH 1/2] Bump godo to v1.60.0 --- go.mod | 2 +- go.sum | 4 +- .../github.com/digitalocean/godo/CHANGELOG.md | 17 +++++++ vendor/github.com/digitalocean/godo/apps.go | 34 ++++++++++++- .../github.com/digitalocean/godo/databases.go | 23 ++++++--- .../github.com/digitalocean/godo/droplets.go | 20 ++++---- vendor/github.com/digitalocean/godo/godo.go | 2 +- .../digitalocean/godo/kubernetes.go | 17 +++++-- vendor/github.com/digitalocean/godo/sizes.go | 1 + vendor/github.com/digitalocean/godo/vpcs.go | 49 +++++++++++++++++++ vendor/modules.txt | 2 +- 11 files changed, 144 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index e6b832de0..4fb36437f 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/digitalocean/terraform-provider-digitalocean require ( github.com/aws/aws-sdk-go v1.25.4 - github.com/digitalocean/godo v1.57.0 + github.com/digitalocean/godo v1.60.0 github.com/hashicorp/go-version v1.2.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.3 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index d8c99a3d3..0d51171f8 100644 --- a/go.sum +++ b/go.sum @@ -71,8 +71,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/digitalocean/godo v1.57.0 h1:uCpe0sRIZ/sJWxWDsJyBPBjUfSvxop+WHkHiSf+tjjM= -github.com/digitalocean/godo v1.57.0/go.mod h1:p7dOjjtSBqCTUksqtA5Fd3uaKs9kyTq2xcz76ulEJRU= +github.com/digitalocean/godo v1.60.0 h1:o/vimtn/HKtYSakFAAZ59Zc5ASORd41S4z1X7pAXPn8= +github.com/digitalocean/godo v1.60.0/go.mod h1:p7dOjjtSBqCTUksqtA5Fd3uaKs9kyTq2xcz76ulEJRU= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/vendor/github.com/digitalocean/godo/CHANGELOG.md b/vendor/github.com/digitalocean/godo/CHANGELOG.md index ac3cd1bb7..95cd1c1c0 100644 --- a/vendor/github.com/digitalocean/godo/CHANGELOG.md +++ b/vendor/github.com/digitalocean/godo/CHANGELOG.md @@ -1,5 +1,22 @@ # Change Log +## [v1.60.0] - 2021-04-04 + +- #443 - @andrewsomething - apps: Support pagination. +- #442 - @andrewsomething - dbaas: Support restoring from a backup. +- #441 - @andrewsomething - k8s: Add URN method to KubernetesCluster. + +## [v1.59.0] - 2021-03-29 + +- #439 - @andrewsomething - vpcs: Support listing members of a VPC. +- #438 - @andrewsomething - Add Go 1.16.x to the testing matrix. + +## [v1.58.0] - 2021-02-17 + +- #436 - @MorrisLaw - kubernetes: add name field to associated resources +- #434 - @andrewsomething - sizes: Add description field. +- #433 - @andrewsomething - Deprecate Name field in godo.DropletCreateVolume + ## [v1.57.0] - 2021-01-15 - #429 - @varshavaradarajan - kubernetes: support optional cascading deletes for clusters diff --git a/vendor/github.com/digitalocean/godo/apps.go b/vendor/github.com/digitalocean/godo/apps.go index f8cec3f99..6079e2821 100644 --- a/vendor/github.com/digitalocean/godo/apps.go +++ b/vendor/github.com/digitalocean/godo/apps.go @@ -73,7 +73,9 @@ type appRoot struct { } type appsRoot struct { - Apps []*App `json:"apps"` + Apps []*App `json:"apps"` + Links *Links `json:"links"` + Meta *Meta `json:"meta"` } type deploymentRoot struct { @@ -82,6 +84,8 @@ type deploymentRoot struct { type deploymentsRoot struct { Deployments []*Deployment `json:"deployments"` + Links *Links `json:"links"` + Meta *Meta `json:"meta"` } type appTierRoot struct { @@ -143,6 +147,11 @@ func (s *AppsServiceOp) Get(ctx context.Context, appID string) (*App, *Response, // List apps. func (s *AppsServiceOp) List(ctx context.Context, opts *ListOptions) ([]*App, *Response, error) { path := appsBasePath + path, err := addOptions(path, opts) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, nil, err @@ -152,6 +161,15 @@ func (s *AppsServiceOp) List(ctx context.Context, opts *ListOptions) ([]*App, *R if err != nil { return nil, resp, err } + + if l := root.Links; l != nil { + resp.Links = l + } + + if m := root.Meta; m != nil { + resp.Meta = m + } + return root.Apps, resp, nil } @@ -219,6 +237,11 @@ func (s *AppsServiceOp) GetDeployment(ctx context.Context, appID, deploymentID s // ListDeployments lists an app deployments. func (s *AppsServiceOp) ListDeployments(ctx context.Context, appID string, opts *ListOptions) ([]*Deployment, *Response, error) { path := fmt.Sprintf("%s/%s/deployments", appsBasePath, appID) + path, err := addOptions(path, opts) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, nil, err @@ -228,6 +251,15 @@ func (s *AppsServiceOp) ListDeployments(ctx context.Context, appID string, opts if err != nil { return nil, resp, err } + + if l := root.Links; l != nil { + resp.Links = l + } + + if m := root.Meta; m != nil { + resp.Meta = m + } + return root.Deployments, resp, nil } diff --git a/vendor/github.com/digitalocean/godo/databases.go b/vendor/github.com/digitalocean/godo/databases.go index 5d90d37d0..d98f5de61 100644 --- a/vendor/github.com/digitalocean/godo/databases.go +++ b/vendor/github.com/digitalocean/godo/databases.go @@ -193,16 +193,23 @@ type DatabaseBackup struct { SizeGigabytes float64 `json:"size_gigabytes,omitempty"` } +// DatabaseBackupRestore contains information needed to restore a backup. +type DatabaseBackupRestore struct { + DatabaseName string `json:"database_name,omitempty"` + BackupCreatedAt string `json:"backup_created_at,omitempty"` +} + // DatabaseCreateRequest represents a request to create a database cluster type DatabaseCreateRequest struct { - Name string `json:"name,omitempty"` - EngineSlug string `json:"engine,omitempty"` - Version string `json:"version,omitempty"` - SizeSlug string `json:"size,omitempty"` - Region string `json:"region,omitempty"` - NumNodes int `json:"num_nodes,omitempty"` - PrivateNetworkUUID string `json:"private_network_uuid"` - Tags []string `json:"tags,omitempty"` + Name string `json:"name,omitempty"` + EngineSlug string `json:"engine,omitempty"` + Version string `json:"version,omitempty"` + SizeSlug string `json:"size,omitempty"` + Region string `json:"region,omitempty"` + NumNodes int `json:"num_nodes,omitempty"` + PrivateNetworkUUID string `json:"private_network_uuid"` + Tags []string `json:"tags,omitempty"` + BackupRestore *DatabaseBackupRestore `json:"backup_restore,omitempty"` } // DatabaseResizeRequest can be used to initiate a database resize operation. diff --git a/vendor/github.com/digitalocean/godo/droplets.go b/vendor/github.com/digitalocean/godo/droplets.go index d08a905fb..460fe403d 100644 --- a/vendor/github.com/digitalocean/godo/droplets.go +++ b/vendor/github.com/digitalocean/godo/droplets.go @@ -177,25 +177,25 @@ func (d DropletCreateImage) MarshalJSON() ([]byte, error) { return json.Marshal(d.ID) } -// DropletCreateVolume identifies a volume to attach for the create request. It -// prefers Name over ID, +// DropletCreateVolume identifies a volume to attach for the create request. type DropletCreateVolume struct { - ID string + ID string + // Deprecated: You must pass a the volume's ID when creating a Droplet. Name string } -// MarshalJSON returns an object with either the name or id of the volume. It -// returns the id if the name is empty. +// MarshalJSON returns an object with either the ID or name of the volume. It +// prefers the ID over the name. func (d DropletCreateVolume) MarshalJSON() ([]byte, error) { - if d.Name != "" { + if d.ID != "" { return json.Marshal(struct { - Name string `json:"name"` - }{Name: d.Name}) + ID string `json:"id"` + }{ID: d.ID}) } return json.Marshal(struct { - ID string `json:"id"` - }{ID: d.ID}) + Name string `json:"name"` + }{Name: d.Name}) } // DropletCreateSSHKey identifies a SSH Key for the create request. It prefers fingerprint over ID. diff --git a/vendor/github.com/digitalocean/godo/godo.go b/vendor/github.com/digitalocean/godo/godo.go index 1219dc0d7..4ec8f02f7 100644 --- a/vendor/github.com/digitalocean/godo/godo.go +++ b/vendor/github.com/digitalocean/godo/godo.go @@ -20,7 +20,7 @@ import ( ) const ( - libraryVersion = "1.57.0" + libraryVersion = "1.60.0" defaultBaseURL = "https://api.digitalocean.com/" userAgent = "godo/" + libraryVersion mediaType = "application/json" diff --git a/vendor/github.com/digitalocean/godo/kubernetes.go b/vendor/github.com/digitalocean/godo/kubernetes.go index 4e4dc164d..5f37f9e31 100644 --- a/vendor/github.com/digitalocean/godo/kubernetes.go +++ b/vendor/github.com/digitalocean/godo/kubernetes.go @@ -202,6 +202,11 @@ type KubernetesCluster struct { UpdatedAt time.Time `json:"updated_at,omitempty"` } +// URN returns the Kubernetes cluster's ID in the format of DigitalOcean URN. +func (kc KubernetesCluster) URN() string { + return ToURN("Kubernetes", kc.ID) +} + // KubernetesClusterUser represents a Kubernetes cluster user. type KubernetesClusterUser struct { Username string `json:"username,omitempty"` @@ -457,9 +462,15 @@ type ClusterlintOwner struct { // KubernetesAssociatedResources represents a cluster's associated resources type KubernetesAssociatedResources struct { - Volumes []string `json:"volumes"` - VolumeSnapshots []string `json:"volume_snapshots"` - LoadBalancers []string `json:"load_balancers"` + Volumes []*AssociatedResource `json:"volumes"` + VolumeSnapshots []*AssociatedResource `json:"volume_snapshots"` + LoadBalancers []*AssociatedResource `json:"load_balancers"` +} + +// AssociatedResource is the object to represent a Kubernetes cluster associated resource's Id and Name. +type AssociatedResource struct { + ID string `json:"id"` + Name string `json:"name"` } type kubernetesClustersRoot struct { diff --git a/vendor/github.com/digitalocean/godo/sizes.go b/vendor/github.com/digitalocean/godo/sizes.go index d2b93ea7f..cff6970db 100644 --- a/vendor/github.com/digitalocean/godo/sizes.go +++ b/vendor/github.com/digitalocean/godo/sizes.go @@ -31,6 +31,7 @@ type Size struct { Regions []string `json:"regions,omitempty"` Available bool `json:"available,omitempty"` Transfer float64 `json:"transfer,omitempty"` + Description string `json:"description,omitempty"` } func (s Size) String() string { diff --git a/vendor/github.com/digitalocean/godo/vpcs.go b/vendor/github.com/digitalocean/godo/vpcs.go index 6c7b141c9..97c5c2d00 100644 --- a/vendor/github.com/digitalocean/godo/vpcs.go +++ b/vendor/github.com/digitalocean/godo/vpcs.go @@ -15,6 +15,7 @@ type VPCsService interface { Create(context.Context, *VPCCreateRequest) (*VPC, *Response, error) Get(context.Context, string) (*VPC, *Response, error) List(context.Context, *ListOptions) ([]*VPC, *Response, error) + ListMembers(context.Context, string, *VPCListMembersRequest, *ListOptions) ([]*VPCMember, *Response, error) Update(context.Context, string, *VPCUpdateRequest) (*VPC, *Response, error) Set(context.Context, string, ...VPCSetField) (*VPC, *Response, error) Delete(context.Context, string) (*Response, error) @@ -77,6 +78,16 @@ type VPC struct { Default bool `json:"default,omitempty"` } +type VPCListMembersRequest struct { + ResourceType string `url:"resource_type,omitempty"` +} + +type VPCMember struct { + URN string `json:"urn,omitempty"` + Name string `json:"name,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` +} + type vpcRoot struct { VPC *VPC `json:"vpc"` } @@ -87,6 +98,12 @@ type vpcsRoot struct { Meta *Meta `json:"meta"` } +type vpcMembersRoot struct { + Members []*VPCMember `json:"members"` + Links *Links `json:"links"` + Meta *Meta `json:"meta"` +} + // Get returns the details of a Virtual Private Cloud. func (v *VPCsServiceOp) Get(ctx context.Context, id string) (*VPC, *Response, error) { path := vpcsBasePath + "/" + id @@ -214,3 +231,35 @@ func (v *VPCsServiceOp) Delete(ctx context.Context, id string) (*Response, error return resp, nil } + +func (v *VPCsServiceOp) ListMembers(ctx context.Context, id string, request *VPCListMembersRequest, opt *ListOptions) ([]*VPCMember, *Response, error) { + path := vpcsBasePath + "/" + id + "/members" + pathWithResourceType, err := addOptions(path, request) + if err != nil { + return nil, nil, err + } + pathWithOpts, err := addOptions(pathWithResourceType, opt) + if err != nil { + return nil, nil, err + } + + req, err := v.client.NewRequest(ctx, http.MethodGet, pathWithOpts, nil) + if err != nil { + return nil, nil, err + } + + root := new(vpcMembersRoot) + resp, err := v.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + if l := root.Links; l != nil { + resp.Links = l + } + if m := root.Meta; m != nil { + resp.Meta = m + } + + return root.Members, resp, nil + +} diff --git a/vendor/modules.txt b/vendor/modules.txt index f50ace045..4d9332fd8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -57,7 +57,7 @@ github.com/aws/aws-sdk-go/service/sts/stsiface github.com/bgentry/go-netrc/netrc # github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew/spew -# github.com/digitalocean/godo v1.57.0 +# github.com/digitalocean/godo v1.60.0 ## explicit github.com/digitalocean/godo # github.com/emirpasic/gods v1.12.0 From f33627984697b17689cecd2545d93981c8024aee Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Mon, 26 Apr 2021 11:49:58 -0400 Subject: [PATCH 2/2] Expose URNs for Kubernetes clusters. --- digitalocean/datasource_digitalocean_kubernetes_cluster.go | 5 +++++ .../datasource_digitalocean_kubernetes_cluster_test.go | 3 +++ digitalocean/resource_digitalocean_kubernetes_cluster.go | 6 ++++++ .../resource_digitalocean_kubernetes_cluster_test.go | 4 ++++ docs/data-sources/kubernetes_cluster.md | 3 ++- docs/resources/kubernetes_cluster.md | 4 ++-- 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/digitalocean/datasource_digitalocean_kubernetes_cluster.go b/digitalocean/datasource_digitalocean_kubernetes_cluster.go index 528fd3a3f..b32d59d9a 100644 --- a/digitalocean/datasource_digitalocean_kubernetes_cluster.go +++ b/digitalocean/datasource_digitalocean_kubernetes_cluster.go @@ -99,6 +99,11 @@ func dataSourceDigitalOceanKubernetesCluster() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + + "urn": { + Type: schema.TypeString, + Computed: true, + }, }, } } diff --git a/digitalocean/datasource_digitalocean_kubernetes_cluster_test.go b/digitalocean/datasource_digitalocean_kubernetes_cluster_test.go index 9ecc6852c..8dce9ad16 100644 --- a/digitalocean/datasource_digitalocean_kubernetes_cluster_test.go +++ b/digitalocean/datasource_digitalocean_kubernetes_cluster_test.go @@ -3,6 +3,7 @@ package digitalocean import ( "context" "fmt" + "regexp" "testing" "github.com/digitalocean/godo" @@ -13,6 +14,7 @@ import ( func TestAccDataSourceDigitalOceanKubernetesCluster_Basic(t *testing.T) { rName := randomTestName() var k8s godo.KubernetesCluster + expectedURNRegEx, _ := regexp.Compile(`do:kubernetes:[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}`) resourceConfig := testAccDigitalOceanKubernetesConfigForDataSource(testClusterVersion19, rName) dataSourceConfig := ` data "digitalocean_kubernetes_cluster" "foobar" { @@ -43,6 +45,7 @@ data "digitalocean_kubernetes_cluster" "foobar" { resource.TestCheckResourceAttr("data.digitalocean_kubernetes_cluster.foobar", "node_pool.0.labels.priority", "high"), resource.TestCheckResourceAttrSet("data.digitalocean_kubernetes_cluster.foobar", "vpc_uuid"), resource.TestCheckResourceAttrSet("data.digitalocean_kubernetes_cluster.foobar", "auto_upgrade"), + resource.TestMatchResourceAttr("data.digitalocean_kubernetes_cluster.foobar", "urn", expectedURNRegEx), ), }, }, diff --git a/digitalocean/resource_digitalocean_kubernetes_cluster.go b/digitalocean/resource_digitalocean_kubernetes_cluster.go index 922c87e38..fd4324dca 100644 --- a/digitalocean/resource_digitalocean_kubernetes_cluster.go +++ b/digitalocean/resource_digitalocean_kubernetes_cluster.go @@ -118,6 +118,11 @@ func resourceDigitalOceanKubernetesCluster() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + + "urn": { + Type: schema.TypeString, + Computed: true, + }, }, CustomizeDiff: customdiff.All( @@ -278,6 +283,7 @@ func digitaloceanKubernetesClusterRead( d.Set("updated_at", cluster.UpdatedAt.UTC().String()) d.Set("vpc_uuid", cluster.VPCUUID) d.Set("auto_upgrade", cluster.AutoUpgrade) + d.Set("urn", cluster.URN()) // find the default node pool from all the pools in the cluster // the default node pool has a custom tag terraform:default-node-pool diff --git a/digitalocean/resource_digitalocean_kubernetes_cluster_test.go b/digitalocean/resource_digitalocean_kubernetes_cluster_test.go index 6c3412129..150ee11e6 100644 --- a/digitalocean/resource_digitalocean_kubernetes_cluster_test.go +++ b/digitalocean/resource_digitalocean_kubernetes_cluster_test.go @@ -1,6 +1,8 @@ package digitalocean import ( + "regexp" + "github.com/digitalocean/terraform-provider-digitalocean/internal/setutil" "context" @@ -64,6 +66,7 @@ func testSweepKubernetesClusters(region string) error { func TestAccDigitalOceanKubernetesCluster_Basic(t *testing.T) { rName := randomTestName() var k8s godo.KubernetesCluster + expectedURNRegEx, _ := regexp.Compile(`do:kubernetes:[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}`) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -111,6 +114,7 @@ func TestAccDigitalOceanKubernetesCluster_Basic(t *testing.T) { resource.TestCheckResourceAttrSet("digitalocean_kubernetes_cluster.foobar", "kube_config.0.expires_at"), resource.TestCheckResourceAttrSet("digitalocean_kubernetes_cluster.foobar", "vpc_uuid"), resource.TestCheckResourceAttrSet("digitalocean_kubernetes_cluster.foobar", "auto_upgrade"), + resource.TestMatchResourceAttr("digitalocean_kubernetes_cluster.foobar", "urn", expectedURNRegEx), ), }, // Update: remove default node_pool taints diff --git a/docs/data-sources/kubernetes_cluster.md b/docs/data-sources/kubernetes_cluster.md index 9d00548a1..0498618de 100644 --- a/docs/data-sources/kubernetes_cluster.md +++ b/docs/data-sources/kubernetes_cluster.md @@ -73,4 +73,5 @@ The following attributes are exported: - `taint` - A list of taints applied to all nodes in the pool. Each taint exports the following attributes: + `key` - An arbitrary string. The "key" and "value" fields of the "taint" object form a key-value pair. + `value` - An arbitrary string. The "key" and "value" fields of the "taint" object form a key-value pair. - + `effect` - How the node reacts to pods that it won't tolerate. Available effect values are: "NoSchedule", "PreferNoSchedule", "NoExecute". \ No newline at end of file + + `effect` - How the node reacts to pods that it won't tolerate. Available effect values are: "NoSchedule", "PreferNoSchedule", "NoExecute". +* `urn` - The uniform resource name (URN) for the Kubernetes cluster. \ No newline at end of file diff --git a/docs/resources/kubernetes_cluster.md b/docs/resources/kubernetes_cluster.md index a3080e2ad..e33ef0a8b 100644 --- a/docs/resources/kubernetes_cluster.md +++ b/docs/resources/kubernetes_cluster.md @@ -21,7 +21,7 @@ resource "digitalocean_kubernetes_cluster" "foo" { name = "worker-pool" size = "s-2vcpu-2gb" node_count = 3 - + taint { key = "workloadKind" value = "database" @@ -189,7 +189,7 @@ In addition to the arguments listed above, the following additional attributes a + `key` - An arbitrary string. The "key" and "value" fields of the "taint" object form a key-value pair. + `value` - An arbitrary string. The "key" and "value" fields of the "taint" object form a key-value pair. + `effect` - How the node reacts to pods that it won't tolerate. Available effect values are: "NoSchedule", "PreferNoSchedule", "NoExecute". - +* `urn` - The uniform resource name (URN) for the Kubernetes cluster. ## Import