Skip to content
Open
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
8 changes: 8 additions & 0 deletions docs/data-sources/region.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ In addition to all arguments above, the following attributes are exported:

* [`placement_group_limits`] (#placement-group-limits) - An object representing the limits relating to placement groups in this region.

* [`monitors`] (#monitors) - An object representing the monitor services available in a region.

### Resolvers

* `ipv4` - The IPv4 addresses for this region’s DNS resolvers, separated by commas.
Expand All @@ -52,3 +54,9 @@ In addition to all arguments above, the following attributes are exported:
* `maximum_pgs_per_customer` - The maximum number of placement groups allowed for the current user in this region.

* `maximum_linodes_per_pg` - The maximum number of Linodes allowed to be assigned to a placement group in this region.

### Monitors

* `metrics` - A list of ACLP metrics services supported in the region.

* `alerts` - A list of ACLP alerts services supported in the region.
8 changes: 8 additions & 0 deletions docs/data-sources/regions.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Each Linode region will be stored in the `regions` attribute and will export the

* [`placement_group_limits`] (#placement-group-limits) - An object representing the limits relating to placement groups in this region.

* [`monitors`] (#monitors) - An object representing the monitor services available in a region.

### Resolvers

* `ipv4` - The IPv4 addresses for this region’s DNS resolvers, separated by commas.
Expand All @@ -71,6 +73,12 @@ Each Linode region will be stored in the `regions` attribute and will export the

* `maximum_linodes_per_pg` - The maximum number of Linodes allowed to be assigned to a placement group in this region.

### Monitors

* `metrics` - A list of ACLP metrics services supported in the region.

* `alerts` - A list of ACLP alerts services supported in the region.

## Filterable Fields

* `status`
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: revert linodego replacement once the lindoego PR merged

replace github.com/linode/linodego => github.com/pmajali/linodego v0.0.0-20251007072421-63cf6a574cc7
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ 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.60.0 h1:SgsebJFRCi+lSmYy+C40wmKZeJllGGm+W12Qw4+yVdI=
github.com/linode/linodego v1.60.0/go.mod h1:1+Bt0oTz5rBnDOJbGhccxn7LYVytXTIIfAy7QYmijDs=
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 @@ -235,6 +233,8 @@ github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4=
github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxuCS6A=
github.com/pmajali/linodego v0.0.0-20251007072421-63cf6a574cc7 h1:/B8b7yCdDfSRXBNbxyyUcwUiQqGJ4AXJf1TrQ8tYiCY=
github.com/pmajali/linodego v0.0.0-20251007072421-63cf6a574cc7/go.mod h1:1+Bt0oTz5rBnDOJbGhccxn7LYVytXTIIfAy7QYmijDs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
2 changes: 2 additions & 0 deletions linode/region/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func TestAccDataSourceRegion_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "resolvers.0.ipv6"),
resource.TestCheckResourceAttrSet(resourceName, "placement_group_limits.0.maximum_pgs_per_customer"),
resource.TestCheckResourceAttrSet(resourceName, "placement_group_limits.0.maximum_linodes_per_pg"),
resource.TestCheckResourceAttrSet(resourceName, "monitors.alerts.0"),
resource.TestCheckResourceAttrSet(resourceName, "monitors.metrics.0"),
acceptance.CheckResourceAttrGreaterThan(resourceName, "capabilities.#", 0),
),
},
Expand Down
2 changes: 1 addition & 1 deletion linode/region/framework_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *DataSource) Read(
return
}

data.ParseRegion(region)
resp.Diagnostics.Append(data.ParseRegion(ctx, region)...)
if resp.Diagnostics.HasError() {
return
}
Expand Down
10 changes: 10 additions & 0 deletions linode/region/framework_datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ var ObjectTypePGLimits = types.ObjectType{
},
}

var MonitorsAttrTypes = map[string]attr.Type{
"alerts": types.ListType{ElemType: types.StringType},
"metrics": types.ListType{ElemType: types.StringType},
}

