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

new: Support tier in LKE resource and data source #1718

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions docs/data-sources/lke_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ In addition to all arguments above, the following attributes are exported:

* `tags` - An array of tags applied to this object. Tags are case-insensitive and are for organizational purposes only.

* `tier` - The desired Kubernetes tier. (**Note: v4beta only and may not currently be available to all users.**)

* `nodes` - The nodes in the Node Pool.

* `id` - The ID of the node.
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/lke_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Each LKE Cluster will be stored in the `lke_clusters` attribute and will export

* `region` - This Kubernetes cluster's location.

* `tier` - The desired Kubernetes tier. (**Note: v4beta only and may not currently be available to all users.**)

* `control_plane.high_availability` - Whether High Availability is enabled for the cluster Control Plane.

To get more information about a cluster, i.e. node pools, please refer to the [linode_lke_cluster](lke_cluster.html.markdown) data source.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/lke_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ The following arguments are supported:

* `external_pool_tags` - (Optional) A set of node pool tags to ignore when planning and applying this cluster. This prevents externally managed node pools from being deleted or unintentionally updated on subsequent applies. See [Externally Managed Node Pools](#externally-managed-node-pools) for more details.

* `tier` - (Optional) The desired Kubernetes tier. (**Note: v4beta only and may not currently be available to all users.**)

### pool

~> **Notice** Due to limitations in Terraform, the order of pools in the `linode_lke_cluster` resource is treated as significant.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/linode/terraform-provider-linode/v2

go 1.23
go 1.23.0

require (
github.com/aws/aws-sdk-go-v2 v1.33.0
Expand Down
4 changes: 4 additions & 0 deletions linode/lke/framework_datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ var frameworkDataSourceSchema = schema.Schema{
Computed: true,
Description: "When this Kubernetes cluster was updated.",
},
"tier": schema.StringAttribute{
Computed: true,
Description: "The desired Kubernetes tier.",
},
},
Blocks: map[string]schema.Block{
"control_plane": schema.ListNestedBlock{
Expand Down
1 change: 1 addition & 0 deletions linode/lke/framework_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestAccDataSourceLKECluster_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceClusterName, "region", testRegion),
resource.TestCheckResourceAttr(dataSourceClusterName, "k8s_version", k8sVersionLatest),
resource.TestCheckResourceAttr(dataSourceClusterName, "status", "ready"),
resource.TestCheckResourceAttr(dataSourceClusterName, "tier", "standard"),
resource.TestCheckResourceAttr(dataSourceClusterName, "tags.#", "1"),
resource.TestCheckResourceAttr(dataSourceClusterName, "pools.#", "1"),
resource.TestCheckResourceAttr(dataSourceClusterName, "pools.0.type", "g6-standard-1"),
Expand Down
2 changes: 2 additions & 0 deletions linode/lke/framework_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type LKEDataModel struct {
Status types.String `tfsdk:"status"`
K8sVersion types.String `tfsdk:"k8s_version"`
Tags types.Set `tfsdk:"tags"`
Tier types.String `tfsdk:"tier"`
ControlPlane []LKEControlPlane `tfsdk:"control_plane"`

// LKE Node Pools
Expand Down Expand Up @@ -98,6 +99,7 @@ func (data *LKEDataModel) parseLKEAttributes(
data.Region = types.StringValue(cluster.Region)
data.Status = types.StringValue(string(cluster.Status))
data.K8sVersion = types.StringValue(cluster.K8sVersion)
data.Tier = types.StringValue(cluster.Tier)

tags, diags := types.SetValueFrom(ctx, types.StringType, cluster.Tags)
if diags != nil {
Expand Down
1 change: 1 addition & 0 deletions linode/lke/framework_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func TestAccResourceLKECluster_basic_smoke(t *testing.T) {
resource.TestCheckResourceAttr(resourceClusterName, "region", testRegion),
resource.TestCheckResourceAttr(resourceClusterName, "k8s_version", k8sVersionLatest),
resource.TestCheckResourceAttr(resourceClusterName, "status", "ready"),
resource.TestCheckResourceAttr(resourceClusterName, "tier", "standard"),
resource.TestCheckResourceAttr(resourceClusterName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceClusterName, "pool.#", "1"),
resource.TestCheckResourceAttr(resourceClusterName, "pool.0.type", "g6-standard-1"),
Expand Down
5 changes: 5 additions & 0 deletions linode/lke/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func readResource(ctx context.Context, d *schema.ResourceData, meta interface{})
d.Set("region", cluster.Region)
d.Set("tags", cluster.Tags)
d.Set("status", cluster.Status)
d.Set("tier", cluster.Tier)
d.Set("kubeconfig", kubeconfig.KubeConfig)
d.Set("dashboard_url", dashboard.URL)
d.Set("api_endpoints", flattenLKEClusterAPIEndpoints(endpoints))
Expand Down Expand Up @@ -150,6 +151,10 @@ func createResource(ctx context.Context, d *schema.ResourceData, meta interface{
K8sVersion: d.Get("k8s_version").(string),
}

if tier, ok := d.GetOk("tier"); ok {
createOpts.Tier = tier.(string)
}

if len(controlPlane) > 0 {
expandedControlPlane := expandControlPlaneOptions(controlPlane[0].(map[string]interface{}))
createOpts.ControlPlane = &expandedControlPlane
Expand Down
5 changes: 5 additions & 0 deletions linode/lke/schema_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ var resourceSchema = map[string]*schema.Schema{
Computed: true,
Description: "The status of the cluster.",
},
"tier": {
Type: schema.TypeString,
Optional: true,
Description: "The desired Kubernetes tier.",
},
"pool": {
Type: schema.TypeList,
Elem: &schema.Resource{
Expand Down
2 changes: 2 additions & 0 deletions linode/lke/tmpl/autoscaler.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test"]
tier = "standard"

pool {
autoscaler {
min = 1
Expand Down
2 changes: 2 additions & 0 deletions linode/lke/tmpl/autoscaler_many_pools.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{ .K8sVersion }}"
tags = ["test"]
tier = "standard"

pool {
autoscaler {
min = 3
Expand Down
1 change: 1 addition & 0 deletions linode/lke/tmpl/autoscaler_no_count.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
label = "{{.Label}}"
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tier = "standard"

pool {
type = "g6-standard-1"
Expand Down
1 change: 1 addition & 0 deletions linode/lke/tmpl/autoscaler_updates.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test"]
tier = "standard"
pool {
autoscaler {
min = 1
Expand Down
1 change: 1 addition & 0 deletions linode/lke/tmpl/basic.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test"]
tier = "standard"

pool {
type = "g6-standard-1"
Expand Down
1 change: 1 addition & 0 deletions linode/lke/tmpl/complex_pools.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test"]
tier = "standard"

pool {
type = "g6-standard-2"
Expand Down
1 change: 1 addition & 0 deletions linode/lke/tmpl/control_plane.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test"]
tier = "standard"

control_plane {
high_availability = {{.HighAvailability}}
Expand Down
1 change: 1 addition & 0 deletions linode/lke/tmpl/many_pools.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test"]
tier = "standard"

pool {
type = "g6-standard-1"
Expand Down
1 change: 1 addition & 0 deletions linode/lke/tmpl/taints_labels.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{ .K8sVersion }}"
tags = ["test"]
tier = "standard"

pool {
type = "g6-standard-1"
Expand Down
1 change: 1 addition & 0 deletions linode/lke/tmpl/updates.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test", "new_tag"]
tier = "standard"

pool {
type = "g6-standard-1"
Expand Down
1 change: 1 addition & 0 deletions linode/lkeclusters/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestAccDataSourceLKEClusters_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "lke_clusters.0.k8s_version", k8sVersionLatest),
resource.TestCheckResourceAttr(dataSourceName, "lke_clusters.0.status", "ready"),
resource.TestCheckResourceAttr(dataSourceName, "lke_clusters.0.tags.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "lke_clusters.0.tier", "standard"),
resource.TestCheckResourceAttr(dataSourceName, "lke_clusters.0.control_plane.high_availability", "false"),
),
},
Expand Down
5 changes: 5 additions & 0 deletions linode/lkeclusters/framework_datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var filterConfig = frameworkfilter.Config{
"created": {APIFilterable: false, TypeFunc: helper.FilterTypeString},
"updated": {APIFilterable: false, TypeFunc: helper.FilterTypeString},
"status": {APIFilterable: false, TypeFunc: helper.FilterTypeString},
"tier": {APIFilterable: false, TypeFunc: helper.FilterTypeString},
}

var frameworkDatasourceSchema = schema.Schema{
Expand Down Expand Up @@ -67,6 +68,10 @@ var frameworkDatasourceSchema = schema.Schema{
Computed: true,
Description: "The status of the cluster.",
},
"tier": schema.StringAttribute{
Computed: true,
Description: "The desired Kubernetes tier.",
},
},
Blocks: map[string]schema.Block{
"control_plane": schema.SingleNestedBlock{
Expand Down
2 changes: 2 additions & 0 deletions linode/lkeclusters/framework_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type LKEClusterModel struct {
K8sVersion types.String `tfsdk:"k8s_version"`
Tags types.Set `tfsdk:"tags"`
ControlPlane LKEControlPlaneModel `tfsdk:"control_plane"`
Tier types.String `tfsdk:"tier"`
}

type LKEControlPlaneModel struct {
Expand Down Expand Up @@ -65,6 +66,7 @@ func (data *LKEClusterModel) parseLKECluster(
data.Region = types.StringValue(cluster.Region)
data.Status = types.StringValue(string(cluster.Status))
data.K8sVersion = types.StringValue(cluster.K8sVersion)
data.Tier = types.StringValue(cluster.Tier)

tags, diags := types.SetValueFrom(ctx, types.StringType, cluster.Tags)
if diags != nil {
Expand Down
6 changes: 4 additions & 2 deletions linode/lkeclusters/tmpl/data_base.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "linode_lke_cluster" "test" {
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test"]
tier = "standard"

pool {
type = "g6-standard-2"
Expand All @@ -13,14 +14,15 @@ resource "linode_lke_cluster" "test" {
}

resource "linode_lke_cluster" "test2" {
label = "2-{{.Label}}"
label = "{{.Label}}-2"
region = "{{ .Region }}"
k8s_version = "{{.K8sVersion}}"
tags = ["test-2"]
tier = "standard"

pool {
type = "g6-standard-2"
count = 3
count = 1
}
}

Expand Down
5 changes: 5 additions & 0 deletions linode/lkeclusters/tmpl/data_filter.gotf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ data "linode_lke_clusters" "test" {
name = "label"
values = ["{{.Label}}"]
}

filter {
name = "tier"
values = ["standard"]
}
}

{{ end }}
Loading