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

Add quickstart guide for DHCP #68

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ testacc:

gen:
go generate
terraform-docs ./modules/bloxone_infra_host_aws
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
terraform-docs ./modules/bloxone_infra_host_aws
terraform-docs ./modules/

Copy link
Collaborator

Choose a reason for hiding this comment

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

To support future modules(GCP, Azure)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't work. The terraform-docs requires the proper directory and does not recursively figure out the sub directories

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tried it, still doesn't work correctly. That works only for child modules. Our directory structure is a bit different.


.PHONY: default test testacc gen
96 changes: 55 additions & 41 deletions docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ The resource types have changed in the new provider. The following table shows t
| b1ddi_dns_auth_nsg | bloxone_dns_auth_nsg |
| b1ddi_dns_record | bloxone_dns_record* |

> NOTE: The _b1ddi_dns_record_ in the B1DDI provider used to be a single resource type that could be used to create any type of DNS record.
> In the BloxOne provider, this has been split into multiple resource types, one for each record type.
> For example, _b1ddi_dns_record_ is now _bloxone_dns_a_record_, _bloxone_dns_aaaa_record_, _bloxone_dns_caa_record_, etc.
>
> The _bloxone_dns_record_ is for resource records that are not supported explicitly by the provider. For example, if you want to create a DNS record of type _URI_, you can use _bloxone_dns_record_.
-> NOTE: The _b1ddi_dns_record_ in the B1DDI provider used to be a single resource type that could be used to create any type of DNS record.
In the BloxOne provider, this has been split into multiple resource types, one for each record type.
For example, _b1ddi_dns_record_ is now _bloxone_dns_a_record_, _bloxone_dns_aaaa_record_, _bloxone_dns_caa_record_, etc. <br>
The _bloxone_dns_record_ is for resource records that are not supported explicitly by the provider.
For example, if you want to create a DNS record of type _URI_, you can use _bloxone_dns_record_.

To migrate your configuration, you will need to replace the old resource types with the new resource types. For example:

Expand Down Expand Up @@ -119,39 +119,53 @@ There should be no changes to your infrastructure if you have replaced all the r

In case there are changes, you will need to make the necessary changes to your configuration to match the new provider.
Some of the changes you may need to make are listed below.
- **Unsupported block type**: Configuration written as blocks will have to be rewritten as values. For example, if you have a block like this:
```terraform
internal_secondaries {
host = "dns/host/989a0d20-c030-11ee-a93d-0b6e6ea305e3"
}
```
you will have to rewrite it with an equal sign :
```terraform
internal_secondaries = [
{
host = "dns/host/989a0d20-c030-11ee-a93d-0b6e6ea305e3"
}
]
```
- **Read Only attributes**: Some attributes are read only in the BloxOne provider. For example, the _type_ attribute in _bloxone_dns_a_record_ is read only. If you have a configuration like this:
```terraform
resource "bloxone_dns_a_record" "example" {
name = "domain.com"
type = "A"
}
```
you will have to remove _type_ from the config as it is read only.
- **Default values**: Some default values may have changed in the new provider. For example, the _hostname_rewrite_regex_ attribute in _bloxone_dns_forward_nsg_ has been changed from `[^a-zA-Z0-9.-]` to `[^a-zA-Z0-9_.]`.
If your configuration, like the one below, doesn't specify a value for _hostname_rewrite_regex_:
```terraform
resource "bloxone_dns_forward_nsg" "example" {
name = "example"
}
```
you'll need to add a _hostname_rewrite_regex_ value to your configuration. This value should match the existing or old default value, otherwise, the plan will indicate a change.
```terraform
resource "bloxone_dns_forward_nsg" "example" {
name = "example"
hostname_rewrite_regex = "[^a-zA-Z0-9.-]"
}
```

#### Unsupported block type
Configuration written as blocks will have to be rewritten as values. For example, if you have a block like this:
```terraform
internal_secondaries {
host = "dns/host/989a0d20-c030-11ee-a93d-0b6e6ea305e3"
}
```
you will have to rewrite it with an equal sign :
```terraform
internal_secondaries = [
{
host = "dns/host/989a0d20-c030-11ee-a93d-0b6e6ea305e3"
}
]
```

#### Read Only attributes
Some attributes are read only in the BloxOne provider. For example, the _type_ attribute in _bloxone_dns_a_record_ is read only.

If you have a configuration like this:
```terraform
resource "bloxone_dns_a_record" "example" {
name = "domain.com"
type = "A"
}
```
you will have to remove _type_ from the config as it is read only:
```terraform
resource "bloxone_dns_a_record" "example" {
name = "domain.com"
}
```

