|
| 1 | +--- |
| 2 | +page_title: "Managing DDI services with the NIOS Terraform Provider" |
| 3 | +subcategory: "Guides" |
| 4 | +description: |- |
| 5 | + This guide provides step-by-step instructions for using the NIOS Terraform Provider to manage DDI resources. |
| 6 | +--- |
| 7 | + |
| 8 | +# Managing DDI services with the NIOS Terraform Provider |
| 9 | + |
| 10 | +This guide provides step-by-step instructions for using the NIOS Terraform Provider to manage DDI resources. |
| 11 | + |
| 12 | +## Configuring the Provider |
| 13 | + |
| 14 | +Before getting started, ensure you have completed the [prerequisites](../README.md#prerequisites). |
| 15 | + |
| 16 | +The provider needs to be configured with a `NIOSHostURL`, `NIOSUsername` and `NIOSPassword`. |
| 17 | + |
| 18 | +Create a directory for the Terraform configuration and create a file named `main.tf` with the following content: |
| 19 | + |
| 20 | +````terraform |
| 21 | +terraform { |
| 22 | + required_providers { |
| 23 | + nios = { |
| 24 | + source = "infobloxopen/nios" |
| 25 | + version = ">= 0.0.1" |
| 26 | + } |
| 27 | + } |
| 28 | + required_version = ">= 1.8.0" |
| 29 | +} |
| 30 | +
|
| 31 | +provider "nios" { |
| 32 | + nios_host_url = "<NIOS_HOST_URL>" |
| 33 | + nios_username = "<NIOS_USERNAME>" |
| 34 | + nios_password = "<NIOS_PASSWORD>" |
| 35 | +} |
| 36 | +```` |
| 37 | + |
| 38 | +> ⚠️ **Warning**: Hard-coded credentials are not recommended in any configuration file. It is recommended to use environment variables. |
| 39 | +
|
| 40 | +You can also use the following environment variables to configure the provider: NIOS_HOST_URL, NIOS_USERNAME and NIOS_PASSWORD. |
| 41 | + |
| 42 | +Initialize the provider by running the following command. This will download the provider and initialize the working directory. |
| 43 | + |
| 44 | + |
| 45 | +```shell |
| 46 | +terraform init |
| 47 | +``` |
| 48 | + |
| 49 | +## Configuring Resources |
| 50 | + |
| 51 | +This section demonstrates how to create and manage resources using the NIOS Terraform provider. |
| 52 | + |
| 53 | +### DNS Resources |
| 54 | + |
| 55 | +### Authoritative Zone |
| 56 | + |
| 57 | +In this example, you will use the following resources to create an authoritative zone. |
| 58 | + |
| 59 | +- [nios_dns_zone_auth](https://registry.terraform.io/providers/infobloxopen/nios/latest/docs/resources/nios_dns_zone_auth) |
| 60 | + |
| 61 | +Add the following to the `main.tf` file: |
| 62 | + |
| 63 | +````terraform |
| 64 | +// Create a DNS zone for the domain |
| 65 | +resource "nios_dns_zone_auth" "create_zone_auth" { |
| 66 | + fqdn = "exampledomain.com" |
| 67 | + extattrs = { |
| 68 | + Site = "location-1" |
| 69 | + } |
| 70 | +} |
| 71 | +```` |
| 72 | + |
| 73 | +Here the `view` attribute has not been set, so the default view will be used. |
| 74 | + |
| 75 | +### DNS Records |
| 76 | +Further, you will create an A record and a CNAME record within the zone. |
| 77 | + |
| 78 | +You will use the following resources to create these |
| 79 | +- [nios_dns_record_a](https://registry.terraform.io/providers/infobloxopen/nios/latest/docs/resources/nios_dns_record_a) |
| 80 | +- [nios_dns_record_cname](https://registry.terraform.io/providers/infobloxopen/nios/latest/docs/resources/nios_dns_record_cname) |
| 81 | + |
| 82 | +Add the following code to your main.tf: |
| 83 | + |
| 84 | +````terraform |
| 85 | +// Create an A record |
| 86 | +resource "nios_dns_record_a" "create_record_a" { |
| 87 | + name = "a_record.${nios_dns_zone_auth.create_zone_auth.fqdn}" |
| 88 | + ipv4addr = "10.0.0.10" |
| 89 | + view = "default" |
| 90 | + // Extensible Attributes |
| 91 | + extattrs = { |
| 92 | + Site = "location-1" |
| 93 | + } |
| 94 | +} |
| 95 | +
|
| 96 | +// Create a CNAME record |
| 97 | +resource "nios_dns_record_cname" "create_record_cname" { |
| 98 | + name = "cname_record.${nios_dns_zone_auth.create_zone_auth.fqdn}" |
| 99 | + canonical = "example-canonical-name.${nios_dns_zone_auth.create_zone_auth.fqdn}" |
| 100 | + depends_on = [nios_dns_zone_auth.create_zone_auth] |
| 101 | +} |
| 102 | +```` |
| 103 | + |
| 104 | +## IPAM Resources |
| 105 | +In this example, you will use the following resources to create a Network View and a Network |
| 106 | + |
| 107 | +- [nios_ipam_network_view](https://registry.terraform.io/providers/infobloxopen/nios/latest/docs/resources/nios_ipam_network_view) |
| 108 | +- [nios_ipam_network](https://registry.terraform.io/providers/infobloxopen/nios/latest/docs/resources/nios_ipam_network) |
| 109 | + |
| 110 | +Add the following to your main.tf: |
| 111 | + |
| 112 | +````terraform |
| 113 | +//Create a Network View |
| 114 | +resource "nios_ipam_network_view" "create_network_view" { |
| 115 | + name = "example_network_view" |
| 116 | +} |
| 117 | +
|
| 118 | +// Create an IPV4 Network |
| 119 | +resource "nios_ipam_network" "create_network" { |
| 120 | + network = "15.0.0.0/24" |
| 121 | + network_view = "example_network_view" |
| 122 | + comment = "Created by Terraform" |
| 123 | + extattrs = { |
| 124 | + "Site" = "location-1" |
| 125 | + } |
| 126 | +} |
| 127 | +```` |
| 128 | + |
| 129 | +## DHCP Resources |
| 130 | +In this example, you will use the following resources to create a Fixed Address within the Network created above. |
| 131 | + |
| 132 | +- [nios_dhcp_fixed_address](https://registry.terraform.io/providers/infobloxopen/nios/latest/docs/resources/nios_dhcp_fixed_address) |
| 133 | + |
| 134 | +Add the following to your main.tf: |
| 135 | + |
| 136 | +````terraform |
| 137 | +//Create a fixed address within the above network |
| 138 | +resource "nios_dhcp_fixed_address" "create_fixed_address" { |
| 139 | + ipv4addr = "15.0.0.10" |
| 140 | + match_client = "MAC_ADDRESS" |
| 141 | + mac = "00:1a:2b:3c:4d:5e" |
| 142 | + depends_on = [nios_ipam_network.create_network] |
| 143 | +} |
| 144 | +```` |
| 145 | + |
| 146 | +You can now run `terraform plan` to see what resources will be created. |
| 147 | + |
| 148 | +```shell |
| 149 | +terraform plan |
| 150 | +``` |
| 151 | + |
| 152 | +## Applying the Configuration |
| 153 | + |
| 154 | +To create the resources, run the following command: |
| 155 | + |
| 156 | +```shell |
| 157 | +terraform apply |
| 158 | +``` |
| 159 | + |
| 160 | +## Destroying the Configuration |
| 161 | + |
| 162 | +To destroy all the resources, run the following command: |
| 163 | + |
| 164 | +```shell |
| 165 | +terraform destroy |
| 166 | +``` |
| 167 | + |
| 168 | +## Configuring Datasources |
| 169 | + |
| 170 | +Datasources allow you to retrieve existing NIOS objects. Here's a simple example: |
| 171 | + |
| 172 | +````terraform |
| 173 | +// Get an existing DNS zone |
| 174 | +data "nios_dns_zone_auth" "get_auth_zone" { |
| 175 | + fqdn = "exampledomain.com" |
| 176 | + view = "default" |
| 177 | +} |
| 178 | +
|
| 179 | +// Output the zone information |
| 180 | +output "zone_info" { |
| 181 | + value = { |
| 182 | + zone_name = data.nios_dns_zone_auth.get_auth_zone.fqdn |
| 183 | + zone_view = data.nios_dns_zone_auth.get_auth_zone.view |
| 184 | + } |
| 185 | +} |
| 186 | +```` |
| 187 | + |
| 188 | +## Next steps |
| 189 | + |
| 190 | +You can also use the NIOS Terraform Provider to manage other resources. For more information, see the [NIOS Terraform Provider documentation](https://registry.terraform.io/providers/infobloxopen/nios/latest/docs). |
0 commit comments