Skip to content

Commit

Permalink
Merge pull request #68 from lord-kyron/l2domains
Browse files Browse the repository at this point in the history
Added l2domains controller. Fixed various bugs in another controllers
  • Loading branch information
lord-kyron authored May 13, 2023
2 parents fc2209f + 327de8c commit 892b73e
Show file tree
Hide file tree
Showing 1,383 changed files with 1,307 additions and 345,250 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test:
go test -v $(shell go list ./... | grep -v /vendor/)

testacc:
TF_ACC=1 go test -v ./plugin/providers/phpipam -run="TestAcc"
go clean -testcache; TF_ACC=1 go test -v ./plugin/providers/phpipam -run="TestAcc"

build: deps
gox -osarch="linux/amd64 windows/amd64 darwin/amd64 darwin/arm64" \
Expand Down
113 changes: 98 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,104 @@ and IP addresses, entirely within Terraform.
[3]: https://phpipam.net/api/api_documentation/
[4]: https://github.com/pavel-z1/phpipam-sdk-go

## Installing
## Building

The provider's executable files are hosted on the [Terraform Repository][8] and are
ready to use without additional assembly.
See the [Plugin Basics][5] page of the Terraform docs to see how to plunk this
into your config. Check the [releases page][6] of this repo to get releases for
Linux, OS X, and Windows.

[5]: https://www.terraform.io/docs/plugins/basics.html
[6]: https://github.com/lord-kyron/terraform-provider-phpipam/releases
[8]: https://registry.terraform.io/providers/lord-kyron/phpipam/latest

Examle for CentOS 7:
How to build providerExamle for Rocky Linux 8:
Build from repo:
```
yum install golang git
mkdir -p $HOME/development/terraform-providers/
sudo yum install golang git
sudo mkdir -p $HOME/development/terraform-providers/
cd $HOME/development/terraform-providers/
git clone https://github.com/lord-kyron/terraform-provider-phpipam
# In some cases need execute go install twice
go install
go build
cp terraform-provider-phpipam ~/.terraform.d/plugins/
cp terraform-provider-phpipam ~/.terraform.d/plugins/local.dev/phpipam/{version}/{os_platform}/
```

## Unit tests

Requirements:
1. Ready for usage phpIPAM instance
2. Created Custom fields for IP address, subnets, vlans objects inside phpIPAM
should be created ext custom fields:
Custom IP addresses fields:
- CustomTestAddresses varchar(30)
- CustomTestAddresses2 varchar(30)
Custom Subnets fields:
- CustomTestSubnets varchar(30)
- CustomTestSubnets2 varchar(30)
Custom VLAN fields:
- CustomTestVLANs varchar(30)
3. Exported environment variable with phpIPAM credentials. Example:
```
export PHPIPAM_APP_ID="terraform"
export PHPIPAM_ENDPOINT_ADDR="http://10.10.0.1/api"
export PHPIPAM_PASSWORD="password"
export PHPIPAM_USER_NAME="Admin"
```

To start unit test exec next command:
```
make testacc
```

