Skip to content

Project: Linode Interfaces #1862

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

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ require (
golang.org/x/sync v0.14.0
)

// Point to Linode Interface feature branch
replace github.com/linode/linodego => github.com/linode/linodego v1.50.1-0.20250516203249-bc899d5edc4a

require (
github.com/ProtonMail/go-crypto v1.1.6 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
Expand Down Expand Up @@ -102,7 +105,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.24.0 // indirect
golang.org/x/oauth2 v0.29.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.32.0 // indirect
golang.org/x/text v0.25.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
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.50.0 h1:5y79VvvQnWb5JyPIjTwyUrU3ArHcs7XZQFdkPS/lNpw=
github.com/linode/linodego v1.50.0/go.mod h1:9S+REoPCtUNWCm63D1vjjxIJZfwEL2t2kTDnwt620FM=
github.com/linode/linodego v1.50.1-0.20250516203249-bc899d5edc4a h1:n+L52L88kdHaWlD3XXNbRaHHDQEasTianm5eskkUiSQ=
github.com/linode/linodego v1.50.1-0.20250516203249-bc899d5edc4a/go.mod h1:zEN2sX+cSdp67EuRY1HJiyuLujoa7HqvVwNEcJv3iXw=
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 @@ -301,8 +301,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.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98=
golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
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
19 changes: 11 additions & 8 deletions linode/accountsettings/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ package accountsettings_test

import (
"context"
"strconv"
"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/accountsettings/tmpl"
)
Expand Down Expand Up @@ -45,13 +47,14 @@ func TestAccDataSourceLinodeAccountSettings_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: tmpl.DataBasic(t),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "backups_enabled", strconv.FormatBool(settings.BackupsEnabled)),
resource.TestCheckResourceAttr(resourceName, "managed", strconv.FormatBool(settings.Managed)),
resource.TestCheckResourceAttr(resourceName, "network_helper", strconv.FormatBool(settings.NetworkHelper)),
resource.TestCheckResourceAttr(resourceName, "object_storage", objectStorageVal),
resource.TestCheckResourceAttr(resourceName, "longview_subscription", longviewVal),
),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("backups_enabled"), knownvalue.Bool(settings.BackupsEnabled)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("managed"), knownvalue.Bool(settings.Managed)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("network_helper"), knownvalue.Bool(settings.NetworkHelper)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("object_storage"), knownvalue.StringExact(objectStorageVal)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("longview_subscription"), knownvalue.StringExact(longviewVal)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("interfaces_for_new_linodes"), knownvalue.StringExact(string(settings.InterfacesForNewLinodes))),
},
},
},
})
Expand Down
4 changes: 4 additions & 0 deletions linode/accountsettings/framework_datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ var frameworkDataSourceSchema = schema.Schema{
Description: "A string describing the status of this account's Object Storage service enrollment.",
Computed: true,
},
"interfaces_for_new_linodes": schema.StringAttribute{
Description: "What kind of interfaces are allowed for new Linode instances.",
Computed: true,
},
},
}
21 changes: 15 additions & 6 deletions linode/accountsettings/framework_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
// AccountSettingsModel describes the Terraform resource data model to match the
// resource schema.
type AccountSettingsModel struct {
ID types.String `tfsdk:"id"`
LongviewSubscription types.String `tfsdk:"longview_subscription"`
ObjectStorage types.String `tfsdk:"object_storage"`
BackupsEnabled types.Bool `tfsdk:"backups_enabled"`
Managed types.Bool `tfsdk:"managed"`
NetworkHelper types.Bool `tfsdk:"network_helper"`
ID types.String `tfsdk:"id"`
LongviewSubscription types.String `tfsdk:"longview_subscription"`
ObjectStorage types.String `tfsdk:"object_storage"`
InterfacesForNewLinodes types.String `tfsdk:"interfaces_for_new_linodes"`
BackupsEnabled types.Bool `tfsdk:"backups_enabled"`
Managed types.Bool `tfsdk:"managed"`
NetworkHelper types.Bool `tfsdk:"network_helper"`
}

