Skip to content

Commit

Permalink
Fixes and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ezilber-akamai committed Feb 24, 2025
1 parent 76b51cd commit 077f131
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 4 deletions.
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: 4 additions & 2 deletions linode/lkeversion/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func TestAccDataSourceLinodeLkeVersion_NoTier(t *testing.T) {
Config: tmpl.DataNoTier(t, version.ID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", version.ID),
resource.TestCheckNoResourceAttr(resourceName, "tier")),
resource.TestCheckNoResourceAttr(resourceName, "tier"),
),
},
},
})
Expand Down Expand Up @@ -71,7 +72,8 @@ func TestAccDataSourceLinodeLkeVersion_Tier(t *testing.T) {
Config: tmpl.DataTier(t, version.ID, tier),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", version.ID),
resource.TestCheckResourceAttr(resourceName, "tier", "enterprise")),
resource.TestCheckResourceAttr(resourceName, "tier", tier),
),
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion linode/lkeversion/framework_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (d DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *
}

// Check if Tier is populated
if data.Tier.ValueString() == "" {
if data.Tier.IsNull() {
// If Tier is not populated, use GetLKEVersion
versionInfo, err := client.GetLKEVersion(ctx, data.ID.ValueString())
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions linode/lkeversion/framework_datasource_schema.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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{
Expand All @@ -13,6 +15,9 @@ var Attributes = map[string]schema.Attribute{
Description: "The tier of the LKE version, either standard or enterprise.",
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("standard", "enterprise"),
},
},
}

Expand Down
3 changes: 3 additions & 0 deletions linode/lkeversions/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestAccDataSourceLinodeLkeVersions_NoTier(t *testing.T) {
Config: tmpl.DataNoTier(t),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "versions.0.id"),
resource.TestCheckNoResourceAttr(resourceName, "versions.0.tier"),
resource.TestCheckNoResourceAttr(resourceName, "tier"),
),
},
},
Expand All @@ -44,6 +46,7 @@ func TestAccDataSourceLinodeLkeVersions_Tier(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "versions.0.id"),
resource.TestCheckResourceAttr(resourceName, "versions.0.tier", tier),
resource.TestCheckResourceAttr(resourceName, "tier", tier),
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion linode/lkeversions/framework_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (d *DataSource) Read(
}

// Check if Tier is populated
if data.Tier.ValueString() == "" {
if data.Tier.IsNull() {
// If Tier is not populated, use ListLKEVersions
tflog.Trace(ctx, "client.ListLKEVersions(...)")
versions, err := client.ListLKEVersions(ctx, nil)
Expand Down
5 changes: 5 additions & 0 deletions linode/lkeversions/framework_datasource_schema.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package lkeversions

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"
"github.com/linode/terraform-provider-linode/v2/linode/lkeversion"
)

Expand All @@ -19,6 +21,9 @@ var frameworkDatasourceSchema = schema.Schema{
Description: "The tier of the LKE versions, either standard or enterprise.",
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("standard", "enterprise"),
},
},
},
Blocks: map[string]schema.Block{
Expand Down
8 changes: 8 additions & 0 deletions linode/lkeversions/framework_models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package lkeversions

import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/linode/linodego"
Expand Down Expand Up @@ -30,6 +32,9 @@ func (model *DataSourceModel) parseLKEVersions(lkeVersions []linodego.LKEVersion

model.Versions = result

id, _ := json.Marshal(lkeVersions)
model.ID = types.StringValue(string(id))

return nil
}

Expand All @@ -50,5 +55,8 @@ func (model *DataSourceModel) parseLKETierVersions(lkeTierVersions []linodego.LK

model.Versions = result

id, _ := json.Marshal(lkeTierVersions)
model.ID = types.StringValue(string(id))

return nil
}

0 comments on commit 077f131

Please sign in to comment.