Skip to content

Commit 2d53051

Browse files
committed
Add address lot resource and data source.
Resolves #468. Resolves #469.
1 parent 78c6e58 commit 2d53051

13 files changed

+801
-27
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ terrafmt: tools
7171
@ echo "-> Running terraform docs codeblocks linter"
7272
@ find ./docs -type f -name "*.md" -exec $(GOBIN)/terrafmt diff -f {} \;
7373

74+
.PHONY: terrafmt-fmt
75+
terrafmt-fmt: tools
76+
@ echo "-> Running terraform docs codeblocks linter"
77+
@ find ./docs -type f -name "*.md" -exec $(GOBIN)/terrafmt fmt -f {} \;
78+
7479
configfmt:
7580
@ echo "-> Running terraform linters on .tf files"
7681
@ terraform fmt -write=false -recursive -check
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
page_title: "oxide_address_lot Data Source - terraform-provider-oxide"
3+
---
4+
5+
# oxide_address_lot (Data Source)
6+
7+
Retrieve information about a specified address lot.
8+
9+
## Example Usage
10+
11+
```hcl
12+
data "oxide_address_lot" "example" {
13+
name = "test-address-lot"
14+
}
15+
```
16+
17+
## Schema
18+
19+
### Required
20+
21+
- `name` (String) Name of the address lot.
22+
23+
### Optional
24+
25+
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))
26+
27+
### Read-Only
28+
29+
- `blocks` (Attributes Set) (see [below for nested schema](#nestedatt--blocks))
30+
- `description` (String) Description for the address lot.
31+
- `id` (String) Unique, immutable, system-controlled identifier of the address lot.
32+
- `kind` (String) Kind for the address lot.
33+
- `time_created` (String) Timestamp of when this address lot was created.
34+
- `time_modified` (String) Timestamp of when this address lot was last modified.
35+
36+
<a id="nestedatt--timeouts"></a>
37+
38+
### Nested Schema for `timeouts`
39+
40+
Optional:
41+
42+
- `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).
43+
44+
<a id="nestedatt--blocks"></a>
45+
46+
### Nested Schema for `blocks`
47+
48+
Read-Only:
49+
50+
- `first_address` (String) First address in the lot.
51+
- `id` (String) ID of the address lot block.
52+
- `last_address` (String) Last address in the lot.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
page_title: "oxide_address_lot Resource - terraform-provider-oxide"
3+
---
4+
5+
# oxide_address_lot (Resource)
6+
7+
This resource manages address lots.
8+
9+
## Example Usage
10+
11+
```hcl
12+
resource "oxide_address_lot" "example" {
13+
description = "a test address lot"
14+
name = "test-address-lot"
15+
kind = "pool"
16+
blocks = [
17+
{
18+
first_address = "172.20.18.227"
19+
last_address = "172.20.18.239"
20+
}
21+
]
22+
}
23+
```
24+
25+
## Schema
26+
27+
### Required
28+
29+
- `blocks` (Attributes Set) (see [below for nested schema](#nestedatt--blocks))
30+
- `description` (String) Description for the address lot.
31+
- `kind` (String) Kind for the address lot.
32+
- `name` (String) Name of the address lot.
33+
34+
### Optional
35+
36+
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))
37+
38+
### Read-Only
39+
40+
- `id` (String) Unique, immutable, system-controlled identifier of the address lot.
41+
- `time_created` (String) Timestamp of when this address lot was created.
42+
- `time_modified` (String) Timestamp of when this address lot was last modified.
43+
44+
<a id="nestedatt--blocks"></a>
45+
46+
### Nested Schema for `blocks`
47+
48+
Required:
49+
50+
- `first_address` (String) First address in the lot.
51+
- `last_address` (String) Last address in the lot.
52+
53+
Read-Only:
54+
55+
- `id` (String) ID of the address lot block.
56+
57+
<a id="nestedatt--timeouts"></a>
58+
59+
### Nested Schema for `timeouts`
60+
61+
Optional:
62+
63+
- `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).
64+
- `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.
65+
- `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.
66+
- `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).

docs/resources/oxide_ip_pool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ Optional:
6363
- `create` (String, Default `10m`)
6464
- `delete` (String, Default `10m`)
6565
- `read` (String, Default `10m`)
66-
- `update` (String, Default `10m`)
66+
- `update` (String, Default `10m`)

docs/resources/oxide_vpc_firewall_rules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ resource "oxide_vpc_firewall_rules" "example" {
7070
},
7171
# Echo Reply types.
7272
{
73-
type = "icmp",
73+
type = "icmp",
7474
icmp_type = 0
7575
},
7676
# Echo Reply types with codes 1-3.
7777
{
78-
type = "icmp",
78+
type = "icmp",
7979
icmp_type = 0
8080
icmp_code = "1-3"
8181
},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/hashicorp/terraform-plugin-log v0.9.0
1212
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
1313
github.com/hashicorp/terraform-plugin-testing v1.13.2
14-
github.com/oxidecomputer/oxide.go v0.5.1-0.20250804182320-d8df86da3154
14+
github.com/oxidecomputer/oxide.go v0.5.1-0.20250812235420-289bbe3858c7
1515
github.com/stretchr/testify v1.10.0
1616
)
1717

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
136136
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
137137
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
138138
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
139-
github.com/oxidecomputer/oxide.go v0.5.1-0.20250804182320-d8df86da3154 h1:qftdu0QhJq6PKHX+AQBjG8wTBpUP4PeY7QHfldRbJ1o=
140-
github.com/oxidecomputer/oxide.go v0.5.1-0.20250804182320-d8df86da3154/go.mod h1:4gfHlxdBQLs/34UbChPvINd+pGNAnGlASRGEd4xIz1Y=
139+
github.com/oxidecomputer/oxide.go v0.5.1-0.20250812235420-289bbe3858c7 h1:GpdJzutYq0OH2nDAt7/XUBah+Xu1MWiy6KyHlL1zRcE=
140+
github.com/oxidecomputer/oxide.go v0.5.1-0.20250812235420-289bbe3858c7/go.mod h1:4gfHlxdBQLs/34UbChPvINd+pGNAnGlASRGEd4xIz1Y=
141141
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
142142
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
143143
github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4=
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
package provider
6+
7+
import (
8+
"context"
9+
"fmt"
10+
11+
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
12+
"github.com/hashicorp/terraform-plugin-framework/datasource"
13+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
14+
"github.com/hashicorp/terraform-plugin-framework/types"
15+
"github.com/hashicorp/terraform-plugin-log/tflog"
16+
"github.com/oxidecomputer/oxide.go/oxide"
17+
)
18+
19+
var _ datasource.DataSource = (*addressLotDataSource)(nil)
20+
var _ datasource.DataSourceWithConfigure = (*addressLotDataSource)(nil)
21+
22+
type addressLotDataSource struct {
23+
client *oxide.Client
24+
}
25+
26+
type addressLotDataSourceModel struct {
27+
Blocks []addressLotDataSourceBlockModel `tfsdk:"blocks"`
28+
Description types.String `tfsdk:"description"`
29+
Kind types.String `tfsdk:"kind"`
30+
Name types.String `tfsdk:"name"`
31+
ID types.String `tfsdk:"id"`
32+
TimeCreated types.String `tfsdk:"time_created"`
33+
TimeModified types.String `tfsdk:"time_modified"`
34+
Timeouts timeouts.Value `tfsdk:"timeouts"`
35+
}
36+
37+
type addressLotDataSourceBlockModel struct {
38+
ID types.String `tfsdk:"id"`
39+
FirstAddress types.String `tfsdk:"first_address"`
40+
LastAddress types.String `tfsdk:"last_address"`
41+
}
42+
43+
// NewAddressLotDataSource initialises an address_lot datasource.
44+
func NewAddressLotDataSource() datasource.DataSource {
45+
return &addressLotDataSource{}
46+
}
47+
48+
func (d *addressLotDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
49+
resp.TypeName = "oxide_address_lot"
50+
}
51+
52+
// Configure adds the provider configured client to the data source.
53+
func (d *addressLotDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
54+
if req.ProviderData == nil {
55+
return
56+
}
57+
58+
d.client = req.ProviderData.(*oxide.Client)
59+
}
60+
61+
func (d *addressLotDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
62+
resp.Schema = schema.Schema{
63+
Attributes: map[string]schema.Attribute{
64+
"name": schema.StringAttribute{
65+
Required: true,
66+
Description: "Name of the address lot.",
67+
},
68+
"description": schema.StringAttribute{
69+
Computed: true,
70+
Description: "Description for the address lot.",
71+
},
72+
"kind": schema.StringAttribute{
73+
Computed: true,
74+
Description: "Kind for the address lot.",
75+
},
76+
"blocks": schema.SetNestedAttribute{
77+
Computed: true,
78+
NestedObject: schema.NestedAttributeObject{
79+
Attributes: map[string]schema.Attribute{
80+
"id": schema.StringAttribute{
81+
Description: "ID of the address lot block.",
82+
Computed: true,
83+
},
84+
"first_address": schema.StringAttribute{
85+
Description: "First address in the lot.",
86+
Computed: true,
87+
},
88+
"last_address": schema.StringAttribute{
89+
Description: "Last address in the lot.",
90+
Computed: true,
91+
},
92+
},
93+
},
94+
},
95+
"id": schema.StringAttribute{
96+
Computed: true,
97+
Description: "Unique, immutable, system-controlled identifier of the address lot.",
98+
},
99+
"time_created": schema.StringAttribute{
100+
Computed: true,
101+
Description: "Timestamp of when this address lot was created.",
102+
},
103+
"time_modified": schema.StringAttribute{
104+
Computed: true,
105+
Description: "Timestamp of when this address lot was last modified.",
106+
},
107+
"timeouts": timeouts.Attributes(ctx),
108+
},
109+
}
110+
}
111+
112+
func (d *addressLotDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
113+
var state addressLotDataSourceModel
114+
115+
// Read Terraform configuration data into the model
116+
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
117+
if resp.Diagnostics.HasError() {
118+
return
119+
}
120+
121+
readTimeout, diags := state.Timeouts.Read(ctx, defaultTimeout())
122+
resp.Diagnostics.Append(diags...)
123+
if resp.Diagnostics.HasError() {
124+
return
125+
}
126+
ctx, cancel := context.WithTimeout(ctx, readTimeout)
127+
defer cancel()
128+
129+
addressLot, err := d.client.NetworkingAddressLotView(ctx, oxide.NetworkingAddressLotViewParams{
130+
AddressLot: oxide.NameOrId(state.Name.ValueString()),
131+
})
132+
if err != nil {
133+
resp.Diagnostics.AddError(
134+
"Unable to read address lot:",
135+
"API error: "+err.Error(),
136+
)
137+
return
138+
}
139+
lot := addressLot.Lot
140+
tflog.Trace(ctx, fmt.Sprintf("read address lot with ID: %v", lot.Id), map[string]any{"success": true})
141+
142+
state.ID = types.StringValue(lot.Id)
143+
state.Name = types.StringValue(string(lot.Name))
144+
state.Kind = types.StringValue(string(lot.Kind))
145+
state.Description = types.StringValue(lot.Description)
146+
state.TimeCreated = types.StringValue(lot.TimeCreated.String())
147+
state.TimeModified = types.StringValue(lot.TimeCreated.String())
148+
149+
blockModels := make([]addressLotDataSourceBlockModel, len(addressLot.Blocks))
150+
for index, item := range addressLot.Blocks {
151+
blockModels[index] = addressLotDataSourceBlockModel{
152+
ID: types.StringValue(item.Id),
153+
FirstAddress: types.StringValue(item.FirstAddress),
154+
LastAddress: types.StringValue(item.LastAddress),
155+
}
156+
}
157+
state.Blocks = blockModels
158+
159+
// Save state into Terraform state
160+
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
161+
if resp.Diagnostics.HasError() {
162+
return
163+
}
164+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
package provider
6+
7+
import (
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
)
12+
13+
var testDataSourceAddressLotConfig = `
14+
resource "oxide_address_lot" "test" {
15+
description = "a test address lot"
16+
name = "terraform-acc-my-address-lot"
17+
kind = "infra"
18+
blocks = [
19+
{
20+
first_address = "172.0.1.1"
21+
last_address = "172.0.1.10"
22+
},
23+
]
24+
}
25+
26+
data "oxide_address_lot" "test" {
27+
name = oxide_address_lot.test.name
28+
}
29+
`
30+
31+
func TestAccDataSourceAddressLot_full(t *testing.T) {
32+
resourceName := "oxide_address_lot.test"
33+
resource.ParallelTest(t, resource.TestCase{
34+
PreCheck: func() { testAccPreCheck(t) },
35+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
36+
Steps: []resource.TestStep{
37+
{
38+
Config: testDataSourceAddressLotConfig,
39+
Check: checkDataSourceAddressLot(resourceName),
40+
},
41+
},
42+
})
43+
}
44+
45+
func checkDataSourceAddressLot(dataName string) resource.TestCheckFunc {
46+
return resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
47+
resource.TestCheckResourceAttrSet(dataName, "id"),
48+
resource.TestCheckResourceAttr(dataName, "description", "a test address lot"),
49+
resource.TestCheckResourceAttr(dataName, "name", "terraform-acc-my-address-lot"),
50+
resource.TestCheckResourceAttrSet(dataName, "blocks.0.first_address"),
51+
resource.TestCheckResourceAttrSet(dataName, "blocks.0.last_address"),
52+
resource.TestCheckResourceAttr(dataName, "blocks.0.first_address", "172.0.1.1"),
53+
resource.TestCheckResourceAttr(dataName, "blocks.0.last_address", "172.0.1.10"),
54+
resource.TestCheckResourceAttrSet(dataName, "time_created"),
55+
resource.TestCheckResourceAttrSet(dataName, "time_modified"),
56+
}...)
57+
}

0 commit comments

Comments
 (0)