Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nest custom fields (subnets) #86

Merged
merged 3 commits into from
May 15, 2024
Merged

Conversation

d-costa
Copy link
Contributor

@d-costa d-costa commented Feb 22, 2024

What

Use nested custom fields SDK feature for subnet resources.

  • Add optional provider-level boolean config nest_custom_fields. Defaults to false (opt-in).
  • Based on this flag, the provider will send custom fields nested within the subnet
  • This optimization is implemented for both resource_phpipam_first_free_subnet and resource_phpipam_subnet resources, but the same methodology can be applied for VLAN and Address resources
  • Had to change some expected 404 error message in VLANs and subnet tests

Why

  • This allows the provider to only make one API call when creating subnets, making use of the nested custom fields feature.
  • Resource creation should be faster, and lead to less application logs in phpIPAM

Ref

Tests

Its behavior is described in the table below:

TF nest_custom_values API nest_custom_values Apply result
false false Success. Same behavior as before (2 calls)
true true Success. Only one API call
true false Fails. API rejects the request and no subnet is created [1]
false true Success, but still does 2 calls. Shows a warning [2]

[1]
306611715-9e10a67

[2]
306614122-a86f4-55a0a6802924

Unit tests

make test
Output

go test -v github.com/lord-kyron/terraform-provider-phpipam github.com/lord-kyron/terraform-provider-phpipam/plugin/providers/phpipam 
=== RUN   TestPluginVersion
--- PASS: TestPluginVersion (0.00s)
PASS
ok      github.com/lord-kyron/terraform-provider-phpipam        0.008s
=== RUN   TestAccDataSourcePHPIPAMAddress
    data_source_phpipam_address_test.go:116: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMAddress (0.00s)
=== RUN   TestAccDataSourcePHPIPAMAddresses
    data_source_phpipam_addresses_test.go:86: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMAddresses (0.00s)
=== RUN   TestAccDataSourcePHPIPAMFirstFreeAddress
    data_source_phpipam_first_free_address_test.go:68: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMFirstFreeAddress (0.00s)
=== RUN   TestAccDataSourcePHPIPAMFirstFreeAddressNoFree
    data_source_phpipam_first_free_address_test.go:86: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMFirstFreeAddressNoFree (0.00s)
=== RUN   TestAccDataSourcePHPIPAMFirstFreeSubnet
    data_source_phpipam_first_free_subnet_test.go:70: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMFirstFreeSubnet (0.00s)
=== RUN   TestAccDataSourcePHPIPAMFirstFreeSubnetNoFree
    data_source_phpipam_first_free_subnet_test.go:88: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMFirstFreeSubnetNoFree (0.00s)
=== RUN   TestAccDataSourcePHPIPAML2Domain
    data_source_phpipam_l2domain_test.go:27: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAML2Domain (0.00s)
=== RUN   TestAccDataSourcePHPIPAMSection
    data_source_phpipam_section_test.go:27: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMSection (0.00s)
=== RUN   TestAccDataSourcePHPIPAMSubnet
    data_source_phpipam_subnet_test.go:85: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMSubnet (0.00s)
=== RUN   TestAccDataSourcePHPIPAMSubnet_CustomFields
    data_source_phpipam_subnet_test.go:108: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMSubnet_CustomFields (0.00s)
=== RUN   TestAccDataSourcePHPIPAMSubnets
    data_source_phpipam_subnets_test.go:77: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMSubnets (0.00s)
=== RUN   TestAccDataSourcePHPIPAMVLAN
    data_source_phpipam_vlan_test.go:36: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccDataSourcePHPIPAMVLAN (0.00s)
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestAccResourcePHPIPAMAddress
    resource_phpipam_address_test.go:107: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccResourcePHPIPAMAddress (0.00s)
=== RUN   TestAccResourcePHPIPAMOptionalAddress
    resource_phpipam_address_test.go:129: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccResourcePHPIPAMOptionalAddress (0.00s)
=== RUN   TestAccResourcePHPIPAMAddress_CustomFields
    resource_phpipam_address_test.go:150: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccResourcePHPIPAMAddress_CustomFields (0.00s)
=== RUN   TestAccResourcePHPIPAML2Domain
    resource_phpipam_l2domain_test.go:23: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccResourcePHPIPAML2Domain (0.00s)
=== RUN   TestAccResourcePHPIPAMSection
    resource_phpipam_section_test.go:23: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccResourcePHPIPAMSection (0.00s)
=== RUN   TestAccResourcePHPIPAMSubnet
    resource_phpipam_subnet_test.go:69: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccResourcePHPIPAMSubnet (0.00s)
=== RUN   TestAccResourcePHPIPAMSubnet_CustomFields
    resource_phpipam_subnet_test.go:91: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccResourcePHPIPAMSubnet_CustomFields (0.00s)
=== RUN   TestAccResourcePHPIPAMVLAN
    resource_phpipam_vlan_test.go:61: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccResourcePHPIPAMVLAN (0.00s)
PASS
ok      github.com/lord-kyron/terraform-provider-phpipam/plugin/providers/phpipam       0.007s

Acceptance tests (Nest custom fields = no)

make testacc
Details

