diff --git a/docs/data-sources/stack.md b/docs/data-sources/stack.md index 846e4a80..ad9aa9c8 100644 --- a/docs/data-sources/stack.md +++ b/docs/data-sources/stack.md @@ -153,6 +153,7 @@ Read-Only: Read-Only: - `kubectl_version` (String) +- `kubernetes_workflow_tool` (String) - `namespace` (String) diff --git a/docs/data-sources/stacks.md b/docs/data-sources/stacks.md index e5d4ba60..fd8f20bb 100644 --- a/docs/data-sources/stacks.md +++ b/docs/data-sources/stacks.md @@ -250,6 +250,7 @@ Read-Only: Read-Only: - `kubectl_version` (String) +- `kubernetes_workflow_tool` (String) - `namespace` (String) diff --git a/docs/resources/stack.md b/docs/resources/stack.md index 5e0fdb59..c12b35a7 100644 --- a/docs/resources/stack.md +++ b/docs/resources/stack.md @@ -367,6 +367,7 @@ Read-Only: Optional: - `kubectl_version` (String) Kubectl version. +- `kubernetes_workflow_tool` (String) Defines the tool that will be used to execute the workflow. This can be one of `KUBERNETES` or `CUSTOM`. Defaults to `KUBERNETES`. - `namespace` (String) Namespace of the Kubernetes cluster to run commands on. Leave empty for multi-namespace Stacks. diff --git a/spacelift/data_stack.go b/spacelift/data_stack.go index 75e0b74f..7c4c86ed 100644 --- a/spacelift/data_stack.go +++ b/spacelift/data_stack.go @@ -322,6 +322,11 @@ func dataStack() *schema.Resource { Description: "Kubectl version.", Computed: true, }, + "kubernetes_workflow_tool": { + Type: schema.TypeString, + Description: "Defines the tool that will be used to execute the workflow. This can be one of `KUBERNETES` or `CUSTOM`. Defaults to `KUBERNETES`.", + Computed: true, + }, }, }, }, diff --git a/spacelift/data_stack_test.go b/spacelift/data_stack_test.go index 5688e6e4..90238e07 100644 --- a/spacelift/data_stack_test.go +++ b/spacelift/data_stack_test.go @@ -190,6 +190,7 @@ func TestStackData(t *testing.T) { Check: Resource( "data.spacelift_stack.test", Attribute("kubernetes.0.kubectl_version", IsNotEmpty()), + Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")), ), }}) }) @@ -214,6 +215,31 @@ func TestStackData(t *testing.T) { Check: Resource( "data.spacelift_stack.test", Attribute("kubernetes.0.kubectl_version", Equals("1.2.3")), + Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")), + ), + }}) + }) + + t.Run("with Kubernetes stack with a kubernetes workflow tool", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + + testSteps(t, []resource.TestStep{{ + Config: fmt.Sprintf(` + resource "spacelift_stack" "test" { + branch = "master" + name = "Test stack %s" + repository = "demo" + kubernetes { + kubernetes_workflow_tool = "CUSTOM" + } + } + data "spacelift_stack" "test" { + stack_id = spacelift_stack.test.id + } + `, randomID), + Check: Resource( + "data.spacelift_stack.test", + Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("CUSTOM")), ), }}) }) diff --git a/spacelift/internal/structs/stack.go b/spacelift/internal/structs/stack.go index 4d9f7b14..c892d8a8 100644 --- a/spacelift/internal/structs/stack.go +++ b/spacelift/internal/structs/stack.go @@ -80,6 +80,7 @@ type Stack struct { Kubernetes struct { Namespace string `graphql:"namespace"` KubectlVersion *string `graphql:"kubectlVersion"` + KubernetesWorkflowTool *string `graphql:"kubernetesWorkflowTool"` } `graphql:"... on StackConfigVendorKubernetes"` Pulumi struct { LoginURL string `graphql:"loginURL"` @@ -136,6 +137,7 @@ func (s *Stack) IaCSettings() (string, map[string]interface{}) { return "kubernetes", map[string]interface{}{ "namespace": s.VendorConfig.Kubernetes.Namespace, "kubectl_version": s.VendorConfig.Kubernetes.KubectlVersion, + "kubernetes_workflow_tool": s.VendorConfig.Kubernetes.KubernetesWorkflowTool, } case StackConfigVendorPulumi: return "pulumi", map[string]interface{}{ @@ -281,6 +283,7 @@ func PopulateStack(d *schema.ResourceData, stack *Stack) error { m := map[string]interface{}{ "namespace": stack.VendorConfig.Kubernetes.Namespace, "kubectl_version": stack.VendorConfig.Kubernetes.KubectlVersion, + "kubernetes_workflow_tool": stack.VendorConfig.Kubernetes.KubernetesWorkflowTool, } d.Set("kubernetes", []interface{}{m}) diff --git a/spacelift/internal/structs/stack_input.go b/spacelift/internal/structs/stack_input.go index 30a2f2e8..64cceddc 100644 --- a/spacelift/internal/structs/stack_input.go +++ b/spacelift/internal/structs/stack_input.go @@ -66,6 +66,7 @@ type CloudFormationInput struct { type KubernetesInput struct { Namespace graphql.String `json:"namespace"` KubectlVersion *graphql.String `json:"kubectlVersion"` + KubernetesWorkflowTool *graphql.String `json:"kubernetesWorkflowTool"` } // PulumiInput represents Pulumi-specific configuration. diff --git a/spacelift/resource_stack.go b/spacelift/resource_stack.go index bc8c3dfb..e95d9966 100644 --- a/spacelift/resource_stack.go +++ b/spacelift/resource_stack.go @@ -458,6 +458,13 @@ func resourceStack() *schema.Resource { Computed: true, ValidateDiagFunc: validations.DisallowEmptyString, }, + "kubernetes_workflow_tool": { + Type: schema.TypeString, + Description: "Defines the tool that will be used to execute the workflow. This can be one of `KUBERNETES` or `CUSTOM`. Defaults to `KUBERNETES`.", + Optional: true, + Computed: true, + ValidateDiagFunc: validations.DisallowEmptyString, + }, }, }, }, @@ -961,6 +968,9 @@ func getVendorConfig(d *schema.ResourceData) *structs.VendorConfigInput { if s := toOptionalString(kubernetesSettings["kubectl_version"]); *s != "" { vendorConfig.Kubernetes.KubectlVersion = s } + if s := toOptionalString(kubernetesSettings["kubernetes_workflow_tool"]); *s != "" { + vendorConfig.Kubernetes.KubernetesWorkflowTool = s + } } return vendorConfig } diff --git a/spacelift/resource_stack_test.go b/spacelift/resource_stack_test.go index da9194c2..d3cf1c2d 100644 --- a/spacelift/resource_stack_test.go +++ b/spacelift/resource_stack_test.go @@ -484,7 +484,7 @@ func TestStackResource(t *testing.T) { }) }) - t.Run("with GitHub and Kubernetes configuration", func(t *testing.T) { + t.Run("with GitHub and Kubernetes (default tool) configuration", func(t *testing.T) { testSteps(t, []resource.TestStep{ { Config: getConfig(`kubernetes {}`), @@ -493,6 +493,7 @@ func TestStackResource(t *testing.T) { Attribute("id", StartsWith("provider-test-stack")), Attribute("kubernetes.0.namespace", Equals("")), Attribute("kubernetes.0.kubectl_version", IsNotEmpty()), + Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")), Attribute("ansible.#", Equals("0")), Attribute("pulumi.#", Equals("0")), Attribute("cloudformation.#", Equals("0")), @@ -508,6 +509,7 @@ func TestStackResource(t *testing.T) { Attribute("id", StartsWith("provider-test-stack")), Attribute("kubernetes.0.namespace", Equals("myapp-prod")), Attribute("kubernetes.0.kubectl_version", IsNotEmpty()), + Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")), Attribute("ansible.#", Equals("0")), Attribute("pulumi.#", Equals("0")), Attribute("cloudformation.#", Equals("0")), @@ -522,6 +524,27 @@ func TestStackResource(t *testing.T) { Attribute("id", StartsWith("provider-test-stack")), Attribute("kubernetes.0.namespace", Equals("")), Attribute("kubernetes.0.kubectl_version", Equals("1.2.3")), + Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")), + Attribute("ansible.#", Equals("0")), + Attribute("pulumi.#", Equals("0")), + Attribute("cloudformation.#", Equals("0")), + ), + }, + }) + }) + + t.Run("with GitHub and Kubernetes (CUSTOM) configuration", func(t *testing.T) { + testSteps(t, []resource.TestStep{ + { + Config: getConfig(`kubernetes { + namespace = "myapp-prod" + kubernetes_workflow_tool = "CUSTOM" + }`), + Check: Resource( + resourceName, + Attribute("id", StartsWith("provider-test-stack")), + Attribute("kubernetes.0.namespace", Equals("myapp-prod")), + Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("CUSTOM")), Attribute("ansible.#", Equals("0")), Attribute("pulumi.#", Equals("0")), Attribute("cloudformation.#", Equals("0")), @@ -1285,6 +1308,8 @@ func TestStackResourceSpace(t *testing.T) { Attribute("repository", Equals("demo")), Attribute("runner_image", Equals("custom_image:runner")), Attribute("kubernetes.0.namespace", Equals("myapp-prod")), + Attribute("kubernetes.0.kubectl_version", IsNotEmpty()), + Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")), Attribute("ansible.#", Equals("0")), Attribute("pulumi.#", Equals("0")), Attribute("cloudformation.#", Equals("0")),