Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Expose URNs for Kubernetes clusters. #626

Merged
merged 3 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions digitalocean/datasource_digitalocean_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func dataSourceDigitalOceanKubernetesCluster() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},

"urn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package digitalocean
import (
"context"
"fmt"
"regexp"
"testing"

"github.com/digitalocean/godo"
Expand All @@ -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" {
Expand Down Expand Up @@ -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),
),
},
},
Expand Down
6 changes: 6 additions & 0 deletions digitalocean/resource_digitalocean_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func resourceDigitalOceanKubernetesCluster() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},

"urn": {
Type: schema.TypeString,
Computed: true,
},
},

CustomizeDiff: customdiff.All(
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions digitalocean/resource_digitalocean_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package digitalocean

import (
"regexp"

"github.com/digitalocean/terraform-provider-digitalocean/internal/setutil"

"context"
Expand Down Expand Up @@ -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) },
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/kubernetes_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".
+ `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.
4 changes: 2 additions & 2 deletions docs/resources/kubernetes_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resource "digitalocean_kubernetes_cluster" "foo" {
name = "worker-pool"
size = "s-2vcpu-2gb"
node_count = 3

taint {
key = "workloadKind"
value = "database"
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
17 changes: 17 additions & 0 deletions vendor/github.com/digitalocean/godo/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion vendor/github.com/digitalocean/godo/apps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions vendor/github.com/digitalocean/godo/databases.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions vendor/github.com/digitalocean/godo/droplets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/digitalocean/godo/godo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions vendor/github.com/digitalocean/godo/kubernetes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/digitalocean/godo/sizes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.