-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for LKE, Volume, NodeBalancer, and network transfer prici…
…ng endpoints (#1591) * Added LKE Types datasource * Added Node Balancer Types datasource * Added Volume Types datasource * Added Network Transfer Prices datasource * Abstracted base pricing types * Addressed PR comments * Fixed filters for new endpoints
- Loading branch information
1 parent
158e8e9
commit 1603370
Showing
28 changed files
with
1,219 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package helper | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var PriceObjectType = types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"hourly": types.Float64Type, | ||
"monthly": types.Float64Type, | ||
}, | ||
} | ||
|
||
var RegionPriceObjectType = types.ObjectType{ | ||
AttrTypes: map[string]attr.Type{ | ||
"id": types.StringType, | ||
"hourly": types.Float64Type, | ||
"monthly": types.Float64Type, | ||
}, | ||
} | ||
|
||
func GetPricingTypeAttributes(typeName string) map[string]schema.Attribute { | ||
return map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: "The unique ID assigned to this " + typeName + ".", | ||
Required: true, | ||
}, | ||
"label": schema.StringAttribute{ | ||
Description: "The " + typeName + "'s label.", | ||
Computed: true, | ||
Optional: true, | ||
}, | ||
"price": schema.ListAttribute{ | ||
Description: "Cost in US dollars, broken down into hourly and monthly charges.", | ||
Computed: true, | ||
ElementType: PriceObjectType, | ||
}, | ||
"region_prices": schema.ListAttribute{ | ||
Description: "A list of region-specific prices for this " + typeName + ".", | ||
Computed: true, | ||
ElementType: RegionPriceObjectType, | ||
}, | ||
"transfer": schema.Int64Attribute{ | ||
Description: "The monthly outbound transfer amount, in MB.", | ||
Computed: true, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build integration || lketypes | ||
|
||
package lketypes_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/linode/terraform-provider-linode/v2/linode/acceptance" | ||
"github.com/linode/terraform-provider-linode/v2/linode/lketypes/tmpl" | ||
) | ||
|
||
func TestAccDataSourceLKETypes_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
dataSourceName := "data.linode_lke_types.foobar" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.PreCheck(t) }, | ||
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: tmpl.DataBasic(t), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "types.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "types.0.id", "lke-sa"), | ||
resource.TestCheckResourceAttr(dataSourceName, "types.0.label", "LKE Standard Availability"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "types.0.transfer"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "types.0.price.0.hourly"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "types.0.price.0.monthly"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package lketypes | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/linode/linodego" | ||
"github.com/linode/terraform-provider-linode/v2/linode/helper" | ||
) | ||
|
||
func NewDataSource() datasource.DataSource { | ||
return &DataSource{ | ||
BaseDataSource: helper.NewBaseDataSource( | ||
helper.BaseDataSourceConfig{ | ||
Name: "linode_lke_types", | ||
Schema: &frameworkDataSourceSchema, | ||
}, | ||
), | ||
} | ||
} | ||
|
||
type DataSource struct { | ||
helper.BaseDataSource | ||
} | ||
|
||
func (r *DataSource) Read( | ||
ctx context.Context, | ||
req datasource.ReadRequest, | ||
resp *datasource.ReadResponse, | ||
) { | ||
tflog.Debug(ctx, "Read data.linode_lke_types") | ||
|
||
var data LKETypeFilterModel | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
id, d := filterConfig.GenerateID(data.Filters) | ||
if d != nil { | ||
resp.Diagnostics.Append(d) | ||
return | ||
} | ||
data.ID = id | ||
|
||
result, d := filterConfig.GetAndFilter( | ||
ctx, r.Meta.Client, data.Filters, listLKETypes, data.Order, data.OrderBy) | ||
if d != nil { | ||
resp.Diagnostics.Append(d) | ||
return | ||
} | ||
|
||
data.parseLKETypes(helper.AnySliceToTyped[linodego.LKEType](result)) | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func listLKETypes(ctx context.Context, client *linodego.Client, filter string) ([]any, error) { | ||
tflog.Debug(ctx, "Listing LKE types", map[string]any{ | ||
"filter_header": filter, | ||
}) | ||
|
||
types, err := client.ListLKETypes(ctx, &linodego.ListOptions{ | ||
Filter: filter, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return helper.TypedSliceToAny(types), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package lketypes | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/linode/terraform-provider-linode/v2/linode/helper" | ||
"github.com/linode/terraform-provider-linode/v2/linode/helper/frameworkfilter" | ||
) | ||
|
||
var lkeTypeSchema = schema.NestedBlockObject{ | ||
Attributes: helper.GetPricingTypeAttributes("LKE Type"), | ||
} | ||
|
||
var filterConfig = frameworkfilter.Config{ | ||
"label": {APIFilterable: true, TypeFunc: frameworkfilter.FilterTypeString}, | ||
"transfer": {APIFilterable: true, TypeFunc: frameworkfilter.FilterTypeInt}, | ||
} | ||
|
||
var frameworkDataSourceSchema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: "The data source's unique ID.", | ||
Computed: true, | ||
}, | ||
"order_by": filterConfig.OrderBySchema(), | ||
"order": filterConfig.OrderSchema(), | ||
}, | ||
Blocks: map[string]schema.Block{ | ||
"filter": filterConfig.Schema(), | ||
"types": schema.ListNestedBlock{ | ||
Description: "The returned list of LKE types.", | ||
NestedObject: lkeTypeSchema, | ||
}, | ||
}, | ||
} |
Oops, something went wrong.