#### Default values
Some default values may have changed in the new provider. For example, the _hostname_rewrite_regex_ attribute in _bloxone_dns_forward_nsg_ has been changed from `[^a-zA-Z0-9.-]` to `[^a-zA-Z0-9_.]`.

If your configuration, like the one below, doesn't specify a value for _hostname_rewrite_regex_:
```terraform
resource "bloxone_dns_forward_nsg" "example" {
name = "example"
}
```
you will need to add a _hostname_rewrite_regex_ value to your configuration. This value should match the existing or old default value, otherwise, the plan will indicate a change.
```terraform
resource "bloxone_dns_forward_nsg" "example" {
name = "example"
hostname_rewrite_regex = "[^a-zA-Z0-9.-]"
}
```
238 changes: 238 additions & 0 deletions docs/guides/quickstart-dhcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
---
page_title: "Managing DHCP service with the BloxOne Terraform Provider"
subcategory: "Guides"
description: |-
This guide provides step-by-step instructions for using the BloxOne Terraform Provider to manage IPAM and DHCP resources.
---

# Managing DHCP service with the BloxOne Terraform Provider

This guide provides step-by-step instructions for using the BloxOne Terraform Provider to manage IPAM and DHCP resources.

## Configuring the Provider

The provider needs to be configured with an API key and the URL of the Infoblox Cloud Services Portal (CSP). You can get the API Key from the Infoblox Cloud Services Portal (CSP) by following the steps outlined in this guide - [Configuring User API Keys](https://docs.infoblox.com/space/BloxOneCloud/35430405/Configuring+User+API+Keys).

Create a directory for the Terraform configuration and create a file named `main.tf` with the following content:

````terraform
terraform {
required_providers {
bloxone = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should mention the terraform client version has to be >= 1.0.0.
Why do we want the provider version to 0.1.X? We are planning to release 1.0.0 and this wouldn't allow that. See: https://developer.hashicorp.com/terraform/tutorials/configuration-language/versions#review-example-configuration

source = "infobloxopen/bloxone"
version = ">= 0.1.0"
}
}

required_version = ">= 1.0.0"
}

provider "bloxone" {
csp_url = "https://csp.infoblox.com"
api_key = "<BloxOne API Key>"
}
````

!> Warning: Hard-coded credentials are not recommended in any configuration file. It is recommended to use environment variables.

You can also use the following environment variables to configure the provider:
`BLOXONE_CSP_URL` and `BLOXONE_API_KEY`.

Initialize the provider by running the following command. This will download the provider and initialize the working directory.

```shell
terraform init
```

## Configuring Resources

### IPAM and DHCP Resources
In this example, you will use the following resources to create an IP space, address block, and subnet.

- [bloxone_ipam_ip_space](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/ipam_ip_space)
- [bloxone_ipam_address_block](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/ipam_address_block)
- [bloxone_ipam_subnet](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/ipam_subnet)

Add the following to the `main.tf` file:

````terraform
// Create an IP space
resource "bloxone_ipam_ip_space" "this" {
name = "example"
}

// Create an address block within the IP space
resource "bloxone_ipam_address_block" "this" {
space = bloxone_ipam_ip_space.this.id
address = "10.0.0.0"
cidr = "16"
}

// Create a subnet within the address block
resource "bloxone_ipam_subnet" "this" {
space = bloxone_ipam_ip_space.this.id
address = "10.0.0.0"
cidr = "24"
}

````

You can now run `terraform plan` to see what resources will be created.

```shell
terraform plan
```

Further, you will create a range and a fixed address reservation within the subnet.

You will use the following resources to create these
- [bloxone_ipam_range](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/ipam_range)
- [bloxone_dhcp_fixed_address](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/dhcp_fixed_address)

You will use the following data sources to get the option codes in the default DHCPv4 option space
- [bloxone_dhcp_option_spaces](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/data-sources/dhcp_option_spaces)
- [bloxone_dhcp_option_codes](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/data-sources/dhcp_option_codes)

Add the following code to your main.tf:

````terraform
// Get the default option space for DHCPv4
data "bloxone_dhcp_option_spaces" "dhcp4" {
filters = {
name = "dhcp4"
}
}

// Get the option codes for the default option space
data "bloxone_dhcp_option_codes" "dhcp4" {
filters = {
option_space = data.bloxone_dhcp_option_spaces.dhcp4.results.0.id
}
}

locals {
// Create a map of option code names to option code IDs
// This will be used to look up the option code ID by name
dhcp4_option_code_lookup = zipmap(data.bloxone_dhcp_option_codes.dhcp4.results[*].name, data.bloxone_dhcp_option_codes.dhcp4.results[*].id)
}

