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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ terrafmt: tools
@ echo "-> Running terraform docs codeblocks linter"
@ find ./docs -type f -name "*.md" -exec $(GOBIN)/terrafmt diff -f {} \;

.PHONY: terrafmt-fmt
terrafmt-fmt: tools
@ echo "-> Running terraform docs codeblocks linter"
@ find ./docs -type f -name "*.md" -exec $(GOBIN)/terrafmt fmt -f {} \;

configfmt:
@ echo "-> Running terraform linters on .tf files"
@ terraform fmt -write=false -recursive -check
Expand Down
52 changes: 52 additions & 0 deletions docs/data-sources/oxide_address_lot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
page_title: "oxide_address_lot Data Source - terraform-provider-oxide"
---

# oxide_address_lot (Data Source)

Retrieve information about a specified address lot.

## Example Usage

```hcl
data "oxide_address_lot" "example" {
name = "test-address-lot"
}
```

## Schema

### Required

- `name` (String) Name of the address lot.

### Optional

- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `blocks` (Attributes Set) (see [below for nested schema](#nestedatt--blocks))
- `description` (String) Description for the address lot.
- `id` (String) Unique, immutable, system-controlled identifier of the address lot.
- `kind` (String) Kind for the address lot.
- `time_created` (String) Timestamp of when this address lot was created.
- `time_modified` (String) Timestamp of when this address lot was last modified.

<a id="nestedatt--timeouts"></a>

### Nested Schema for `timeouts`

Optional:

- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).

<a id="nestedatt--blocks"></a>

### Nested Schema for `blocks`

Read-Only:

- `first_address` (String) First address in the lot.
- `id` (String) ID of the address lot block.
- `last_address` (String) Last address in the lot.
66 changes: 66 additions & 0 deletions docs/resources/oxide_address_lot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
page_title: "oxide_address_lot Resource - terraform-provider-oxide"
---

# oxide_address_lot (Resource)

This resource manages address lots.

## Example Usage

```hcl
resource "oxide_address_lot" "example" {
description = "a test address lot"
name = "test-address-lot"
kind = "pool"
blocks = [
{
first_address = "172.20.18.227"
last_address = "172.20.18.239"
}
]
}
```

## Schema

### Required

- `blocks` (Attributes Set) (see [below for nested schema](#nestedatt--blocks))
- `description` (String) Description for the address lot.
- `kind` (String) Kind for the address lot. Must be one of "infra" or "pool".
- `name` (String) Name of the address lot.

### Optional

- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `id` (String) Unique, immutable, system-controlled identifier of the address lot.
- `time_created` (String) Timestamp of when this address lot was created.
- `time_modified` (String) Timestamp of when this address lot was last modified.

<a id="nestedatt--blocks"></a>

### Nested Schema for `blocks`

Required:

- `first_address` (String) First address in the lot.
- `last_address` (String) Last address in the lot.

Read-Only:

- `id` (String) ID of the address lot block.

<a id="nestedatt--timeouts"></a>

### Nested Schema for `timeouts`

Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
2 changes: 1 addition & 1 deletion docs/resources/oxide_ip_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ Optional:
- `create` (String, Default `10m`)
- `delete` (String, Default `10m`)
- `read` (String, Default `10m`)
- `update` (String, Default `10m`)
- `update` (String, Default `10m`)
4 changes: 2 additions & 2 deletions docs/resources/oxide_vpc_firewall_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ resource "oxide_vpc_firewall_rules" "example" {
},
# Echo Reply types.
{
type = "icmp",
type = "icmp",
icmp_type = 0
},
# Echo Reply types with codes 1-3.
{
type = "icmp",
type = "icmp",
icmp_type = 0
icmp_code = "1-3"
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
github.com/hashicorp/terraform-plugin-testing v1.13.3
github.com/oxidecomputer/oxide.go v0.6.0
github.com/oxidecomputer/oxide.go v0.6.1-0.20250818174811-729a349856d0
github.com/stretchr/testify v1.10.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oxidecomputer/oxide.go v0.6.0 h1:H9vf6na1CzhNmLzT7fZV0nf0azaRVBILXSlA9hHWShM=
github.com/oxidecomputer/oxide.go v0.6.0/go.mod h1:4gfHlxdBQLs/34UbChPvINd+pGNAnGlASRGEd4xIz1Y=
github.com/oxidecomputer/oxide.go v0.6.1-0.20250818174811-729a349856d0 h1:+xHMg700XYrWg8iInqs6bxqdMncO4vLOAHcsloKNffU=
github.com/oxidecomputer/oxide.go v0.6.1-0.20250818174811-729a349856d0/go.mod h1:4gfHlxdBQLs/34UbChPvINd+pGNAnGlASRGEd4xIz1Y=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4=
Expand Down
164 changes: 164 additions & 0 deletions internal/provider/data_source_address_lot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

package provider

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/oxidecomputer/oxide.go/oxide"
)

var _ datasource.DataSource = (*addressLotDataSource)(nil)
var _ datasource.DataSourceWithConfigure = (*addressLotDataSource)(nil)

type addressLotDataSource struct {
client *oxide.Client
}

type addressLotDataSourceModel struct {
Blocks []addressLotDataSourceBlockModel `tfsdk:"blocks"`
Description types.String `tfsdk:"description"`
Kind types.String `tfsdk:"kind"`
Name types.String `tfsdk:"name"`
ID types.String `tfsdk:"id"`
TimeCreated types.String `tfsdk:"time_created"`
TimeModified types.String `tfsdk:"time_modified"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
}

type addressLotDataSourceBlockModel struct {
ID types.String `tfsdk:"id"`
FirstAddress types.String `tfsdk:"first_address"`
LastAddress types.String `tfsdk:"last_address"`
}

// NewAddressLotDataSource initialises an address_lot datasource.
func NewAddressLotDataSource() datasource.DataSource {
return &addressLotDataSource{}
}

func (d *addressLotDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "oxide_address_lot"
}

// Configure adds the provider configured client to the data source.
func (d *addressLotDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

d.client = req.ProviderData.(*oxide.Client)
}

func (d *addressLotDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Required: true,
Description: "Name of the address lot.",
},
"description": schema.StringAttribute{
Computed: true,
Description: "Description for the address lot.",
},
"kind": schema.StringAttribute{
Computed: true,
Description: "Kind for the address lot.",
},
"blocks": schema.SetNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "ID of the address lot block.",
Computed: true,
},
"first_address": schema.StringAttribute{
Description: "First address in the lot.",
Computed: true,
},
"last_address": schema.StringAttribute{
Description: "Last address in the lot.",
Computed: true,
},
},
},
},
"id": schema.StringAttribute{
Computed: true,
Description: "Unique, immutable, system-controlled identifier of the address lot.",
},
"time_created": schema.StringAttribute{
Computed: true,
Description: "Timestamp of when this address lot was created.",
},
"time_modified": schema.StringAttribute{
Computed: true,
Description: "Timestamp of when this address lot was last modified.",
},
"timeouts": timeouts.Attributes(ctx),
},
}
}

func (d *addressLotDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var state addressLotDataSourceModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}

readTimeout, diags := state.Timeouts.Read(ctx, defaultTimeout())
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()

addressLot, err := d.client.NetworkingAddressLotView(ctx, oxide.NetworkingAddressLotViewParams{
AddressLot: oxide.NameOrId(state.Name.ValueString()),
})
if err != nil {
resp.Diagnostics.AddError(
"Unable to read address lot:",
"API error: "+err.Error(),
)
return
}
lot := addressLot.Lot
tflog.Trace(ctx, fmt.Sprintf("read address lot with ID: %v", lot.Id), map[string]any{"success": true})

state.ID = types.StringValue(lot.Id)
state.Name = types.StringValue(string(lot.Name))
state.Kind = types.StringValue(string(lot.Kind))
state.Description = types.StringValue(lot.Description)
state.TimeCreated = types.StringValue(lot.TimeCreated.String())
state.TimeModified = types.StringValue(lot.TimeCreated.String())

blockModels := make([]addressLotDataSourceBlockModel, len(addressLot.Blocks))
for index, item := range addressLot.Blocks {
blockModels[index] = addressLotDataSourceBlockModel{
ID: types.StringValue(item.Id),
FirstAddress: types.StringValue(item.FirstAddress),
LastAddress: types.StringValue(item.LastAddress),
}
}
state.Blocks = blockModels

// Save state into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}
}
57 changes: 57 additions & 0 deletions internal/provider/data_source_address_lot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

package provider

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

var testDataSourceAddressLotConfig = `
resource "oxide_address_lot" "test" {
description = "a test address lot"
name = "terraform-acc-my-address-lot"
kind = "infra"
blocks = [
{
first_address = "172.0.1.1"
last_address = "172.0.1.10"
},
]
}

data "oxide_address_lot" "test" {
name = oxide_address_lot.test.name
}
`

func TestAccDataSourceAddressLot_full(t *testing.T) {
resourceName := "oxide_address_lot.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Config: testDataSourceAddressLotConfig,
Check: checkDataSourceAddressLot(resourceName),
},
},
})
}

func checkDataSourceAddressLot(dataName string) resource.TestCheckFunc {
return resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
resource.TestCheckResourceAttrSet(dataName, "id"),
resource.TestCheckResourceAttr(dataName, "description", "a test address lot"),
resource.TestCheckResourceAttr(dataName, "name", "terraform-acc-my-address-lot"),
resource.TestCheckResourceAttrSet(dataName, "blocks.0.first_address"),
resource.TestCheckResourceAttrSet(dataName, "blocks.0.last_address"),
resource.TestCheckResourceAttr(dataName, "blocks.0.first_address", "172.0.1.1"),
resource.TestCheckResourceAttr(dataName, "blocks.0.last_address", "172.0.1.10"),
resource.TestCheckResourceAttrSet(dataName, "time_created"),
resource.TestCheckResourceAttrSet(dataName, "time_modified"),
}...)
}
Loading