var DataSourceSchema = schema.Schema{
Attributes: map[string]schema.Attribute{
"country": schema.StringAttribute{
Expand Down Expand Up @@ -45,6 +50,11 @@ var DataSourceSchema = schema.Schema{
Computed: true,
ElementType: ObjectTypePGLimits,
},
"monitors": schema.ObjectAttribute{
Description: "The monitoring services available in a region.",
Computed: true,
AttributeTypes: MonitorsAttrTypes,
},
},
Blocks: map[string]schema.Block{
"resolvers": schema.ListNestedBlock{
Expand Down
39 changes: 38 additions & 1 deletion linode/region/framework_models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package region

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/linode/linodego"
"github.com/linode/terraform-provider-linode/v3/linode/helper"
Expand Down Expand Up @@ -28,9 +31,19 @@ type RegionModel struct {
Capabilities []types.String `tfsdk:"capabilities"`
Resolvers []RegionResolversModel `tfsdk:"resolvers"`
PlacementGroupLimits []RegionPGLimitsModel `tfsdk:"placement_group_limits"`
Monitors types.Object `tfsdk:"monitors"`
}

// RegionMonitors contains the monitoring configuration for a region
type RegionMonitors struct {
Alerts types.List `tfsdk:"alerts"`
Metrics types.List `tfsdk:"metrics"`
}

func (m *RegionModel) ParseRegion(region *linodego.Region) {
func (m *RegionModel) ParseRegion(
ctx context.Context,
region *linodego.Region,
) diag.Diagnostics {
m.ID = types.StringValue(region.ID)
m.Label = types.StringValue(region.Label)
m.Status = types.StringValue(region.Status)
Expand All @@ -56,4 +69,28 @@ func (m *RegionModel) ParseRegion(region *linodego.Region) {
},
}
}

var monitorsModel RegionMonitors
alerts, err := types.ListValueFrom(ctx, types.StringType, region.Monitors.Alerts)
if err != nil {
return err
}

monitorsModel.Alerts = alerts

metrics, err := types.ListValueFrom(ctx, types.StringType, region.Monitors.Metrics)
if err != nil {
return err
}

monitorsModel.Metrics = metrics

monitors, err := types.ObjectValueFrom(ctx, MonitorsAttrTypes, &monitorsModel)
if err != nil {
return err
}

m.Monitors = monitors

return nil
}
15 changes: 14 additions & 1 deletion linode/region/framework_models_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package region

import (
"context"
"testing"

"github.com/hashicorp/terraform-plugin-framework/types"
Expand All @@ -26,11 +27,15 @@ func TestParseRegion(t *testing.T) {
MaximumPGsPerCustomer: 10,
},
Label: "Newark, NJ, USA",
Monitors: linodego.RegionMonitors{
Alerts: []string{"Managed Databases"},
Metrics: []string{"Managed Databases"},
},
}

model := &RegionModel{}

model.ParseRegion(region)
model.ParseRegion(context.Background(), region)

assert.Equal(t, types.StringValue("us-east"), model.ID)
assert.Equal(t, types.StringValue("Newark, NJ, USA"), model.Label)
Expand All @@ -47,4 +52,12 @@ func TestParseRegion(t *testing.T) {

assert.Equal(t, types.Int64Value(5), model.PlacementGroupLimits[0].MaximumLinodesPerPG)
assert.Equal(t, types.Int64Value(10), model.PlacementGroupLimits[0].MaximumPGsPerCustomer)

monitorVal, diag := types.ListValueFrom(context.Background(), types.StringType, []string{"Managed Databases"})
if diag != nil {
t.Error(diag.Errors())
}

assert.Equal(t, monitorVal, model.Monitors.Attributes()["metrics"])
assert.Equal(t, monitorVal, model.Monitors.Attributes()["alerts"])
}
2 changes: 1 addition & 1 deletion linode/regions/framework_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *DataSource) Read(
return
}

data.parseRegions(helper.AnySliceToTyped[linodego.Region](result))
data.parseRegions(ctx, helper.AnySliceToTyped[linodego.Region](result))

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Expand Down
9 changes: 7 additions & 2 deletions linode/regions/framework_models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package regions

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/linode/linodego"
"github.com/linode/terraform-provider-linode/v3/linode/helper/frameworkfilter"
Expand All @@ -16,13 +18,16 @@ type RegionFilterModel struct {
}

// parseRegions parses the given list of regions into the `regions` model attribute.
func (model *RegionFilterModel) parseRegions(regions []linodego.Region) {
func (model *RegionFilterModel) parseRegions(
ctx context.Context,
regions []linodego.Region,
) {
result := make([]regionResource.RegionModel, len(regions))

for i, region := range regions {
region := region
model := regionResource.RegionModel{}
model.ParseRegion(&region)
model.ParseRegion(ctx, &region)
result[i] = model
}

Expand Down
19 changes: 18 additions & 1 deletion linode/regions/framework_models_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package regions

import (
"context"
"testing"

"github.com/hashicorp/terraform-plugin-framework/types"
Expand All @@ -27,6 +28,10 @@ func TestParseRegions(t *testing.T) {
MaximumLinodesPerPG: 6,
MaximumPGsPerCustomer: 11,
},
Monitors: linodego.RegionMonitors{
Alerts: []string{"Managed Databases"},
Metrics: []string{"Managed Databases"},
},
},
{
ID: "ap-west",
Expand All @@ -43,12 +48,16 @@ func TestParseRegions(t *testing.T) {
MaximumLinodesPerPG: 5,
MaximumPGsPerCustomer: 10,
},
Monitors: linodego.RegionMonitors{
Alerts: []string{"Managed Databases"},
Metrics: []string{"Managed Databases"},
},
},
}

model := &RegionFilterModel{}

model.parseRegions(regions)
model.parseRegions(context.Background(), regions)

assert.Len(t, model.Regions, len(regions))

Expand Down Expand Up @@ -77,5 +86,13 @@ func TestParseRegions(t *testing.T) {
types.Int64Value(int64(expectedRegion.PlacementGroupLimits.MaximumLinodesPerPG)),
model.Regions[i].PlacementGroupLimits[0].MaximumLinodesPerPG,
)

monitorVal, diag := types.ListValueFrom(context.Background(), types.StringType, []string{"Managed Databases"})
if diag != nil {
t.Error(diag.Errors())
}

assert.Equal(t, monitorVal, model.Regions[i].Monitors.Attributes()["metrics"])
assert.Equal(t, monitorVal, model.Regions[i].Monitors.Attributes()["alerts"])
}
}