Example unit test results:
```
go clean -testcache; TF_ACC=1 go test -v ./plugin/providers/phpipam -run="TestAcc"
=== RUN TestAccDataSourcePHPIPAMAddress
--- PASS: TestAccDataSourcePHPIPAMAddress (3.00s)
=== RUN TestAccDataSourcePHPIPAMAddresses
--- PASS: TestAccDataSourcePHPIPAMAddresses (3.71s)
=== RUN TestAccDataSourcePHPIPAMFirstFreeAddress
--- PASS: TestAccDataSourcePHPIPAMFirstFreeAddress (1.52s)
=== RUN TestAccDataSourcePHPIPAMFirstFreeAddressNoFree
--- PASS: TestAccDataSourcePHPIPAMFirstFreeAddressNoFree (0.79s)
=== RUN TestAccDataSourcePHPIPAMFirstFreeSubnet
--- PASS: TestAccDataSourcePHPIPAMFirstFreeSubnet (1.30s)
=== RUN TestAccDataSourcePHPIPAMFirstFreeSubnetNoFree
--- PASS: TestAccDataSourcePHPIPAMFirstFreeSubnetNoFree (0.69s)
=== RUN TestAccDataSourcePHPIPAML2Domain
--- PASS: TestAccDataSourcePHPIPAML2Domain (1.01s)
=== RUN TestAccDataSourcePHPIPAMSection
--- PASS: TestAccDataSourcePHPIPAMSection (1.27s)
=== RUN TestAccDataSourcePHPIPAMSubnet
--- PASS: TestAccDataSourcePHPIPAMSubnet (1.62s)
=== RUN TestAccDataSourcePHPIPAMSubnet_CustomFields
--- PASS: TestAccDataSourcePHPIPAMSubnet_CustomFields (1.50s)
=== RUN TestAccDataSourcePHPIPAMSubnets
--- PASS: TestAccDataSourcePHPIPAMSubnets (2.57s)
=== RUN TestAccDataSourcePHPIPAMVLAN
--- PASS: TestAccDataSourcePHPIPAMVLAN (1.07s)
=== RUN TestAccResourcePHPIPAMAddress
--- PASS: TestAccResourcePHPIPAMAddress (1.25s)
=== RUN TestAccResourcePHPIPAMOptionalAddress
--- PASS: TestAccResourcePHPIPAMOptionalAddress (1.42s)
=== RUN TestAccResourcePHPIPAMAddress_CustomFields
--- PASS: TestAccResourcePHPIPAMAddress_CustomFields (2.26s)
=== RUN TestAccResourcePHPIPAML2Domain
--- PASS: TestAccResourcePHPIPAML2Domain (1.12s)
=== RUN TestAccResourcePHPIPAMSection
--- PASS: TestAccResourcePHPIPAMSection (1.06s)
=== RUN TestAccResourcePHPIPAMSubnet
--- PASS: TestAccResourcePHPIPAMSubnet (1.11s)
=== RUN TestAccResourcePHPIPAMSubnet_CustomFields
--- PASS: TestAccResourcePHPIPAMSubnet_CustomFields (1.95s)
=== RUN TestAccResourcePHPIPAMVLAN
--- PASS: TestAccResourcePHPIPAMVLAN (1.27s)
PASS
ok github.com/lord-kyron/terraform-provider-phpipam/plugin/providers/phpipam 31.522s
```

## Usage

