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
46 changes: 46 additions & 0 deletions docs/data-sources/lke_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
page_title: "Linode: linode_lke_version"
description: |-
Provides details about a Kubernetes version available for deployment to a Kubernetes cluster.
---

# linode\_lke\_version

Provides details about a specific Kubernetes versions available for deployment to a Kubernetes cluster.
For more information, see the [Linode APIv4 docs](https://techdocs.akamai.com/linode-api/reference/get-lke-version).

## Example Usage

The following example shows how one might use this data source to access information about a Linode LKE Version.

```hcl
data "linode_lke_version" "example" {id = "1.31"}
```

The following example shows how one might use this data source to access information about a Linode LKE Version
with additional information about the Linode LKE Version's tier (`enterprise` or `standard`).

> **_NOTE:_** This functionality may not be currently available to all users and can only be used with v4beta.

```hcl
data "linode_lke_version" "example" {
id = "1.31"
tier = "standard"
}
```

## Argument Reference

The following arguments are supported:

* `id` - (Required) The unique ID of this Linode LKE Version.

* `tier` - (Optional) The tier (`standard` or `enterprise`) of Linode LKE Version to fetch.

## Attributes Reference

The Linode LKE Version datasource exports the following attributes:

* `id` - The Kubernetes version numbers available for deployment to a Kubernetes cluster in the format of [major].[minor], and the latest supported patch version.

* `tier` - The Kubernetes version tier. Only exported if `tier` was provided when using the datasource.
17 changes: 17 additions & 0 deletions docs/data-sources/lke_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,25 @@ The following example shows how one might use this data source to access informa
data "linode_lke_versions" "example" {}
```

The following example shows how one might use this data source to access information about a Linode LKE Version
with additional information about the Linode LKE Version's tier (`enterprise` or `standard`).

> **_NOTE:_** This functionality may not be currently available to all users and can only be used with v4beta.

```hcl
data "linode_lke_versions" "example" {tier = "enterprise"}
```

## Argument Reference

The following arguments are supported:

* `tier` - (Optional) The tier (`standard` or `enterprise`) of Linode LKE Versions to fetch.

## Attributes Reference

Each Linode LKE Version will be stored in the `versions` attribute and will export the following attributes:

* `id` - The Kubernetes version numbers available for deployment to a Kubernetes cluster in the format of [major].[minor], and the latest supported patch version.

* `tier` - The Kubernetes version tier. Only exported if `tier` was provided when using the datasource.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.4
github.com/aws/aws-sdk-go-v2/service/s3 v1.78.1
github.com/aws/smithy-go v1.22.3
github.com/go-resty/resty/v2 v2.16.3
github.com/go-resty/resty/v2 v2.16.5
github.com/google/go-cmp v0.7.0
github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637
github.com/hashicorp/go-hclog v1.6.3
Expand All @@ -24,7 +24,7 @@ require (
github.com/hashicorp/terraform-plugin-mux v0.18.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/linode/linodego v1.47.0
github.com/linode/linodego v1.48.1
github.com/linode/linodego/k8s v1.25.2
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.35.0
Expand Down Expand Up @@ -100,7 +100,7 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.16.2 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2Kv
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-resty/resty/v2 v2.16.3 h1:zacNT7lt4b8M/io2Ahj6yPypL7bqx9n1iprfQuodV+E=
github.com/go-resty/resty/v2 v2.16.3/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
Expand Down Expand Up @@ -194,8 +194,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/linode/linodego v1.47.0 h1:6MFNCyzWbr8Rhl4r7d5DwZLwxvFIsM4ARH6W0KS/R0U=
github.com/linode/linodego v1.47.0/go.mod h1:vyklQRzZUWhFVBZdYx4dcYJU/gG9yKB9VUcUs6ub0Lk=
github.com/linode/linodego v1.48.1 h1:Ojw1S+K5jJr1dggO8/H6r4FINxXnJbOU5GkbpaTfmhU=
github.com/linode/linodego v1.48.1/go.mod h1:fc3t60If8X+yZTFAebhCnNDFrhwQhq9HDU92WnBousQ=
github.com/linode/linodego/k8s v1.25.2 h1:PY6S0sAD3xANVvM9WY38bz9GqMTjIbytC8IJJ9Cv23o=
github.com/linode/linodego/k8s v1.25.2/go.mod h1:DC1XCSRZRGsmaa/ggpDPSDUmOM6aK1bhSIP6+f9Cwhc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
Expand Down Expand Up @@ -299,8 +299,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
3 changes: 3 additions & 0 deletions linode/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package linode
import (
"context"

"github.com/linode/terraform-provider-linode/v2/linode/lkeversion"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
Expand Down Expand Up @@ -260,6 +262,7 @@ func (p *FrameworkProvider) DataSources(ctx context.Context) []func() datasource
nb.NewDataSource,
networkingip.NewDataSource,
networktransferprices.NewDataSource,
lkeversion.NewDataSource,
lkeversions.NewDataSource,
regions.NewDataSource,
ipv6range.NewDataSource,
Expand Down
99 changes: 99 additions & 0 deletions linode/lkeversion/datasource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//go:build integration || lkeversion

package lkeversion_test

import (
"context"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
"github.com/linode/terraform-provider-linode/v2/linode/acceptance"
"github.com/linode/terraform-provider-linode/v2/linode/lkeversion/tmpl"
)

func TestAccDataSourceLinodeLkeVersion_NoTier(t *testing.T) {
t.Parallel()

resourceName := "data.linode_lke_version.foobar"

client, err := acceptance.GetTestClient()
if err != nil {
t.Fatal(err)
}

// Resolve an LKE version
versions, err := client.ListLKEVersions(context.Background(), nil)
if err != nil {
t.Fatalf("failed to list lke versions: %s", err)
}

version := versions[0]

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: tmpl.DataNoTier(t, version.ID),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
resourceName,
tfjsonpath.New("id"),
knownvalue.StringExact(version.ID),
),
statecheck.ExpectKnownValue(
resourceName,
tfjsonpath.New("tier"),
knownvalue.Null(),
),
},
},
},
})
}

func TestAccDataSourceLinodeLkeVersion_Tier(t *testing.T) {
t.Parallel()

resourceName := "data.linode_lke_version.foobar"

client, err := acceptance.GetTestClient()
if err != nil {
t.Fatal(err)
}

tier := "enterprise"

// Resolve an LKE version
versions, err := client.ListLKETierVersions(context.Background(), tier, nil)
if err != nil {
t.Fatalf("failed to list lke versions: %s", err)
}

version := versions[0]

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: tmpl.DataTier(t, version.ID, tier),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
resourceName,
tfjsonpath.New("id"),
knownvalue.StringExact(version.ID),
),
statecheck.ExpectKnownValue(
resourceName,
tfjsonpath.New("tier"),
knownvalue.StringExact(tier),
),
},
},
},
})
}
73 changes: 73 additions & 0 deletions linode/lkeversion/framework_datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package lkeversion

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/linode/terraform-provider-linode/v2/linode/helper"
)

func NewDataSource() datasource.DataSource {
return &DataSource{
BaseDataSource: helper.NewBaseDataSource(
helper.BaseDataSourceConfig{
Name: "linode_lke_version",
Schema: &frameworkDatasourceSchema,
},
),
}
}

type DataSource struct {
helper.BaseDataSource
}

func (d DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
tflog.Debug(ctx, "Read data.linode_lke_version")

client := d.Meta.Client

var data DataSourceModel

// Get the config data
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

// Check if Tier is populated
if data.Tier.IsNull() {
// If Tier is not populated, use GetLKEVersion
versionInfo, err := client.GetLKEVersion(ctx, data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error getting lke version %s: ", data.ID.ValueString()), err.Error(),
)
return
}

resp.Diagnostics.Append(data.ParseLKEVersion(versionInfo)...)
if resp.Diagnostics.HasError() {
return
}

} else {
// If Tier is populated, use GetLKETierVersion
versionInfo, err := client.GetLKETierVersion(ctx, data.Tier.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error getting lke version %s %s: ", data.Tier.ValueString(), data.ID.ValueString()), err.Error(),
)
return
}

resp.Diagnostics.Append(data.ParseLKETierVersion(versionInfo)...)
if resp.Diagnostics.HasError() {
return
}
}

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
26 changes: 26 additions & 0 deletions linode/lkeversion/framework_datasource_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package lkeversion

import (
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

var Attributes = map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "The unique ID assigned to this LKE version.",
Required: true,
},
"tier": schema.StringAttribute{
Description: "The tier of the LKE version, either standard or enterprise.",
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("standard", "enterprise"),
},
},
}

var frameworkDatasourceSchema = schema.Schema{
Attributes: Attributes,
}
27 changes: 27 additions & 0 deletions linode/lkeversion/framework_models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lkeversion

import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/linode/linodego"
)

type DataSourceModel struct {
ID types.String `tfsdk:"id"`
Tier types.String `tfsdk:"tier"`
}

func (data *DataSourceModel) ParseLKEVersion(lkeVersion *linodego.LKEVersion,
) diag.Diagnostics {
data.ID = types.StringValue(lkeVersion.ID)

return nil
}

func (data *DataSourceModel) ParseLKETierVersion(lkeTierVersion *linodego.LKETierVersion,
) diag.Diagnostics {
data.ID = types.StringValue(lkeTierVersion.ID)
data.Tier = types.StringValue(string(lkeTierVersion.Tier))

return nil
}
Loading
Loading