Skip to content

Commit

Permalink
Merge pull request #1407 from linode/dev
Browse files Browse the repository at this point in the history
Release v2.20.1
  • Loading branch information
ykim-akamai authored Apr 30, 2024
2 parents f09810d + 67fc086 commit 7945c4e
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 81 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.22.0
golang.org/x/net v0.24.0
golang.org/x/sync v0.6.0
golang.org/x/sync v0.7.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
7 changes: 7 additions & 0 deletions linode/accountsettings/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ func (r *Resource) Update(

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

// Apply the state changes
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}
Expand Down
8 changes: 8 additions & 0 deletions linode/firewalldevice/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ func (r *Resource) Update(
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
1 change: 1 addition & 0 deletions linode/helper/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type BatchFunction func(ctx context.Context) error

// RunBatch is intended to simplify executing functions concurrently.
// This is handy for running certain non-sequential API requests in parallel.
// NOTE: This should NOT be used until linodego has been confirmed to be thread-safe.
func RunBatch(ctx context.Context, toExecute ...BatchFunction) error {
eg, ctx := errgroup.WithContext(ctx)

Expand Down
8 changes: 8 additions & 0 deletions linode/image/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ func (r *Resource) Update(
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
64 changes: 22 additions & 42 deletions linode/instance/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,50 +53,30 @@ func readResource(ctx context.Context, d *schema.ResourceData, meta interface{})
return diag.Errorf("Error parsing Linode instance ID %s as int: %s", d.Id(), err)
}

var instance *linodego.Instance
var instanceNetwork *linodego.InstanceIPAddressResponse
var instanceDisks []linodego.InstanceDisk
var instanceConfigs []linodego.InstanceConfig

err = helper.RunBatch(ctx,
func(ctx context.Context) (err error) {
instance, err = client.GetInstance(ctx, id)
if err != nil {
err = fmt.Errorf("failed to get instance: %w", err)
}
return
},
func(ctx context.Context) (err error) {
instanceNetwork, err = client.GetInstanceIPAddresses(ctx, id)
if err != nil {
err = fmt.Errorf("failed to get instance networking: %w", err)
}
return
},
func(ctx context.Context) (err error) {
instanceDisks, err = client.ListInstanceDisks(ctx, id, nil)
if err != nil {
err = fmt.Errorf("failed to get instance disks: %w", err)
}
return
},
func(ctx context.Context) (err error) {
instanceConfigs, err = client.ListInstanceConfigs(ctx, id, nil)
if err != nil {
err = fmt.Errorf("failed to get instance configs: %w", err)
}
return
},
)
instance, err := client.GetInstance(ctx, id)
if linodego.IsNotFound(err) {
tflog.Warn(ctx, "Removing Linode Instance ID %q from state because it no longer exists")
d.SetId("")
return nil
}

if err != nil {
// We can assume a 404 from any of these endpoints implies a deleted instance
if linodego.IsNotFound(err) {
tflog.Warn(ctx, "removing Linode Instance ID %q from state because it no longer exists")
d.SetId("")
return nil
}
return diag.Errorf("failed to get instance: %s", err)
}

instanceNetwork, err := client.GetInstanceIPAddresses(ctx, id)
if err != nil {
return diag.Errorf("failed to get instance networking: %s", err)
}

instanceDisks, err := client.ListInstanceDisks(ctx, id, nil)
if err != nil {
return diag.Errorf("failed to get instance disks: %s", err)
}

return diag.Errorf("failed to read instance: %v", err)
instanceConfigs, err := client.ListInstanceConfigs(ctx, id, nil)
if err != nil {
return diag.Errorf("failed to get instance configs: %s", err)
}

var ips []string
Expand Down
54 changes: 18 additions & 36 deletions linode/instanceconfig/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,45 +73,27 @@ func readResource(ctx context.Context, d *schema.ResourceData, meta any) diag.Di

linodeID := d.Get("linode_id").(int)

var cfg *linodego.InstanceConfig
var inst *linodego.Instance
var instNetworking *linodego.InstanceIPAddressResponse

err = helper.RunBatch(ctx,
func(ctx context.Context) (err error) {
cfg, err = client.GetInstanceConfig(ctx, linodeID, id)
if err != nil {
err = fmt.Errorf("failed to get instance config: %w", err)
}
cfg, err := client.GetInstanceConfig(ctx, linodeID, id)
if linodego.IsNotFound(err) {
tflog.Warn(ctx, fmt.Sprintf(
"removing Instance Config ID %q from state because it no longer exists", d.Id(),
))
d.SetId("")
return nil
}

return
},
func(ctx context.Context) (err error) {
inst, err = client.GetInstance(ctx, linodeID)
if err != nil {
err = fmt.Errorf("failed to get instance: %w", err)
}
return
},
func(ctx context.Context) (err error) {
// We want to guarantee that we're resolving a public IPv4 address
instNetworking, err = client.GetInstanceIPAddresses(ctx, linodeID)
if err != nil {
err = fmt.Errorf("failed to get instance networking: %w", err)
}
return
},
)
if err != nil {
if linodego.IsNotFound(err) {
tflog.Warn(ctx, fmt.Sprintf(
"removing Instance Config ID %q from state because it no longer exists", d.Id(),
))
d.SetId("")
return nil
}
return diag.Errorf("failed to get instance config: %s", err)
}

return diag.Errorf("Error finding the specified Linode Instance Config: %s", err)
inst, err := client.GetInstance(ctx, linodeID)
if err != nil {
return diag.Errorf("failed to get instance: %s", err)
}

instNetworking, err := client.GetInstanceIPAddresses(ctx, linodeID)
if err != nil {
return diag.Errorf("failed to get instance networking: %s", err)
}

configBooted, err := isConfigBooted(ctx, &client, inst, cfg.ID)
Expand Down
8 changes: 8 additions & 0 deletions linode/instancedisk/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ func (r *Resource) Update(
plan.FlattenDisk(disk, true)

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
7 changes: 7 additions & 0 deletions linode/instanceip/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ func (r *Resource) Update(
}
plan.CopyFrom(ctx, state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
8 changes: 8 additions & 0 deletions linode/instancesharedips/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ func (r *Resource) Update(
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
8 changes: 8 additions & 0 deletions linode/ipv6range/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ func (r *Resource) Update(
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
8 changes: 8 additions & 0 deletions linode/lkenodepool/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ func (r *Resource) Update(
}

plan.FlattenLKENodePool(readyPool, true, &resp.Diagnostics)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
if resp.Diagnostics.HasError() {
return
Expand Down
9 changes: 9 additions & 0 deletions linode/nb/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,16 @@ func (r *Resource) Update(

resp.Diagnostics.Append(plan.FlattenNodeBalancer(ctx, nodeBalancer, firewalls, true)...)
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
8 changes: 8 additions & 0 deletions linode/nbconfig/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ func (r *Resource) Update(

plan.FlattenNodeBalancerConfig(config, true)
plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
8 changes: 8 additions & 0 deletions linode/objkey/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ func (r *Resource) Update(
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
9 changes: 9 additions & 0 deletions linode/rdns/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,16 @@ func (r *Resource) Update(
}
plan.FlattenInstanceIP(ip, true)
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
9 changes: 9 additions & 0 deletions linode/sshkey/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,16 @@ func (r *Resource) Update(
}
plan.FlattenSSHKey(key, true)
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
8 changes: 8 additions & 0 deletions linode/stackscript/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ func (r *Resource) Update(
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
8 changes: 8 additions & 0 deletions linode/token/framework_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ func (r *Resource) Update(
}

plan.CopyFrom(state, true)

// Workaround for Crossplane issue where ID is not
// properly populated in plan
// See TPT-2865 for more details
if plan.ID.ValueString() == "" {
plan.ID = state.ID
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand Down
Loading

0 comments on commit 7945c4e

Please sign in to comment.