Expand Down Expand Up @@ -158,7 +234,7 @@ output "address_description" {
```
data "phpipam_address" "address" {
subnet_id = 3
description_match = "Customer 1"
description = "Customer 1"
}
output "address_description" {
Expand All @@ -173,7 +249,7 @@ data "phpipam_address" "address" {
subnet_id = 3
custom_field_filter {
CustomTestAddresses = ".*terraform.*"
custom_CustomTestAddresses = ".*terraform.*"
}
}
Expand Down Expand Up @@ -207,7 +283,8 @@ source.

⚠️ **NOTE:** An empty or unspecified `custom_field_filter` value is the
equivalent to a regular expression that matches everything, and hence will
return the first address it sees in the subnet.
return the first address it sees in the subnet. Custom fileds must contain mandatory
prefix `custom_`.

Arguments are processed in the following order of precedence:

Expand Down Expand Up @@ -262,7 +339,7 @@ data "phpipam_addresses" "address_search" {
subnet_id = 3
custom_field_filter {
CustomTestAddresses = ".*terraform.*"
custom_CustomTestAddresses = ".*terraform.*"
}
}
Expand Down Expand Up @@ -297,6 +374,7 @@ One of the following fields is required alongside `subnet_id`:
⚠️ **NOTE:** An empty or unspecified `custom_field_filter` value is the
equivalent to a regular expression that matches everything, and hence will
return **all** addresses that contain the referenced custom field key!
Custom fileds must contain mandatory prefix `custom_`.

##### Attribute Reference

Expand Down Expand Up @@ -525,7 +603,7 @@ data "phpipam_subnet" "subnet" {
section_id = 1
custom_field_filter = {
CustomTestSubnets = ".*terraform.*"
custom_CustomTestSubnets = ".*terraform.*"
}
}
Expand Down Expand Up @@ -595,7 +673,8 @@ The data source takes the following parameters:
Conversely, the resource fails if it somehow finds multiple results on a CIDR
(subnet and mask) search - this is to assert that you are getting the subnet you
requested. If you want to return multiple results, combine this data source with
the `phpipam_subnets` data source.
the `phpipam_subnets` data source. Custom fileds must contain mandatory prefix
`custom_`

⚠️ **NOTE:** An empty or unspecified `custom_field_filter` value is the
equivalent to a regular expression that matches everything, and hence will
Expand Down Expand Up @@ -669,7 +748,7 @@ data "phpipam_subnets" "subnet_search" {
subnet_id = 3
custom_field_filter {
CustomTestSubnets = ".*terraform.*"
custom_CustomTestSubnets = ".*terraform.*"
}
}
Expand Down Expand Up @@ -709,6 +788,7 @@ You can find documentation for the regular expression syntax used with the
⚠️ **NOTE:** An empty or unspecified `custom_field_filter` value is the
equivalent to a regular expression that matches everything, and hence will
return **all** subnets that contain the referenced custom field key!
Custom fileds must contain mandatory prefix `custom_`.

##### Attribute Reference

Expand Down Expand Up @@ -776,6 +856,7 @@ The `phpipam_address` resource manages an IP address in PHPIPAM. You can use it
to create IP address reservations for IP addresses that have been created by
other Terraform resources, or supplied by the `phpipam_first_free_address` data
source. An example usage is below.
Custom fileds must contain mandatory prefix `custom_`.

⚠️ **NOTE:** If you are using the `phpipam_first_free_address` to get the first
free IP address in a specific subnet, make sure you set `subnet_id` and
Expand Down Expand Up @@ -807,7 +888,7 @@ resource "phpipam_address" "newip" {
description = "Managed by Terraform"
custom_fields = {
CustomTestAddresses = "terraform-test"
custom_CustomTestAddresses = "terraform-test"
}
lifecycle {
Expand Down Expand Up @@ -855,6 +936,7 @@ all fields set to optional when using this plugin. For more info see
[here](https://github.com/phpipam/phpipam/issues/1073). Further to this, either
ensure that your fields also do not have default values, or ensure the default
is set in your TF configuration. Diff loops may happen otherwise!
Custom fileds must contain mandatory prefix `custom_`.

##### Attribute Reference

Expand Down Expand Up @@ -1151,7 +1233,7 @@ resource "phpipam_subnet" "subnet" {
subnet_mask = 24
custom_fields = {
CustomTestSubnets = "terraform-test"
custom_CustomTestSubnets = "terraform-test"
}
}
```
Expand Down Expand Up @@ -1206,6 +1288,7 @@ all fields set to optional when using this plugin. For more info see
[here](https://github.com/phpipam/phpipam/issues/1073). Further to this, either
ensure that your fields also do not have default values, or ensure the default
is set in your TF configuration. Diff loops may happen otherwise!
Custom fileds must contain mandatory prefix `custom_`.

##### Attribute Reference

Expand All @@ -1232,7 +1315,7 @@ resource "phpipam_vlan" "vlan" {
description = "Managed by Terraform"
custom_fields = {
CustomTestVLANs = "terraform-test"
custom_CustomTestVLANs = "terraform-test"
}
}
```
Expand Down
43 changes: 5 additions & 38 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,25 @@ module github.com/lord-kyron/terraform-provider-phpipam
go 1.20

require (
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/pavel-z1/phpipam-sdk-go v0.1.5
github.com/pavel-z1/phpipam-sdk-go v0.1.7
)

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.19.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.1 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apex/log v1.9.0 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.37.0 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-getter v1.5.3 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.9 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.5.1 // indirect
Expand All @@ -54,40 +34,27 @@ require (
github.com/hashicorp/terraform-registry-address v0.2.0 // indirect
github.com/hashicorp/terraform-svchost v0.1.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.11.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mitchellh/cli v1.1.5 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/posener/complete v1.2.1 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
github.com/zclconf/go-cty-yaml v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.114.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.54.0 // indirect
Expand Down
Loading

0 comments on commit 892b73e

Please sign in to comment.