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

Update the kubernetes #164

Merged
merged 1 commit into from
Feb 8, 2023
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
4 changes: 2 additions & 2 deletions civo/datasource_kubernetes_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func flattenKubernetesVersion(version, _ interface{}, _ map[string]interface{})
flattenedVersion := map[string]interface{}{}
flattenedVersion["version"] = s.Version
flattenedVersion["label"] = fmt.Sprintf("v%s", s.Version)
flattenedVersion["type"] = s.Type
flattenedVersion["type"] = s.ClusterType
flattenedVersion["default"] = s.Default
return flattenedVersion, nil
}
Expand All @@ -67,7 +67,7 @@ func kubernetesVersionSchema() map[string]*schema.Schema {
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of the version - can be `stable`, `legacy` & etc",
Description: "The type of the cluster, can be `talos` or `k3s`",
},
"default": {
Type: schema.TypeBool,
Expand Down
4 changes: 2 additions & 2 deletions civo/datasource_kubernetes_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func testAccCheckDataSourceCivoKubernetesVersionFiltered(n string) resource.Test

for i := 0; i < total; i++ {
name := rs.Primary.Attributes[fmt.Sprintf("versions.%d.type", i)]
if !stringInSlice(name, []string{"stable"}) {
if !stringInSlice(name, []string{"talos"}) {
return fmt.Errorf("Type is not in expected test filter values")
}

Expand All @@ -117,7 +117,7 @@ func testAccDataSourceCivoKubernetesVersionConfigWhitFilter() string {
data "civo_kubernetes_version" "foobar" {
filter {
key = "type"
values = ["stable"]
values = ["talos"]
}
}
`
Expand Down
11 changes: 11 additions & 0 deletions civo/resource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func resourceKubernetesCluster() *schema.Resource {
Required: true,
Description: "The existing firewall ID to use for this cluster",
},
"cluster_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The type of cluster to create, valid options are `k3s` or `talos` the default is `k3s`",
},
// Computed resource
"installed_applications": applicationSchema(),
"pools": nodePoolSchema(),
Expand Down Expand Up @@ -270,6 +276,10 @@ func resourceKubernetesClusterCreate(ctx context.Context, d *schema.ResourceData
config.Applications = ""
}

if attr, ok := d.GetOk("cluster_type"); ok {
config.ClusterType = attr.(string)
}

if attr, ok := d.GetOk("firewall_id"); ok {
firewallID := attr.(string)
firewall, err := apiClient.FindFirewall(firewallID)
Expand Down Expand Up @@ -344,6 +354,7 @@ func resourceKubernetesClusterRead(_ context.Context, d *schema.ResourceData, m
d.Set("num_target_nodes", resp.NumTargetNode)
d.Set("target_nodes_size", resp.TargetNodeSize)
d.Set("kubernetes_version", resp.KubernetesVersion)
d.Set("cluster_type", resp.ClusterType)
d.Set("cni", resp.CNIPlugin)
d.Set("tags", strings.Join(resp.Tags, " ")) // space separated tags
d.Set("status", resp.Status)
Expand Down
2 changes: 2 additions & 0 deletions civo/resource_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestAccCivoKubernetesCluster_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resName, "master_ip"),
resource.TestCheckResourceAttrSet(resName, "dns_entry"),
resource.TestCheckResourceAttrSet(resName, "created_at"),
resource.TestCheckResourceAttrSet(resName, "cluster_type"),
),
},
},
Expand Down Expand Up @@ -78,6 +79,7 @@ func TestAccCivoKubernetesClusterCNI(t *testing.T) {
resource.TestCheckResourceAttrSet(resName, "master_ip"),
resource.TestCheckResourceAttrSet(resName, "dns_entry"),
resource.TestCheckResourceAttrSet(resName, "created_at"),
resource.TestCheckResourceAttrSet(resName, "cluster_type"),
),
},
},
Expand Down
17 changes: 12 additions & 5 deletions examples/data-sources/civo_kubernetes_version/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
data "civo_kubernetes_version" "stable" {
filter {
key = "type"
values = ["stable"]
}
data "civo_kubernetes_version" "talos" {
filter {
key = "type"
values = ["talos"]
}
}

data "civo_kubernetes_version" "k3s" {
filter {
key = "type"
values = ["k3s"]
}
}
29 changes: 28 additions & 1 deletion examples/resources/civo_kubernetes_cluster/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ resource "civo_firewall_rule" "kubernetes" {
action = "allow"
}

# Create a cluster
# Create a cluster without expecific cluster type by default is k3s
resource "civo_kubernetes_cluster" "my-cluster" {
name = "my-cluster"
applications = "Portainer,Linkerd:Linkerd & Jaeger"
Expand All @@ -39,3 +39,30 @@ resource "civo_kubernetes_cluster" "my-cluster" {
node_count = 3
}
}

# Create a cluster with k3s
resource "civo_kubernetes_cluster" "my-cluster" {
name = "my-cluster"
applications = "Portainer,Linkerd:Linkerd & Jaeger"
firewall_id = civo_firewall.my-firewall.id
cluster_type = "k3s"
pools {
label = "front-end" // Optional
size = element(data.civo_size.xsmall.sizes, 0).name
node_count = 3
}
}


# Create a cluster with talos
resource "civo_kubernetes_cluster" "my-cluster" {
name = "my-cluster"
applications = "Portainer,Linkerd:Linkerd & Jaeger"
firewall_id = civo_firewall.my-firewall.id
cluster_type = "talos"
pools {
label = "front-end" // Optional
size = element(data.civo_size.xsmall.sizes, 0).name
node_count = 3
}
}
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/civo/terraform-provider-civo

require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/civo/civogo v0.3.23
github.com/civo/civogo v0.3.24
github.com/google/uuid v1.3.0
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/civo/civogo v0.3.23 h1:FTSad682Qu7CsjkNAYWpSe2CSR1NJOE2NRxc6gUzHDk=
github.com/civo/civogo v0.3.23/go.mod h1:SbS06e0JPgIF27r1sLC97gjU1xWmONQeHgzF1hfLpak=
github.com/civo/civogo v0.3.24 h1:7kXEhtVUFkWIunNePqPCcIUilOktnXLWrKfi5sDqBNQ=
github.com/civo/civogo v0.3.24/go.mod h1:SbS06e0JPgIF27r1sLC97gjU1xWmONQeHgzF1hfLpak=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand Down