Skip to content

Commit ff2f428

Browse files
authored
[DDIA-308] Assign Service Instance in DHCP Config Profile (#121)
* Added DHCP Hosts resource config * Added support for retry and timeouts * Added a new schema * Resolved lint errors * Fixed tag issue * Implemented the review changes * Formatting changes * Updated Example * Fixed issues * Reverted changes in data source schema * Generated docs
1 parent 382697d commit ff2f428

File tree

11 files changed

+1385
-821
lines changed

11 files changed

+1385
-821
lines changed

docs/resources/dhcp_host.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "bloxone_dhcp_host Resource - terraform-provider-bloxone"
4+
subcategory: "IPAM/DHCP"
5+
description: |-
6+
Manages DHCP Hosts.
7+
A DHCP Host object associates a DHCP Config Profile with an on-prem host.
8+
Note: This resource represents an existing backend object that cannot be created or deleted through API calls. Instead, it can only be updated. When using terraform apply the resource configuration is applied to the existing object, and no new object is created. Similarly terraform destroy removes the configuration associated with the object without actually deleting it from the backend.
9+
---
10+
11+
# bloxone_dhcp_host (Resource)
12+
13+
Manages DHCP Hosts.
14+
15+
A DHCP Host object associates a DHCP Config Profile with an on-prem host.
16+
17+
Note: This resource represents an existing backend object that cannot be created or deleted through API calls. Instead, it can only be updated. When using terraform apply the resource configuration is applied to the existing object, and no new object is created. Similarly terraform destroy removes the configuration associated with the object without actually deleting it from the backend.
18+
19+
## Example Usage
20+
21+
```terraform
22+
data "bloxone_infra_hosts" "host" {
23+
filters = {
24+
display_name = "my-host"
25+
}
26+
}
27+
28+
resource "bloxone_dhcp_server" "dhcp_server" {
29+
name = "my-dhcp-server"
30+
}
31+
32+
resource "bloxone_dhcp_host" "example_dhcp_host" {
33+
id = data.bloxone_infra_hosts.host.results.0.legacy_id
34+
server = bloxone_dhcp_server.dhcp_server.id
35+
}
36+
```
37+
38+
<!-- schema generated by tfplugindocs -->
39+
## Schema
40+
41+
### Required
42+
43+
- `id` (String) The resource identifier.
44+
- `server` (String) The resource identifier.
45+
46+
### Optional
47+
48+
- `retry_if_not_found` (Boolean) If set to `true`, the resource will retry until a matching host is found, or until the Create Timeout expires.
49+
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
50+
51+
### Read-Only
52+
53+
- `address` (String) The primary IP address of the on-prem host.
54+
- `anycast_addresses` (List of String) Anycast address configured to the host. Order is not significant.
55+
- `associated_server` (Attributes) The DHCP Config Profile for the on-prem host. (see [below for nested schema](#nestedatt--associated_server))
56+
- `comment` (String) The description for the on-prem host.
57+
- `current_version` (String) Current dhcp application version of the host.
58+
- `ip_space` (String) The resource identifier.
59+
- `name` (String) The display name of the on-prem host.
60+
- `ophid` (String) The on-prem host ID.
61+
- `provider_id` (String) External provider identifier.
62+
- `tags` (Map of String) The tags of the on-prem host in JSON format.
63+
- `tags_all` (Map of String) The tags of the on-prem host in JSON format including default tags.
64+
- `type` (String) Defines the type of host. Allowed values: * _bloxone_ddi_: host type is BloxOne DDI, * _microsoft_azure_: host type is Microsoft Azure, * _amazon_web_service_: host type is Amazon Web Services. * _microsoft_active_directory_: host type is Microsoft Active Directory.
65+
66+
<a id="nestedblock--timeouts"></a>
67+
### Nested Schema for `timeouts`
68+
69+
Optional:
70+
71+
- `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).
72+
73+
74+
<a id="nestedatt--associated_server"></a>
75+
### Nested Schema for `associated_server`
76+
77+
Read-Only:
78+
79+
- `id` (String) The resource identifier.
80+
- `name` (String) The DHCP Config Profile name.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
data "bloxone_infra_hosts" "host" {
2+
filters = {
3+
display_name = "my-host"
4+
}
5+
}
6+
7+
resource "bloxone_dhcp_server" "dhcp_server" {
8+
name = "my-dhcp-server"
9+
}
10+
11+
resource "bloxone_dhcp_host" "example_dhcp_host" {
12+
id = data.bloxone_infra_hosts.host.results.0.legacy_id
13+
server = bloxone_dhcp_server.dhcp_server.id
14+
}

internal/acctest/acctest.go

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,86 @@
11
package acctest
22

33
import (
4-
"fmt"
5-
"math/rand"
6-
"os"
7-
"testing"
4+
"fmt"
5+
"math/rand"
6+
"os"
7+
"testing"
88

9-
"github.com/hashicorp/terraform-plugin-framework/providerserver"
10-
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
11-
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-framework/providerserver"
10+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
11+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1212

13-
bloxoneclient "github.com/infobloxopen/bloxone-go-client/client"
14-
"github.com/infobloxopen/bloxone-go-client/option"
15-
"github.com/infobloxopen/terraform-provider-bloxone/internal/provider"
13+
bloxoneclient "github.com/infobloxopen/bloxone-go-client/client"
14+
"github.com/infobloxopen/bloxone-go-client/option"
15+
"github.com/infobloxopen/terraform-provider-bloxone/internal/provider"
1616
)
1717

1818
const (
19-
letterBytes = "abcdefghijklmnopqrstuvwxyz"
20-
defaultKey = "managed_by"
21-
defaultValue = "terraform"
19+
letterBytes = "abcdefghijklmnopqrstuvwxyz"
20+
defaultKey = "managed_by"
21+
defaultValue = "terraform"
2222
)
2323

2424
var (
25-
// BloxOneClient will be used to do verification tests
26-
BloxOneClient *bloxoneclient.APIClient
25+
// BloxOneClient will be used to do verification tests
26+
BloxOneClient *bloxoneclient.APIClient
2727

28-
// ProtoV6ProviderFactories are used to instantiate a provider during
29-
// acceptance testing. The factory function will be invoked for every Terraform
30-
// CLI command executed to create a provider server to which the CLI can
31-
// reattach.
32-
ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
33-
"bloxone": providerserver.NewProtocol6WithError(provider.New("test", "test")()),
34-
}
35-
ProtoV6ProviderFactoriesWithTags = map[string]func() (tfprotov6.ProviderServer, error){
36-
"bloxone": providerserver.NewProtocol6WithError(provider.NewWithTags(map[string]string{defaultKey: defaultValue})()),
37-
}
28+
// ProtoV6ProviderFactories are used to instantiate a provider during
29+
// acceptance testing. The factory function will be invoked for every Terraform
30+
// CLI command executed to create a provider server to which the CLI can
31+
// reattach.
32+
ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
33+
"bloxone": providerserver.NewProtocol6WithError(provider.New("test", "test")()),
34+
}
35+
ProtoV6ProviderFactoriesWithTags = map[string]func() (tfprotov6.ProviderServer, error){
36+
"bloxone": providerserver.NewProtocol6WithError(provider.NewWithTags(map[string]string{defaultKey: defaultValue})()),
37+
}
3838
)
3939

4040
// RandomNameWithPrefix generates a random name with the given prefix.
4141
// This is used in the acceptance tests where a unique name is required for the resource.
4242
func RandomNameWithPrefix(prefix string) string {
43-
return fmt.Sprintf("%s-%s", prefix, RandomName())
43+
return fmt.Sprintf("%s-%s", prefix, RandomName())
4444
}
4545

4646
func RandomIP() string {
47-
return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255))
47+
return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255))
4848
}
4949

5050
func RandomName() string {
51-
b := make([]byte, 6)
52-
for i := range b {
53-
b[i] = letterBytes[rand.Intn(len(letterBytes))]
54-
}
55-
return string(b)
51+
b := make([]byte, 6)
52+
for i := range b {
53+
b[i] = letterBytes[rand.Intn(len(letterBytes))]
54+
}
55+
return string(b)
5656
}
5757

5858
func PreCheck(t *testing.T) {
59-
cspURL := os.Getenv("BLOXONE_CSP_URL")
60-
if cspURL == "" {
61-
t.Fatal("BLOXONE_CSP_URL must be set for acceptance tests")
62-
}
59+
cspURL := os.Getenv("BLOXONE_CSP_URL")
60+
if cspURL == "" {
61+
t.Fatal("BLOXONE_CSP_URL must be set for acceptance tests")
62+
}
6363

64-
apiKey := os.Getenv("BLOXONE_API_KEY")
65-
if apiKey == "" {
66-
t.Fatal("BLOXONE_API_KEY must be set for acceptance tests")
67-
}
64+
apiKey := os.Getenv("BLOXONE_API_KEY")
65+
if apiKey == "" {
66+
t.Fatal("BLOXONE_API_KEY must be set for acceptance tests")
67+
}
6868

69-
BloxOneClient = bloxoneclient.NewAPIClient(
70-
option.WithClientName("terraform-acceptance-tests"),
71-
option.WithCSPUrl(cspURL),
72-
option.WithAPIKey(apiKey),
73-
option.WithDebug(true),
74-
)
69+
BloxOneClient = bloxoneclient.NewAPIClient(
70+
option.WithClientName("terraform-acceptance-tests"),
71+
option.WithCSPUrl(cspURL),
72+
option.WithAPIKey(apiKey),
73+
option.WithDebug(true),
74+
)
7575
}
7676

7777
func VerifyDefaultTag(resourceName string) resource.TestCheckFunc {
78-
return resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("tags_all.%s", defaultKey), defaultValue)
78+
return resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("tags_all.%s", defaultKey), defaultValue)
7979
}
8080

8181
// TestAccBase_DhcpHosts creates a Terraform datasource config that allows you to filter by tags
8282
func TestAccBase_DhcpHosts() string {
83-
return `
83+
return `
8484
data "bloxone_dhcp_hosts" "test" {
8585
tag_filters = {
8686
used_for = "Terraform Provider Acceptance Tests"

0 commit comments

Comments
 (0)