Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gitlab/resource_gitlab_project_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}

Expand Down
31 changes: 26 additions & 5 deletions gitlab/resource_gitlab_project_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -79,13 +94,13 @@ func TestAccGitlabProjectCluster_import(t *testing.T) {
CheckDestroy: testAccCheckGitlabProjectClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccGitlabProjectClusterConfig(rInt),
Config: testAccGitlabProjectClusterConfig(rInt, true),
},
{
ResourceName: "gitlab_project_cluster.foo",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"enabled", "kubernetes_token"},
ImportStateVerifyIgnore: []string{"enabled", "kubernetes_token", "managed"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how hard is it to add a test that creates a cluster managed and one unmanaged, even if we can not read the status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I added a test but I'm not sure it really tests much

},
},
})
Expand Down Expand Up @@ -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 = <<EOF
Expand All @@ -208,12 +228,13 @@ resource gitlab_project_cluster "foo" {
project = "${gitlab_project.foo.id}"
name = "foo-cluster-%d"
domain = "example.com"
managed = "%s"
kubernetes_api_url = "https://123.123.123"
kubernetes_token = "some-token"
kubernetes_ca_cert = "${trimspace(var.cert)}"
kubernetes_authorization_type = "abac"
}
`, projectClusterFakeCert, rInt, rInt)
`, projectClusterFakeCert, rInt, rInt, m)
}

func testAccGitlabProjectClusterUpdateConfig(rInt int, authType string) string {
Expand Down
10 changes: 6 additions & 4 deletions website/docs/r/project_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 `*`.
Expand Down