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

Workflow for DFP Service #126

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
258 changes: 258 additions & 0 deletions docs/guides/quickstart-dfp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
---
page_title: "Managing Policy Based DFP service using the BloxOne Terraform Provider"
subcategory: "Guides"
description: |-
This guide provides step-by-step instructions for using the BloxOne Terraform Provider to manage the DFP Service , Security Policies and various resources associated to it.
---

# Managing Policy Based DFP service using the BloxOne Terraform Provider

This guide provides step-by-step instructions for using the BloxOne Terraform Provider to manage the DFP Service , Security Policies and various resources associated to it.

## 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 = {
source = "infobloxopen/bloxone"
version = ">= 1.0.0"
}
}
required_version = ">= 1.5.0"
}

provider "bloxone" {
csp_url = "https://csp.infoblox.com"

Choose a reason for hiding this comment

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

We suggest to use environment variables, if then I would recommend to update the Terraform content with ENV variables for both CSP & API. Then add some comment for ENV variable with value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Users generally provide credentials as Env variables . This is given just as an example here . We have also added a warning against hard coded credentials below !

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

### BloxOne Host on AWS with DFP service

As the first step, you will configure a BloxOne Host on AWS with DFP service.

You will use the following module to create it:
- [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:

Choose a reason for hiding this comment

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

Why do we mention about DHCP service here ?

Choose a reason for hiding this comment

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

Also, why are we creating the host with DHCP service in DFP example ?

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 is a typo . Has been modified.

- 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 = {
dfp = "start"
}
}
````

You will need the pool ID of the AWS host to create the Infra Service block for DFP.

To create the Infra service block , we use the following resource :
- [bloxone_infra_service](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/infra_service)

Add the following code to your main.tf:

````terraform
resource "bloxone_infra_service" "example" {
name = "example_dfp_service"
pool_id = data.bloxone_infra_hosts.dfp_host.results.0.pool_id
service_type = "dfp"
desired_state = "start"
}
````


Next , we create the DFP Service block and an Internal Domain List using the following resources:
- [bloxone_td_internal_domain_list](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/td_internal_domain_list)
- [bloxone_dfp_service](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/dfp_service)

We use the service ID of the Infra Service block to create the DFP Service.

Add the following code to your main.tf:

````terraform
resource "bloxone_td_internal_domain_list" "example_list" {
name = "example_internal_domain_list"
internal_domains = ["example.domain.com"]
}

# Create the DFP Service
resource "bloxone_dfp_service" "example" {
Copy link

@agowtham agowtham Jul 25, 2024

Choose a reason for hiding this comment

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

Match the name 'bloxone_dfp_service' in all cases through out the document. In previous step, Infra service was created with name 'example_dfp_service' and here, we mentioned resource with different name.

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

service_id = bloxone_infra_service.example.id

# Other optional fields
internal_domain_lists = [bloxone_td_internal_domain_list.example_list.id]
resolvers_all = [
{
address = "1.1.1.1"
is_fallback = true
is_local = false
protocols = ["DO53"]
}
]
}
````
The `resolvers_all` attribute is used to specify the DNS resolvers for the DFP service.

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

```shell
terraform plan
```

### Creating the Security Policy and Resources associated with it
In this example, you will use the following resources to create a Custom List, Bypass Code and an External Network.

- [bloxone_td_named_list (Custom List)](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/td_named_list)
- [bloxone_td_access_code (Bypass Code)](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/td_access_code)
- [bloxone_td_network_list (External Network)](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/td_network_list)

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

````terraform
# Create the Named List
resource "bloxone_td_named_list" "example" {
name = "example_named_list"
items_described = [
{
item = "tf-domain.com"
description = "Example Domain"
}
]
type = "custom_list"
}

# Create the Access Code using the Named List
resource "bloxone_td_access_code" "example" {
name = "example_access_code"
activation = timestamp()
expiration = timeadd(timestamp(), "24h")
rules = [
{
data = bloxone_td_named_list.example.name,
type = bloxone_td_named_list.example.type
}
]
# Other optional fields
description = "Example Access Code"
}

# Create the Network List
resource "bloxone_td_network_list" "example" {
name = "example_network_list"
items = ["156.2.3.0/24"]

# Other optional fields
description = "Example Network List"
}


````
The `rules` attribute in the Access code resource is used to specify the Named List created earlier.

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

```shell
terraform plan
```

Finally, you will create the Security Policy that uses the Custom List, Bypass Code and an External Network created earlier.

Choose a reason for hiding this comment

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

If this document is specific to DFP, then I would not like to add content for Bypass Code and External Network List

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idea was that , since we are already demonstrating a DFP based Security policy , we demonstrate all the other TD objects associated with it . This has been mentioned in the description too .

Choose a reason for hiding this comment

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

Here, it is good to mention that create policy with DFP.

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


- [bloxone_td_security_policy](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs/resources/td_security_policy)

Add the following code to your main.tf:

````terraform
# Create the Security Policy using the Named List, Network List, and Access Code
resource "bloxone_td_security_policy" "example" {
name = "example_security_policy"

# Other optional fields
rules = [
{
action = "action_allow",
data = bloxone_td_named_list.example.name,
type = bloxone_td_named_list.example.type
}
]
description = "Example Security Policy"
dfps = [bloxone_dfp_service.example.id]
ecs = true
onprem_resolve = true
safe_search = false
tags = {
site = "Site A"
}
network_lists = [bloxone_td_network_list.example.id]
access_codes = [bloxone_td_access_code.example.id]
}
````

Here the `dfps` attribute is used to associate the Security Policy with the DFP Service.

The `onprem_resolve` attribute is used to enable the resolution of on-premises domains.

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 DNS and DHCP/IPAM resources. For more information, see the [BloxOne Terraform Provider documentation](https://registry.terraform.io/providers/infobloxopen/bloxone/latest/docs).
Loading
Loading