From 4c6e10102b728f189cd1486231c3a28f4bfde704 Mon Sep 17 00:00:00 2001 From: Brandon Dimcheff Date: Fri, 24 May 2019 12:40:35 -0400 Subject: [PATCH 1/4] add support for managed clusters The gitlab api has a "managed" field to disable cluster management features when adding a kubernetes cluster. This implements that field. Default is true if you don't supply it. This can only be toggled at cluster creation time, so changes will delete and readd the integration. https://docs.gitlab.com/ee/api/project_clusters.html#add-existing-cluster-to-project --- gitlab/resource_gitlab_project_cluster.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gitlab/resource_gitlab_project_cluster.go b/gitlab/resource_gitlab_project_cluster.go index 0759fc67f..e30b3f8ee 100644 --- a/gitlab/resource_gitlab_project_cluster.go +++ b/gitlab/resource_gitlab_project_cluster.go @@ -40,6 +40,12 @@ func resourceGitlabProjectCluster() *schema.Resource { Default: true, ForceNew: true, }, + "managed": { + Type: schema.TypeBool, + Optional: true, + Default: true, + ForceNew: true, + }, "created_at": { Type: schema.TypeString, Computed: true, @@ -113,6 +119,7 @@ func resourceGitlabProjectClusterCreate(d *schema.ResourceData, meta interface{} options := &gitlab.AddClusterOptions{ Name: gitlab.String(d.Get("name").(string)), Enabled: gitlab.Bool(d.Get("enabled").(bool)), + Managed: gitlab.Bool(d.Get("managed").(bool)), PlatformKubernetes: &pk, } From 3a9b37f93e820eb4390fa97aa81026e1094a816f Mon Sep 17 00:00:00 2001 From: Brandon Dimcheff Date: Fri, 24 May 2019 13:07:46 -0400 Subject: [PATCH 2/4] ignore managed flag in cluster import tests --- gitlab/resource_gitlab_project_cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/resource_gitlab_project_cluster_test.go b/gitlab/resource_gitlab_project_cluster_test.go index 0fb839e3d..47504f520 100644 --- a/gitlab/resource_gitlab_project_cluster_test.go +++ b/gitlab/resource_gitlab_project_cluster_test.go @@ -85,7 +85,7 @@ func TestAccGitlabProjectCluster_import(t *testing.T) { ResourceName: "gitlab_project_cluster.foo", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"enabled", "kubernetes_token"}, + ImportStateVerifyIgnore: []string{"enabled", "kubernetes_token", "managed"}, }, }, }) From a50a368402f99d3a3b372efeeed044f9e25496cf Mon Sep 17 00:00:00 2001 From: Brandon Dimcheff Date: Fri, 24 May 2019 14:58:12 -0400 Subject: [PATCH 3/4] add documentation for managed flag in project_cluster --- website/docs/r/project_cluster.html.markdown | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/website/docs/r/project_cluster.html.markdown b/website/docs/r/project_cluster.html.markdown index db522f49c..fd0f79e70 100644 --- a/website/docs/r/project_cluster.html.markdown +++ b/website/docs/r/project_cluster.html.markdown @@ -44,16 +44,18 @@ The following arguments are supported: * `domain` - (Optional, string) The base domain of the cluster. -* `enabled` - (Optional, boolean) Determines if cluster is active or not. Defaults to `true`. +* `enabled` - (Optional, boolean) Determines if cluster is active or not. Defaults to `true`. This attribute cannot be read. + +* `managed` - (Optional, boolean) Determines if cluster is managed by gitlab or not. Defaults to `true`. This attribute cannot be read. * `kubernetes_api_url` - (Required, string) The URL to access the Kubernetes API. * `kubernetes_token` - (Required, string) The token to authenticate against Kubernetes. - + * `kubernetes_ca_cert` - (Optional, string) TLS certificate (needed if API is using a self-signed TLS certificate). - + * `kubernetes_namespace` - (Optional, string) The unique namespace related to the project. - + * `kubernetes_authorization_type` - (Optional, string) The cluster authorization type. Valid values are `rbac`, `abac`, `unknown_authorization`. Defaults to `rbac`. * `environment_scope` - (Optional, string) The associated environment to the cluster. Defaults to `*`. From 469d3554be19a0e4b049fcbb184f39c1f49de751 Mon Sep 17 00:00:00 2001 From: Brandon Dimcheff Date: Fri, 7 Jun 2019 11:03:07 -0400 Subject: [PATCH 4/4] add a test that creates an unmanaged cluster --- .../resource_gitlab_project_cluster_test.go | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gitlab/resource_gitlab_project_cluster_test.go b/gitlab/resource_gitlab_project_cluster_test.go index 47504f520..e5eebf9b7 100644 --- a/gitlab/resource_gitlab_project_cluster_test.go +++ b/gitlab/resource_gitlab_project_cluster_test.go @@ -21,7 +21,22 @@ func TestAccGitlabProjectCluster_basic(t *testing.T) { Steps: []resource.TestStep{ // Create a project and cluster with default options { - Config: testAccGitlabProjectClusterConfig(rInt), + Config: testAccGitlabProjectClusterConfig(rInt, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckGitlabProjectClusterExists("gitlab_project_cluster.foo", &cluster), + testAccCheckGitlabProjectClusterAttributes(&cluster, &testAccGitlabProjectClusterExpectedAttributes{ + Name: fmt.Sprintf("foo-cluster-%d", rInt), + Domain: "example.com", + EnvironmentScope: "*", + KubernetesApiURL: "https://123.123.123", + KubernetesCACert: projectClusterFakeCert, + KubernetesAuthorizationType: "abac", + }), + ), + }, + // create an unmanaged cluster + { + Config: testAccGitlabProjectClusterConfig(rInt, false), Check: resource.ComposeTestCheckFunc( testAccCheckGitlabProjectClusterExists("gitlab_project_cluster.foo", &cluster), testAccCheckGitlabProjectClusterAttributes(&cluster, &testAccGitlabProjectClusterExpectedAttributes{ @@ -79,7 +94,7 @@ func TestAccGitlabProjectCluster_import(t *testing.T) { CheckDestroy: testAccCheckGitlabProjectClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGitlabProjectClusterConfig(rInt), + Config: testAccGitlabProjectClusterConfig(rInt, true), }, { ResourceName: "gitlab_project_cluster.foo", @@ -187,7 +202,12 @@ func testAccCheckGitlabProjectClusterAttributes(cluster *gitlab.ProjectCluster, } } -func testAccGitlabProjectClusterConfig(rInt int) string { +func testAccGitlabProjectClusterConfig(rInt int, managed bool) string { + m := "false" + if managed { + m = "true" + } + return fmt.Sprintf(` variable "cert" { default = <