func (data *AccountSettingsModel) FlattenAccountSettings(
Expand All @@ -36,6 +37,11 @@ func (data *AccountSettingsModel) FlattenAccountSettings(
helper.GetStringPtrWithDefault(settings.ObjectStorage, ""),
preserveKnown,
)
data.InterfacesForNewLinodes = helper.KeepOrUpdateString(
data.InterfacesForNewLinodes,
string(settings.InterfacesForNewLinodes),
preserveKnown,
)

data.Managed = helper.KeepOrUpdateBool(data.Managed, settings.Managed, preserveKnown)
data.BackupsEnabled = helper.KeepOrUpdateBool(
Expand All @@ -54,6 +60,9 @@ func (data *AccountSettingsModel) CopyFrom(other AccountSettingsModel, preserveK
data.ObjectStorage = helper.KeepOrUpdateValue(
data.ObjectStorage, other.ObjectStorage, preserveKnown,
)
data.InterfacesForNewLinodes = helper.KeepOrUpdateValue(
data.InterfacesForNewLinodes, other.InterfacesForNewLinodes, preserveKnown,
)
data.BackupsEnabled = helper.KeepOrUpdateValue(
data.BackupsEnabled, other.BackupsEnabled, preserveKnown,
)
Expand Down
15 changes: 10 additions & 5 deletions linode/accountsettings/framework_model_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ func TestFlattenAccountSettings(t *testing.T) {
networkHelperValue := false

mockSettings := &linodego.AccountSettings{
BackupsEnabled: backupsEnabledValue,
Managed: managedValue,
NetworkHelper: networkHelperValue,
LongviewSubscription: &longviewSubscriptionValue,
ObjectStorage: &objectStorageValue,
BackupsEnabled: backupsEnabledValue,
Managed: managedValue,
NetworkHelper: networkHelperValue,
LongviewSubscription: &longviewSubscriptionValue,
ObjectStorage: &objectStorageValue,
InterfacesForNewLinodes: linodego.LinodeDefaultButLegacyConfigAllowed,
}

// Create a mock AccountSettingsModel instance
Expand All @@ -46,6 +47,10 @@ func TestFlattenAccountSettings(t *testing.T) {
t.Errorf("Expected ObjectStorage to be %s, but got %s", "active", model.ObjectStorage)
}

if model.InterfacesForNewLinodes != types.StringValue(string(linodego.LinodeDefaultButLegacyConfigAllowed)) {
t.Errorf("Expected InterfacesForNewLinodes to be %s, but got %s", string(linodego.LinodeDefaultButLegacyConfigAllowed), model.InterfacesForNewLinodes)
}

if model.BackupsEnabled != types.BoolValue(true) {
t.Errorf("Expected BackupsEnabed to be %v, but got %v", true, model.BackupsEnabled)
}
Expand Down
50 changes: 32 additions & 18 deletions linode/accountsettings/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ func (r *Resource) Create(
}

// Update the account
resp.Diagnostics.Append(
r.updateAccountSettings(ctx, &plan)...,
)
r.createOrUpdateAccountSettings(ctx, &plan, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
Expand Down Expand Up @@ -117,9 +115,7 @@ func (r *Resource) Update(
}

// Update the account
resp.Diagnostics.Append(
r.updateAccountSettings(ctx, &plan)...,
)
r.createOrUpdateAccountSettings(ctx, &plan, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
Expand All @@ -145,12 +141,22 @@ func (r *Resource) Delete(
tflog.Debug(ctx, "Delete "+r.Config.Name)
}

func (r *Resource) updateAccountSettings(
func (r *Resource) createOrUpdateAccountSettings(
ctx context.Context,
plan *AccountSettingsModel,
) diag.Diagnostics {
diags *diag.Diagnostics,
) {
client := r.Meta.Client
var diagnostics diag.Diagnostics

account, err := client.GetAccount(ctx)
if err != nil {
diags.AddError(
"Failed to get Linode Account",
err.Error(),
)
return
}
email := account.Email

// Longview Plan update functionality has been moved
if !plan.LongviewSubscription.IsNull() {
Expand All @@ -164,17 +170,26 @@ func (r *Resource) updateAccountSettings(

_, err := client.UpdateLongviewPlan(ctx, options)
if err != nil {
diagnostics.AddError(
diags.AddError(
"Failed to update Linode Longview Plan",
err.Error(),
)
return diagnostics
return
}
}

updateOpts := linodego.AccountSettingsUpdateOptions{
BackupsEnabled: plan.BackupsEnabled.ValueBoolPointer(),
NetworkHelper: plan.NetworkHelper.ValueBoolPointer(),
updateOpts := linodego.AccountSettingsUpdateOptions{}

if !plan.BackupsEnabled.IsUnknown() {
updateOpts.BackupsEnabled = plan.BackupsEnabled.ValueBoolPointer()
}

if !plan.NetworkHelper.IsUnknown() {
updateOpts.NetworkHelper = plan.NetworkHelper.ValueBoolPointer()
}

if !plan.InterfacesForNewLinodes.IsUnknown() {
updateOpts.InterfacesForNewLinodes = (*linodego.InterfacesForNewLinodes)(plan.InterfacesForNewLinodes.ValueStringPointer())
}

tflog.Debug(ctx, "client.UpdateAccountSettings(...)", map[string]any{
Expand All @@ -183,10 +198,9 @@ func (r *Resource) updateAccountSettings(

settings, err := client.UpdateAccountSettings(ctx, updateOpts)
if err != nil {
diagnostics.AddError("Failed to update Linode Account Settings", err.Error())
return diagnostics
diags.AddError("Failed to update Linode Account Settings", err.Error())
return
}

plan.FlattenAccountSettings(plan.ID.ValueString(), settings, true)
return diagnostics
plan.FlattenAccountSettings(email, settings, true)
}
17 changes: 16 additions & 1 deletion linode/accountsettings/framework_resource_schema.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package accountsettings

import (
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

var frameworkResourceSchema = schema.Schema{
Expand Down Expand Up @@ -40,7 +42,20 @@ var frameworkResourceSchema = schema.Schema{
stringplanmodifier.UseStateForUnknown(),
},
},

"interfaces_for_new_linodes": schema.StringAttribute{
Description: "Account-wide backups default.",
Computed: true,
Optional: true,
Validators: []validator.String{stringvalidator.OneOf(
"legacy_config_only",
"legacy_config_default_but_linode_allowed",
"linode_default_but_legacy_config_allowed",
"linode_only",
)},
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"managed": schema.BoolAttribute{
Description: "Enables monitoring for connectivity, response, and total request time.",
Computed: true,
Expand Down
50 changes: 37 additions & 13 deletions linode/accountsettings/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"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/linodego"
"github.com/linode/terraform-provider-linode/v2/linode/acceptance"
"github.com/linode/terraform-provider-linode/v2/linode/accountsettings/tmpl"
)
Expand All @@ -23,12 +27,13 @@ func TestAccResourceAccountSettings_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: tmpl.Basic(t),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "backups_enabled"),
resource.TestCheckResourceAttrSet(resourceName, "managed"),
resource.TestCheckResourceAttrSet(resourceName, "network_helper"),
resource.TestCheckResourceAttrSet(resourceName, "object_storage"),
),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("backups_enabled"), knownvalue.NotNull()),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("managed"), knownvalue.NotNull()),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("network_helper"), knownvalue.NotNull()),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("object_storage"), knownvalue.NotNull()),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("interfaces_for_new_linodes"), knownvalue.NotNull()),
},
},
},
})
Expand All @@ -51,11 +56,19 @@ func TestAccResourceAccountSettings_update(t *testing.T) {
currLongviewPlan := longviewSettings.ID
currBackupsEnabled := accountSettings.BackupsEnabled
currNetworkHelper := accountSettings.NetworkHelper
currInterfacesForNewLinodes := accountSettings.InterfacesForNewLinodes

updatedLongviewPlan := "longview-10"
updatedBackupsEnabled := !currBackupsEnabled
updatedNetworkHelper := !currNetworkHelper

var updatedInterfacesForNewLinodes string
if currInterfacesForNewLinodes == linodego.LegacyConfigDefaultButLinodeAllowed {
updatedInterfacesForNewLinodes = string(linodego.LinodeDefaultButLegacyConfigAllowed)
} else {
updatedInterfacesForNewLinodes = string(linodego.LegacyConfigDefaultButLinodeAllowed)
}

if currLongviewPlan == "" || currLongviewPlan == "longview-10" {
updatedLongviewPlan = "longview-3"
}
Expand All @@ -65,20 +78,31 @@ func TestAccResourceAccountSettings_update(t *testing.T) {
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: tmpl.Updates(t, updatedLongviewPlan, updatedBackupsEnabled, updatedNetworkHelper),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "longview_subscription", updatedLongviewPlan),
resource.TestCheckResourceAttr(resourceName, "backups_enabled", strconv.FormatBool(updatedBackupsEnabled)),
resource.TestCheckResourceAttr(resourceName, "network_helper", strconv.FormatBool(updatedNetworkHelper)),
),
Config: tmpl.Updates(t, updatedLongviewPlan, updatedInterfacesForNewLinodes, updatedBackupsEnabled, updatedNetworkHelper),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("longview_subscription"), knownvalue.StringExact(updatedLongviewPlan)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("backups_enabled"), knownvalue.Bool(updatedBackupsEnabled)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("network_helper"), knownvalue.Bool(updatedNetworkHelper)),
statecheck.ExpectKnownValue(
resourceName, tfjsonpath.New("interfaces_for_new_linodes"), knownvalue.StringExact(updatedInterfacesForNewLinodes),
),
},
},
{
Config: tmpl.Updates(t, currLongviewPlan, currBackupsEnabled, currNetworkHelper),
Config: tmpl.Updates(t, currLongviewPlan, string(currInterfacesForNewLinodes), currBackupsEnabled, currNetworkHelper),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "longview_subscription", currLongviewPlan),
resource.TestCheckResourceAttr(resourceName, "backups_enabled", strconv.FormatBool(currBackupsEnabled)),
resource.TestCheckResourceAttr(resourceName, "network_helper", strconv.FormatBool(currNetworkHelper)),
),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("longview_subscription"), knownvalue.StringExact(currLongviewPlan)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("backups_enabled"), knownvalue.Bool(currBackupsEnabled)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("network_helper"), knownvalue.Bool(currNetworkHelper)),
statecheck.ExpectKnownValue(
resourceName, tfjsonpath.New("interfaces_for_new_linodes"), knownvalue.StringExact(string(currInterfacesForNewLinodes)),
),
},
},
},
})
Expand Down
Loading