Skip to content
Closed
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
35 changes: 35 additions & 0 deletions linode/lke/framework_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,3 +820,38 @@ func TestAccResourceLKECluster_acl_disabled_addresses(t *testing.T) {
},
})
}

// TestAccResourceLKECluster_tierNoAccess ensures that a tier value of
// `standard` will not trigger diffs in a cluster that does not expose
// the `tier` field due to various circumstances.
func TestAccResourceLKECluster_tierNoAccess(t *testing.T) {
t.Parallel()

clusterName := acctest.RandomWithPrefix("tf_test")
resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
ProtoV6ProviderFactories: acceptance.ProtoV6ProviderFactories,
CheckDestroy: acceptance.CheckLKEClusterDestroy,
Steps: []resource.TestStep{
{
Config: tmpl.TierNoAccess(t, clusterName, k8sVersionLatest, testRegion, string(linodego.LKEVersionStandard)),
},
{
Config: tmpl.TierNoAccess(t, clusterName, k8sVersionLatest, testRegion, string(linodego.LKEVersionStandard)),
},
{
Config: tmpl.TierNoAccess(
t,
clusterName,
k8sVersionLatest,
testRegion,
string(linodego.LKEVersionEnterprise),
),
ExpectError: regexp.MustCompile(".*"),
},
{
Config: tmpl.TierNoAccess(t, clusterName, k8sVersionLatest, testRegion, string(linodego.LKEVersionStandard)),
},
},
})
}
13 changes: 12 additions & 1 deletion linode/lke/schema_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,19 @@ var resourceSchema = map[string]*schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The desired Kubernetes tier.",
ForceNew: true,
Description: "The desired Kubernetes tier.",

// The tier attribute may not be returned under certain conditions,
// notably when not using v4beta.
//
// This was originally going to be implemented as a validator requiring
// api_version be set to v4beta but this approach eliminates the need for
// an additional change once LKE tiers become available in the v4 namespace
// and accounts for any possible edge cases where this could occur (e.g. old clusters).
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return old == "" && linodego.LKEVersionTier(new) == linodego.LKEVersionStandard
},
},
"subnet_id": {
Type: schema.TypeInt,
Expand Down
8 changes: 8 additions & 0 deletions linode/lke/tmpl/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type TemplateData struct {
Taints []TaintData
Labels map[string]string
AuditLogsEnabled bool
Tier string
}

func Basic(t testing.TB, name, version, region string) string {
Expand Down Expand Up @@ -157,3 +158,10 @@ func ACLDisabledAddressesDisallowed(t testing.TB, name, version, region string)
TemplateData{Label: name, K8sVersion: version, Region: region},
)
}

func TierNoAccess(t testing.TB, name, version, region, tier string) string {
return acceptance.ExecuteTemplate(t,
"lke_cluster_tier_no_access",
TemplateData{Label: name, K8sVersion: version, Region: region, Tier: tier},
)
}
23 changes: 23 additions & 0 deletions linode/lke/tmpl/tier_no_access.gotf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{ define "lke_cluster_tier_no_access" }}

provider "linode" {
alias = "v4"
api_version = "v4"
}

resource "linode_lke_cluster" "test" {
provider = linode.v4

label = "{{ .Label }}"
region = "{{ .Region }}"
k8s_version = "{{ .K8sVersion }}"
tier = "{{ .Tier }}"

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

{{ end }}