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

[DDIA-308] Assign Service Instance in DHCP Config Profile #121

Merged
merged 13 commits into from
Jun 17, 2024
10 changes: 5 additions & 5 deletions docs/data-sources/dhcp_hosts.md
Copy link
Collaborator

Choose a reason for hiding this comment

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

nothing should have changed for this, since you separated the models.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ Optional:
<a id="nestedatt--results"></a>
### Nested Schema for `results`

Optional:
Required:

- `associated_server` (Attributes) The DHCP Config Profile for the on-prem host. (see [below for nested schema](#nestedatt--results--associated_server))
- `ip_space` (String) The resource identifier.
- `id` (String) The resource identifier.
- `server` (String) The resource identifier.
- `tags` (Map of String) The tags of the on-prem host in JSON format.

Read-Only:

- `address` (String) The primary IP address of the on-prem host.
- `anycast_addresses` (List of String) Anycast address configured to the host. Order is not significant.
- `associated_server` (Attributes) The DHCP Config Profile for the on-prem host. (see [below for nested schema](#nestedatt--results--associated_server))
- `comment` (String) The description for the on-prem host.
- `current_version` (String) Current dhcp application version of the host.
- `id` (String) The resource identifier.
- `ip_space` (String) The resource identifier.
- `name` (String) The display name of the on-prem host.
- `ophid` (String) The on-prem host ID.
- `provider_id` (String) External provider identifier.
- `tags` (Map of String) The tags of the on-prem host in JSON format.
- `tags_all` (Map of String) The tags of the on-prem host in JSON format including default tags.
- `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.

Expand Down
80 changes: 80 additions & 0 deletions docs/resources/dhcp_host.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bloxone_dhcp_host Resource - terraform-provider-bloxone"
subcategory: "IPAM/DHCP"
description: |-
Manages DHCP Hosts.
A DHCP Host object associates a DHCP Config Profile with an on-prem host.
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.
---

# bloxone_dhcp_host (Resource)

Manages DHCP Hosts.

A DHCP Host object associates a DHCP Config Profile with an on-prem host.

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.

## Example Usage

```terraform
data "bloxone_infra_hosts" "host" {
filters = {
display_name = "my-host"
}
}

resource "bloxone_dhcp_server" "dhcp_server" {
name = "my-dhcp-server"
}

resource "bloxone_dhcp_host" "example_dhcp_host" {
id = data.bloxone_infra_hosts.host.results.0.legacy_id
server = bloxone_dhcp_server.dhcp_server.id
}
```

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

### Required

- `id` (String) The resource identifier.
- `server` (String) The resource identifier.

### Optional

- `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.
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-Only

- `address` (String) The primary IP address of the on-prem host.
- `anycast_addresses` (List of String) Anycast address configured to the host. Order is not significant.
- `associated_server` (Attributes) The DHCP Config Profile for the on-prem host. (see [below for nested schema](#nestedatt--associated_server))
- `comment` (String) The description for the on-prem host.
- `current_version` (String) Current dhcp application version of the host.
- `ip_space` (String) The resource identifier.
- `name` (String) The display name of the on-prem host.
- `ophid` (String) The on-prem host ID.
- `provider_id` (String) External provider identifier.
- `tags` (Map of String) The tags of the on-prem host in JSON format.
- `tags_all` (Map of String) The tags of the on-prem host in JSON format including default tags.
- `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.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `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).


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

Read-Only:

- `id` (String) The resource identifier.
- `name` (String) The DHCP Config Profile name.
14 changes: 14 additions & 0 deletions examples/resources/bloxone_dhcp_host/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
data "bloxone_infra_hosts" "host" {
filters = {
display_name = "my-host"
}
}

resource "bloxone_dhcp_server" "dhcp_server" {
name = "my-dhcp-server"
}

resource "bloxone_dhcp_host" "example_dhcp_host" {
id = data.bloxone_infra_hosts.host.results.0.legacy_id
server = bloxone_dhcp_server.dhcp_server.id
}
96 changes: 48 additions & 48 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
package acctest

import (
"fmt"
"math/rand"
"os"
"testing"
"fmt"
"math/rand"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"

bloxoneclient "github.com/infobloxopen/bloxone-go-client/client"
"github.com/infobloxopen/bloxone-go-client/option"
"github.com/infobloxopen/terraform-provider-bloxone/internal/provider"
bloxoneclient "github.com/infobloxopen/bloxone-go-client/client"
"github.com/infobloxopen/bloxone-go-client/option"
"github.com/infobloxopen/terraform-provider-bloxone/internal/provider"
)

const (
letterBytes = "abcdefghijklmnopqrstuvwxyz"
defaultKey = "managed_by"
defaultValue = "terraform"
letterBytes = "abcdefghijklmnopqrstuvwxyz"
defaultKey = "managed_by"
defaultValue = "terraform"
)

var (
// BloxOneClient will be used to do verification tests
BloxOneClient *bloxoneclient.APIClient
// BloxOneClient will be used to do verification tests
BloxOneClient *bloxoneclient.APIClient

// ProtoV6ProviderFactories are used to instantiate a provider during
// acceptance testing. The factory function will be invoked for every Terraform
// CLI command executed to create a provider server to which the CLI can
// reattach.
ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"bloxone": providerserver.NewProtocol6WithError(provider.New("test", "test")()),
}
ProtoV6ProviderFactoriesWithTags = map[string]func() (tfprotov6.ProviderServer, error){
"bloxone": providerserver.NewProtocol6WithError(provider.NewWithTags(map[string]string{defaultKey: defaultValue})()),
}
// ProtoV6ProviderFactories are used to instantiate a provider during
// acceptance testing. The factory function will be invoked for every Terraform
// CLI command executed to create a provider server to which the CLI can
// reattach.
ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"bloxone": providerserver.NewProtocol6WithError(provider.New("test", "test")()),
}
ProtoV6ProviderFactoriesWithTags = map[string]func() (tfprotov6.ProviderServer, error){
"bloxone": providerserver.NewProtocol6WithError(provider.NewWithTags(map[string]string{defaultKey: defaultValue})()),
}
)

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

func RandomIP() string {
return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255))
return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255))
}