go clean -testcache; TF_ACC=1 go test -v ./plugin/providers/phpipam -run="TestAcc"
=== RUN   TestAccDataSourcePHPIPAMAddress
--- PASS: TestAccDataSourcePHPIPAMAddress (12.79s)
=== RUN   TestAccDataSourcePHPIPAMAddresses
--- PASS: TestAccDataSourcePHPIPAMAddresses (10.07s)
=== RUN   TestAccDataSourcePHPIPAMFirstFreeAddress
--- PASS: TestAccDataSourcePHPIPAMFirstFreeAddress (2.96s)
=== RUN   TestAccDataSourcePHPIPAMFirstFreeAddressNoFree
--- PASS: TestAccDataSourcePHPIPAMFirstFreeAddressNoFree (1.80s)
=== RUN   TestAccDataSourcePHPIPAMFirstFreeSubnet
--- PASS: TestAccDataSourcePHPIPAMFirstFreeSubnet (2.93s)
=== RUN   TestAccDataSourcePHPIPAMFirstFreeSubnetNoFree
--- PASS: TestAccDataSourcePHPIPAMFirstFreeSubnetNoFree (1.69s)
=== RUN   TestAccDataSourcePHPIPAML2Domain
--- PASS: TestAccDataSourcePHPIPAML2Domain (1.96s)
=== RUN   TestAccDataSourcePHPIPAMSection
--- PASS: TestAccDataSourcePHPIPAMSection (1.96s)
=== RUN   TestAccDataSourcePHPIPAMSubnet
--- PASS: TestAccDataSourcePHPIPAMSubnet (4.65s)
=== RUN   TestAccDataSourcePHPIPAMSubnet_CustomFields
--- PASS: TestAccDataSourcePHPIPAMSubnet_CustomFields (3.16s)
=== RUN   TestAccDataSourcePHPIPAMSubnets
--- PASS: TestAccDataSourcePHPIPAMSubnets (6.36s)
=== RUN   TestAccDataSourcePHPIPAMVLAN
--- PASS: TestAccDataSourcePHPIPAMVLAN (3.27s)
=== RUN   TestAccResourcePHPIPAMAddress
--- PASS: TestAccResourcePHPIPAMAddress (2.73s)
=== RUN   TestAccResourcePHPIPAMOptionalAddress
--- PASS: TestAccResourcePHPIPAMOptionalAddress (2.57s)
=== RUN   TestAccResourcePHPIPAMAddress_CustomFields
--- PASS: TestAccResourcePHPIPAMAddress_CustomFields (4.81s)
=== RUN   TestAccResourcePHPIPAML2Domain
--- PASS: TestAccResourcePHPIPAML2Domain (1.58s)
=== RUN   TestAccResourcePHPIPAMSection
--- PASS: TestAccResourcePHPIPAMSection (1.51s)
=== RUN   TestAccResourcePHPIPAMSubnet
--- PASS: TestAccResourcePHPIPAMSubnet (2.09s)
=== RUN   TestAccResourcePHPIPAMSubnet_CustomFields
--- PASS: TestAccResourcePHPIPAMSubnet_CustomFields (3.98s)
=== RUN   TestAccResourcePHPIPAMVLAN
--- PASS: TestAccResourcePHPIPAMVLAN (2.16s)
PASS
ok      github.com/lord-kyron/terraform-provider-phpipam/plugin/providers/phpipam       75.041s

@lord-kyron lord-kyron requested a review from pavel-z1 February 23, 2024 10:54
@d-costa d-costa changed the title Support nest custom fields support (subnets) Use nest custom fields (subnets) Feb 26, 2024
@dgteixeira
Copy link

@lord-kyron , @pavel-z1 any updates on this ?
We need these changes and didn’t want to create a new fork of this provider just to use this feature.

@pavel-z1 pavel-z1 self-assigned this Mar 25, 2024
@pavel-z1
Copy link
Collaborator

Hi @d-costa
Thank you for your hard work!

Please, add information about optional config parameter nest_custom_fields to the docs/index.md

After this the PR will be approved.

Maybe you can add nested custom fields support to the address and vlans too?

@pavel-z1
Copy link
Collaborator

@d-costa can you fix description to move forward with PR?

@pavel-z1
Copy link
Collaborator

@d-costa can you please update description?
We waiting for this update to merge this PR and move forward with next PRs

@d-costa
Copy link
Contributor Author

d-costa commented Apr 19, 2024

hey @pavel-z1, sorry for the delay. I've updated docs/index.md; let me know if you have any more requests

@nullck
Copy link

nullck commented May 8, 2024

Hello @pavel-z1, please, I'm waiting for this feature and the following quick fix: #88

It would be awesome to have it implemented.

docs/index.md Outdated
@@ -109,6 +109,9 @@ The options for the plugin are as follows:
supplied via the `PHPIPAM_USER_NAME` variable.
- `insecure` - Set to true to not validate the HTTPS certificate chain.
Optional parameter, can be used only with HTTPS connections
- `nest_custom_fields` - Set to true if your PHPIPAM application has the nested
custom fields feature enabled. ptional parameter, currently only affects
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo
Please correct it to Optional parameter

@pavel-z1 pavel-z1 merged commit e8e7cb6 into lord-kyron:master May 15, 2024
@pavel-z1
Copy link
Collaborator

@d-costa Thank you for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set custom fields directly on subnet creation
4 participants