Skip to content

Commit

Permalink
Feat/ip data source (#241)
Browse files Browse the repository at this point in the history
* feat: implement ips data source

* chore(test): fix acceptance test pipeline

* fix: set correct Dockerfile path
  • Loading branch information
alrayyes authored Dec 30, 2024
1 parent d48902d commit 15f006a
Show file tree
Hide file tree
Showing 49 changed files with 848 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
PUBLIC_CLOUD_API_SPEC_URL=https://raw.githubusercontent.com/Leaseweb/leaseweb-go-sdk/main/publiccloud/api/openapi.yaml
DEDICATED_SERVER_API_SPEC_URL=https://raw.githubusercontent.com/Leaseweb/leaseweb-go-sdk/main/dedicatedserver/api/openapi.yaml
DNS_API_SPEC_URL=https://raw.githubusercontent.com/Leaseweb/leaseweb-go-sdk/main/dns/api/openapi.yaml
IPMGMT_API_SPEC_URL=https://raw.githubusercontent.com/Leaseweb/leaseweb-go-sdk/main/ipmgmt/api/openapi.yaml
#PUBLIC_CLOUD_API_SPEC_URL=http://host.docker.internal:8081/publicCloud.json
#DEDICATED_SERVER_API_SPEC_URL=http://host.docker.internal:8081/dedicatedServer.json
#DNS_SERVER_API_SPEC_URL=http://host.docker.internal:8081/dns.json
#IPMGMT_API_SPEC_URL=http://host.docker.internal:8081/ipmgmt.json
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ services:
- path: .env
extra_hosts:
- "host.docker.internal:host-gateway"
prism_ipmgmt:
container_name: prism_ipmgmt
build:
dockerfile: docker/prism/Dockerfile
command: >
mock -p 4010 --host 0.0.0.0
${IPMGMT_API_SPEC_URL}
env_file:
- path: .env
extra_hosts:
- "host.docker.internal:host-gateway"
prism-proxy:
build:
dockerfile: docker/caddy/Dockerfile
Expand All @@ -76,6 +87,7 @@ services:
- prism_public_cloud
- prism_dedicated_server
- prism_dns
- prism_ipmgmt

volumes:
golang:
5 changes: 5 additions & 0 deletions docker/caddy/prism/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ route /hosting/v2/* {
reverse_proxy prism_dns:4010
}

route /ipMgmt/v2/* {
uri strip_prefix /ipMgmt/v2
reverse_proxy prism_ipmgmt:4010
}

log {
format console
}
13 changes: 13 additions & 0 deletions docker/docker-compose-acc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ services:
- path: .env
extra_hosts:
- "host.docker.internal:host-gateway"
prism_ipmgmt:
container_name: prism_ipmgmt
build:
dockerfile: prism/Dockerfile
command: >
mock -p 4010 --host 0.0.0.0
${IPMGMT_API_SPEC_URL}
env_file:
- path: .env
extra_hosts:
- "host.docker.internal:host-gateway"
prism-proxy:
build:
dockerfile: caddy/Dockerfile
Expand All @@ -42,3 +53,5 @@ services:
depends_on:
- prism_public_cloud
- prism_dedicated_server
- prism_dns
- prism_ipmgmt
85 changes: 85 additions & 0 deletions docs/data-sources/ipmgmt_ips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "leaseweb_ipmgmt_ips Data Source - leaseweb"
subcategory: ""
description: |-
---

# leaseweb_ipmgmt_ips (Data Source)



## Example Usage

```terraform
# List all IPs
data "leaseweb_ipmgmt_ips" "all" {}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `assigned_contract_ids` (List of String) Return only IPs assigned to contracts with these IDs
- `equipment_ids` (List of String) Return only IPs assigned to equipment items
- `filtered_ips` (List of String) Return only these IPs
- `from_ip` (String) Return only IPs greater or equal to the specified address
- `null_routed` (Boolean) Filter by whether the IP has an active null route
- `primary` (Boolean) Filter by whether or not the IP is primary
- `reverse_lookup` (String) Filter by reverse lookup
- `sort` (List of String) Sort field names. Prepend the field name with '-' for descending order. E.g. `ip,-nullrouted`. Sortable field names are `ip`, `nullRouted`, `reverseLookup`
- `subnet_id` (String) Filter by subnet
- `to_ip` (String) Return only IPs lower or equal to the specified address
- `type` (String) Filter by IP type. Valid options are
- *NORMAL_IP*
- *NETWORK*
- *BROADCAST*
- *GATEWAY*
- *ROUTER1*
- *ROUTER2*
- *IPMI*
- `version` (Number) Filter by protocol version. Valid options are
- *4*
- *6*

### Read-Only

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

<a id="nestedatt--ips"></a>
### Nested Schema for `ips`

Read-Only:

- `assigned_contract` (Attributes) (see [below for nested schema](#nestedatt--ips--assigned_contract))
- `equipment_id` (String) ID of the equipment using the IP
- `ip` (String) IP address
- `null_level` (Number) Null route level
- `null_routed` (Boolean) Boolean to indicate if the IP is null-routed
- `prefix_length` (Number) Prefix length of the IP range represented by the record. Note: this is not the same as `subnet.prefixLength`
- `primary` (Boolean) Boolean indicating if this is the primary IP of the assigned equipment
- `reverse_lookup` (String) Reverse lookup set for the IP. This only applies to IPv4
- `subnet` (Attributes) (see [below for nested schema](#nestedatt--ips--subnet))
- `type` (String) IP type
- `unnulling_allowed` (Boolean) Boolean indicating if the null route can be removed
- `version` (Number) Protocol version

<a id="nestedatt--ips--assigned_contract"></a>
### Nested Schema for `ips.assigned_contract`

Read-Only:

- `id` (String) ID of the contract connected to the IP


<a id="nestedatt--ips--subnet"></a>
### Nested Schema for `ips.subnet`

Read-Only:

- `gateway` (String) The gateway IP to be used in network settings
- `id` (String) Subnet identifier consisting of network IP and prefix length separated by underscore (e.g. 192.0.2.0_24)
- `network_ip` (String) Network IP of the subnet
- `prefix_length` (Number) Address prefix length
2 changes: 2 additions & 0 deletions examples/data-sources/leaseweb_ipmgmt_ips/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# List all IPs
data "leaseweb_ipmgmt_ips" "all" {}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ require (
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/leaseweb/leaseweb-go-sdk/v3 v3.2.0
github.com/leaseweb/leaseweb-go-sdk/dedicatedserver v0.0.0-20241230111213-3c3be0c1799d
github.com/leaseweb/leaseweb-go-sdk/dns v0.0.0-20241230111213-3c3be0c1799d
github.com/leaseweb/leaseweb-go-sdk/ipmgmt v0.0.0-20241230111213-3c3be0c1799d
github.com/leaseweb/leaseweb-go-sdk/publiccloud v0.0.0-20241230111213-3c3be0c1799d
github.com/stretchr/testify v1.10.0
)

Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,14 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/leaseweb/leaseweb-go-sdk/v3 v3.2.0 h1:7yw3TcU/gmtujieBdiQ0S7y803PgqkuYG4+ONAX0bmo=
github.com/leaseweb/leaseweb-go-sdk/v3 v3.2.0/go.mod h1:PMSo8i57KR7k2RlS2K0OH1dKf5FHxOY3eDzXBZ69Lig=
github.com/leaseweb/leaseweb-go-sdk/dedicatedserver v0.0.0-20241230111213-3c3be0c1799d h1:8f3E6JqTlFFyUp8geaAnOEDE3DoSbTTUWkPoXjrm+VE=
github.com/leaseweb/leaseweb-go-sdk/dedicatedserver v0.0.0-20241230111213-3c3be0c1799d/go.mod h1:8c8VAxXnjCxuUEss0Unrd5NB9o7oAkOPeORCs58y76s=
github.com/leaseweb/leaseweb-go-sdk/dns v0.0.0-20241230111213-3c3be0c1799d h1:QZ1Y3Ht4yznT1lENi90eU4LUlyrcHgK3Z8SPV6e2T6E=
github.com/leaseweb/leaseweb-go-sdk/dns v0.0.0-20241230111213-3c3be0c1799d/go.mod h1:ntxqh2fT7XDwjPLNsWtq6tTjwjL/75llxnbzEZvvzIo=
github.com/leaseweb/leaseweb-go-sdk/ipmgmt v0.0.0-20241230111213-3c3be0c1799d h1:+VsKOBalRTClDO3kAAcbx+4qDcJtYbUhsYk4qe82abQ=
github.com/leaseweb/leaseweb-go-sdk/ipmgmt v0.0.0-20241230111213-3c3be0c1799d/go.mod h1:ipS7tM7zdo0VGHnw6RF5e+7O0aPI7xAj/C5JjJPh6hU=
github.com/leaseweb/leaseweb-go-sdk/publiccloud v0.0.0-20241230111213-3c3be0c1799d h1:y/26SD6eX/Qikvp3u3WdYLWg6QaT6rUv6TWp/m5tw2U=
github.com/leaseweb/leaseweb-go-sdk/publiccloud v0.0.0-20241230111213-3c3be0c1799d/go.mod h1:AYJsx8WlHYQXRAzEMuXzuApwIctcLPFazfAo9uy6ogY=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down
16 changes: 13 additions & 3 deletions internal/provider/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
package client

import (
"github.com/leaseweb/leaseweb-go-sdk/v3/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/v3/dns"
"github.com/leaseweb/leaseweb-go-sdk/v3/publiccloud"
"github.com/leaseweb/leaseweb-go-sdk/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/dns"
"github.com/leaseweb/leaseweb-go-sdk/ipmgmt"
"github.com/leaseweb/leaseweb-go-sdk/publiccloud"
)

const userAgentBase = "leaseweb-terraform"
Expand All @@ -14,6 +15,7 @@ type Client struct {
PubliccloudAPI publiccloud.PubliccloudAPI
DedicatedserverAPI dedicatedserver.DedicatedserverAPI
DNSAPI dns.DnsAPI
IPmgmtAPI ipmgmt.IpmgmtAPI
}

type Optional struct {
Expand All @@ -25,16 +27,19 @@ func NewClient(token string, optional Optional, version string) Client {
publiccloudCFG := publiccloud.NewConfiguration()
dedicatedserverCFG := dedicatedserver.NewConfiguration()
dnsCFG := dns.NewConfiguration()
ipmgmtCFG := ipmgmt.NewConfiguration()

if optional.Host != nil {
publiccloudCFG.Host = *optional.Host
dedicatedserverCFG.Host = *optional.Host
dnsCFG.Host = *optional.Host
ipmgmtCFG.Host = *optional.Host
}
if optional.Scheme != nil {
publiccloudCFG.Scheme = *optional.Scheme
dedicatedserverCFG.Scheme = *optional.Scheme
dnsCFG.Scheme = *optional.Scheme
ipmgmtCFG.Scheme = *optional.Scheme
}

userAgent := userAgentBase + "-" + version
Expand All @@ -48,13 +53,18 @@ func NewClient(token string, optional Optional, version string) Client {
dnsCFG.AddDefaultHeader("X-LSW-Auth", token)
dnsCFG.UserAgent = userAgent

ipmgmtCFG.AddDefaultHeader("X-LSW-Auth", token)
ipmgmtCFG.UserAgent = userAgent

publiccloudAPI := publiccloud.NewAPIClient(publiccloudCFG)
dedicatedserverAPI := dedicatedserver.NewAPIClient(dedicatedserverCFG)
dnsAPI := dns.NewAPIClient(dnsCFG)
ipmgmtAPI := ipmgmt.NewAPIClient(ipmgmtCFG)

return Client{
PubliccloudAPI: publiccloudAPI.PubliccloudAPI,
DedicatedserverAPI: dedicatedserverAPI.DedicatedserverAPI,
DNSAPI: dnsAPI.DnsAPI,
IPmgmtAPI: ipmgmtAPI.IpmgmtAPI,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/leaseweb/leaseweb-go-sdk/v3/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/dedicatedserver"
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/leaseweb/leaseweb-go-sdk/v3/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/dedicatedserver"
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/dedicatedserver/credential_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/leaseweb/leaseweb-go-sdk/v3/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/dedicatedserver"
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/dedicatedserver/installation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/leaseweb/leaseweb-go-sdk/v3/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/dedicatedserver"
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/leaseweb/leaseweb-go-sdk/v3/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/dedicatedserver"
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/leaseweb/leaseweb-go-sdk/v3/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/dedicatedserver"
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/dedicatedserver/server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/leaseweb/leaseweb-go-sdk/v3/dedicatedserver"
"github.com/leaseweb/leaseweb-go-sdk/dedicatedserver"
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/dns/resource_record_set_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/leaseweb/leaseweb-go-sdk/v3/dns"
"github.com/leaseweb/leaseweb-go-sdk/dns"
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils"
)

Expand Down
2 changes: 2 additions & 0 deletions internal/provider/ipmgmt/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package ipmgmt implements functionality for IP management.
package ipmgmt
Loading

0 comments on commit 15f006a

Please sign in to comment.