Skip to content

Commit 87ec2ec

Browse files
authored
Add support for pools and ranges (#42)
1 parent ddac0f5 commit 87ec2ec

File tree

13 files changed

+660
-227
lines changed

13 files changed

+660
-227
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.1.0 (unreleased)
2+
3+
- Add support for multiple pools
4+
- Add support for IP ranges
5+
- Improve provider configuration validation
6+
17
## 0.0.2
28

39
- Fix assignment of multiple ÍPs

docs/index.md

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,37 @@
33
layout: ""
44
page_title: "Provider: IPAM"
55
description: |-
6-
The IPAM provider manages a list of IP addresses and can assign IP addresses to unique IDs (e.g., hostnames).
6+
The IPAM provider manages pools of IP addresses and can allocate IP addresses to hosts.
77
---
88

99
# IPAM Provider
1010

11-
The IPAM provider manages a list of IP addresses and can assign IP addresses to unique IDs (e.g., hostnames).
11+
The IPAM provider manages pools of IP addresses and can allocate IP addresses to hosts.
1212

1313
## Example Usage
1414

1515
```terraform
1616
provider "ipam" {
17-
addresses = [
17+
pools = [
1818
{
19-
ip = "1.1.1.1"
20-
prefix_length = "24"
19+
name = "POOL1"
20+
prefix_length = 24
2121
gateway = "1.1.1.254"
22-
},
23-
{
24-
ip = "1.1.1.2"
25-
prefix_length = "24"
26-
gateway = "1.1.1.254"
27-
},
28-
{
29-
ip = "1.1.1.3"
30-
prefix_length = "24"
31-
gateway = "1.1.1.254"
32-
},
22+
ranges = [
23+
{
24+
from_ip = "1.1.1.1"
25+
to_ip = "1.1.1.10"
26+
}
27+
]
28+
addresses = [
29+
{
30+
ip = "1.1.1.20"
31+
},
32+
{
33+
ip = "1.1.1.30"
34+
},
35+
]
36+
}
3337
]
3438
}
3539
```
@@ -39,13 +43,44 @@ provider "ipam" {
3943

4044
### Required
4145

42-
- `addresses` (Attributes List) A list of managed addresses. (see [below for nested schema](#nestedatt--addresses))
46+
- `pools` (Attributes List) A list of managed IP pools. (see [below for nested schema](#nestedatt--pools))
4347

44-
<a id="nestedatt--addresses"></a>
45-
### Nested Schema for `addresses`
48+
<a id="nestedatt--pools"></a>
49+
### Nested Schema for `pools`
50+
51+
Required:
52+
53+
- `name` (String) IP pool name.
54+
55+
Optional:
56+
57+
- `addresses` (Attributes List) A list of IP addresses. (see [below for nested schema](#nestedatt--pools--addresses))
58+
- `gateway` (String) Default gateway IP.
59+
- `prefix_length` (Number) Default prefix length.
60+
- `ranges` (Attributes List) A list of IP ranges. (see [below for nested schema](#nestedatt--pools--ranges))
61+
62+
<a id="nestedatt--pools--addresses"></a>
63+
### Nested Schema for `pools.addresses`
4664

4765
Required:
4866

49-
- `gateway` (String) Gateway IP.
5067
- `ip` (String) IP address.
51-
- `prefix_length` (String) Prefix length.
68+
69+
Optional:
70+
71+
- `gateway` (String) Gateway IP.
72+
- `prefix_length` (Number) Prefix length.
73+
74+
75+
<a id="nestedatt--pools--ranges"></a>
76+
### Nested Schema for `pools.ranges`
77+
78+
Required:
79+
80+
- `from_ip` (String) First IP.
81+
- `to_ip` (String) Last IP.
82+
83+
Optional:
84+
85+
- `gateway` (String) Gateway IP.
86+
- `prefix_length` (Number) Prefix length.

docs/resources/allocate.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,63 @@
33
page_title: "ipam_allocate Resource - terraform-provider-ipam"
44
subcategory: ""
55
description: |-
6-
Allocate one IP per ID.
6+
Allocate one IP from a pool per unique host ID. A single resource must be used per pool.
77
---
88

99
# ipam_allocate (Resource)
1010

11-
Allocate one IP per ID.
11+
Allocate one IP from a pool per unique host ID. A single resource must be used per pool.
1212

1313
## Example Usage
1414

1515
```terraform
1616
resource "ipam_allocate" "example" {
17-
addresses = {
17+
pool = "POOL1"
18+
hosts = {
1819
"host1" = {}
1920
"host2" = {}
2021
}
2122
}
23+
24+
output "hosts" {
25+
value = ipam_allocate.example.hosts
26+
}
27+
28+
/*
29+
hosts = tomap({
30+
"host1" = {
31+
"gateway" = "1.1.1.254"
32+
"ip" = "1.1.1.1"
33+
"prefix_length" = 24
34+
}
35+
"host2" = {
36+
"gateway" = "1.1.1.254"
37+
"ip" = "1.1.1.2"
38+
"prefix_length" = 24
39+
}
40+
})
41+
*/
2242
```
2343

2444
<!-- schema generated by tfplugindocs -->
2545
## Schema
2646

2747
### Required
2848

29-
- `addresses` (Attributes Map) A list of IDs and its addresses. (see [below for nested schema](#nestedatt--addresses))
49+
- `hosts` (Attributes Map) A map of host IDs and its assigned addresses. (see [below for nested schema](#nestedatt--hosts))
50+
- `pool` (String) Pool name. Must reference a pool from the provider configuration.
51+
52+
### Read-Only
53+
54+
- `id` (String) Random internal ID.
3055

31-
<a id="nestedatt--addresses"></a>
32-
### Nested Schema for `addresses`
56+
<a id="nestedatt--hosts"></a>
57+
### Nested Schema for `hosts`
3358

34-
Required:
59+
Read-Only:
3560

3661
- `gateway` (String) Gateway IP.
3762
- `ip` (String) IP address.
38-
- `prefix_length` (String) Prefix length.
63+
- `prefix_length` (Number) Prefix length.
3964

4065

examples/provider/provider.tf

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
provider "ipam" {
2-
addresses = [
2+
pools = [
33
{
4-
ip = "1.1.1.1"
5-
prefix_length = "24"
4+
name = "POOL1"
5+
prefix_length = 24
66
gateway = "1.1.1.254"
7-
},
8-
{
9-
ip = "1.1.1.2"
10-
prefix_length = "24"
11-
gateway = "1.1.1.254"
12-
},
13-
{
14-
ip = "1.1.1.3"
15-
prefix_length = "24"
16-
gateway = "1.1.1.254"
17-
},
7+
ranges = [
8+
{
9+
from_ip = "1.1.1.1"
10+
to_ip = "1.1.1.10"
11+
}
12+
]
13+
addresses = [
14+
{
15+
ip = "1.1.1.20"
16+
},
17+
{
18+
ip = "1.1.1.30"
19+
},
20+
]
21+
}
1822
]
1923
}
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
resource "ipam_allocate" "example" {
2-
addresses = {
2+
pool = "POOL1"
3+
hosts = {
34
"host1" = {}
45
"host2" = {}
56
}
67
}
8+
9+
output "hosts" {
10+
value = ipam_allocate.example.hosts
11+
}
12+
13+
/*
14+
hosts = tomap({
15+
"host1" = {
16+
"gateway" = "1.1.1.254"
17+
"ip" = "1.1.1.1"
18+
"prefix_length" = 24
19+
}
20+
"host2" = {
21+
"gateway" = "1.1.1.254"
22+
"ip" = "1.1.1.2"
23+
"prefix_length" = 24
24+
}
25+
})
26+
*/

go.mod

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/hashicorp/terraform-plugin-docs v0.13.0
7-
github.com/hashicorp/terraform-plugin-framework v0.16.0
7+
github.com/hashicorp/terraform-plugin-framework v0.17.0
88
github.com/hashicorp/terraform-plugin-go v0.14.2
99
github.com/hashicorp/terraform-plugin-log v0.7.0
1010
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
@@ -27,7 +27,7 @@ require (
2727
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
2828
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
2929
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
30-
github.com/hashicorp/go-hclog v1.2.1 // indirect
30+
github.com/hashicorp/go-hclog v1.3.1 // indirect
3131
github.com/hashicorp/go-multierror v1.1.1 // indirect
3232
github.com/hashicorp/go-plugin v1.4.6 // indirect
3333
github.com/hashicorp/go-uuid v1.0.3 // indirect
@@ -39,32 +39,32 @@ require (
3939
github.com/hashicorp/terraform-json v0.14.0 // indirect
4040
github.com/hashicorp/terraform-registry-address v0.1.0 // indirect
4141
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
42-
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
42+
github.com/hashicorp/yamux v0.1.1 // indirect
4343
github.com/huandu/xstrings v1.3.2 // indirect
4444
github.com/imdario/mergo v0.3.13 // indirect
45-
github.com/mattn/go-colorable v0.1.12 // indirect
46-
github.com/mattn/go-isatty v0.0.14 // indirect
45+
github.com/mattn/go-colorable v0.1.13 // indirect
46+
github.com/mattn/go-isatty v0.0.16 // indirect
4747
github.com/mitchellh/cli v1.1.4 // indirect
4848
github.com/mitchellh/copystructure v1.2.0 // indirect
4949
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
5050
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
5151
github.com/mitchellh/mapstructure v1.5.0 // indirect
5252
github.com/mitchellh/reflectwalk v1.0.2 // indirect
53-
github.com/oklog/run v1.0.0 // indirect
53+
github.com/oklog/run v1.1.0 // indirect
5454
github.com/posener/complete v1.2.3 // indirect
5555
github.com/russross/blackfriday v1.6.0 // indirect
5656
github.com/shopspring/decimal v1.3.1 // indirect
5757
github.com/spf13/cast v1.5.0 // indirect
5858
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
5959
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
60-
github.com/vmihailenco/tagparser v0.1.1 // indirect
60+
github.com/vmihailenco/tagparser v0.1.2 // indirect
6161
github.com/zclconf/go-cty v1.12.1 // indirect
6262
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
63-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
64-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
63+
golang.org/x/net v0.2.0 // indirect
64+
golang.org/x/sys v0.2.0 // indirect
6565
golang.org/x/text v0.4.0 // indirect
66-
google.golang.org/appengine v1.6.6 // indirect
67-
google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect
66+
google.golang.org/appengine v1.6.7 // indirect
67+
google.golang.org/genproto v0.0.0-20221201204527-e3fa12d562f3 // indirect
6868
google.golang.org/grpc v1.51.0 // indirect
6969
google.golang.org/protobuf v1.28.1 // indirect
7070
)

0 commit comments

Comments
 (0)