func RandomName() string {
b := make([]byte, 6)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
b := make([]byte, 6)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}

func PreCheck(t *testing.T) {
cspURL := os.Getenv("BLOXONE_CSP_URL")
if cspURL == "" {
t.Fatal("BLOXONE_CSP_URL must be set for acceptance tests")
}
cspURL := os.Getenv("BLOXONE_CSP_URL")
if cspURL == "" {
t.Fatal("BLOXONE_CSP_URL must be set for acceptance tests")
}

apiKey := os.Getenv("BLOXONE_API_KEY")
if apiKey == "" {
t.Fatal("BLOXONE_API_KEY must be set for acceptance tests")
}
apiKey := os.Getenv("BLOXONE_API_KEY")
if apiKey == "" {
t.Fatal("BLOXONE_API_KEY must be set for acceptance tests")
}

BloxOneClient = bloxoneclient.NewAPIClient(
option.WithClientName("terraform-acceptance-tests"),
option.WithCSPUrl(cspURL),
option.WithAPIKey(apiKey),
option.WithDebug(true),
)
BloxOneClient = bloxoneclient.NewAPIClient(
option.WithClientName("terraform-acceptance-tests"),
option.WithCSPUrl(cspURL),
option.WithAPIKey(apiKey),
option.WithDebug(true),
)
}

func VerifyDefaultTag(resourceName string) resource.TestCheckFunc {
return resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("tags_all.%s", defaultKey), defaultValue)
return resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("tags_all.%s", defaultKey), defaultValue)
}

// TestAccBase_DhcpHosts creates a Terraform datasource config that allows you to filter by tags
func TestAccBase_DhcpHosts() string {
return `
return `
data "bloxone_dhcp_hosts" "test" {
tag_filters = {
used_for = "Terraform Provider Acceptance Tests"
Expand Down
Loading
Loading