// Create a range within the subnet
resource "bloxone_ipam_range" "this" {
space = bloxone_ipam_ip_space.this.id
start = "10.0.0.5"
end = "10.0.0.100"
dhcp_options = [
{
option_code = local.dhcp4_option_code_lookup["domain-name-servers"]
option_value = "10.0.0.1"
type = "option"
},
{
option_code = local.dhcp4_option_code_lookup["domain-name"]
option_value = "domain.com"
type = "option"
}
]

depends_on = [bloxone_ipam_subnet.this]
}

// Create a Fixed Address within the subnet
resource "bloxone_dhcp_fixed_address" "this" {
ip_space = bloxone_ipam_ip_space.this.id
address = "10.0.0.6"
match_type = "mac"
match_value = "00:11:22:33:44:55"
dhcp_options = [
{
option_code = local.dhcp4_option_code_lookup["time-offset"]
option_value = "-5"
type = "option"
}
]

depends_on = [bloxone_ipam_subnet.this]
}
````

You can now run `terraform plan` to see what resources will be created.

```shell
terraform plan
```

### BloxOne Host on AWS with DHCP service

As a final step, you will also configure a BloxOne Host on AWS with DHCP service.
You will use the following module to create these
- [bloxone_infra_host_aws](https://github.com/infobloxopen/terraform-provider-bloxone/tree/master/modules/bloxone_infra_host_aws)

The module requires the [AWS terraform provider](https://registry.terraform.io/providers/hashicorp/aws/latest) to be configured.
To configure the AWS provider, add the following code to your main.tf:

````terraform
provider "aws" {
region = "us-west-2"
access_key = "my-access-key"
secret_key = "my-secret-key"
}
````

!> Warning: Hard-coded credentials are not recommended in any configuration file. It is recommended to use the AWS credentials file or environment variables.

You can also use the following environment variables to configure the provider:
`AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.

To create an EC2 instance with DHCP service, you will need to have the following information:
- key_name: The name of the key pair to use for the instance
- subnet_id: The ID of the subnet to launch the instance into
- vpc_security_group_ids: A list of security group IDs to associate with the instance

Add the following code to your main.tf to create an EC2 instance with DHCP service:

````terraform

// Create a BloxOne Host on AWS with DHCP service
module "bloxone_infra_host_aws" {
source = "github.com/infobloxopen/terraform-provider-bloxone//modules/bloxone_infra_host_aws"

key_name = "my-key"
subnet_id = "subnet-id"
vpc_security_group_ids = ["vpc-security-group-id"]

services = {
dhcp = "start"
}
}
````

You will also have to modify the subnet resource to assign the BloxOne Host to serve the subnet. To do this, replace the subnet resource with the following code:

````terraform
resource "bloxone_ipam_subnet" "this" {
space = bloxone_ipam_ip_space.this.id
address = "10.0.0.0"
cidr = "24"
dhcp_host = module.bloxone_infra_host_aws.host.legacy_id
}
````

Here, the `dhcp_host` attribute has been added to the subnet resource and assigned the `legacy_id` of the BloxOne Host to serve the subnet.

You can now run `terraform plan` to see what resources will be created.

```shell
terraform plan
```

## Applying the Configuration

To create the resources, run the following command:

```shell
terraform apply
```

## Next steps

You can also use the BloxOne Terraform Provider to manage other resources such as DNS zones, DNS records. For more information, see the [BloxOne Terraform Provider documentation](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs).
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bloxone Provider"
page_title: "BloxOne Provider"
subcategory: ""
description: |-

The BloxOne provider is used to interact with the resources supported by Infoblox BloxOne API.
---

# bloxone Provider

# BloxOne Provider

The BloxOne provider is used to interact with the resources supported by Infoblox BloxOne API.

## Example Usage

Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (p *BloxOneProvider) Metadata(_ context.Context, _ provider.MetadataRequest

func (p *BloxOneProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "The BloxOne provider is used to interact with the resources supported by Infoblox BloxOne API.",
Attributes: map[string]schema.Attribute{
"csp_url": schema.StringAttribute{
MarkdownDescription: "URL for BloxOne Cloud Services Portal. Can also be configured using the `BLOXONE_CSP_URL` environment variable.",
Expand Down
5 changes: 2 additions & 3 deletions modules/bloxone_infra_host_aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ module "bloxone_infra_host_aws" {

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
| <a name="provider_bloxone"></a> [bloxone](#provider\_bloxone) | n/a |
| <a name="provider_random"></a> [random](#provider\_random) | n/a |

Expand Down
Loading
Loading