- Go version: 1.14
- Terraform version: 0.13.1
- Go to inside of the project directory
cd terraform
- Compile the project:
go build
There's the app.yml file that specifying the application configurations such as logging configurations... Sample configuration file:
logging:
level: warn
file: provider_bluecat.log
Create a file main.tf
with the following
provider "bluecat" {
server = "127.0.0.1"
api_version = "1"
transport = "http"
port = "5000"
username = "api_user"
password = "encryption_password/plain_text_password"
encrypt_password = true/false
}
encrypt_password: Default is false, to indicate if the password is encrypted
Note: The "depends_on" property in each resource to indicate the plan for actions, so that resources are created and destroyed in the correct order
resource "bluecat_configuration" "conf_record" {
name = "terraform_demo"
properties = "description=terraform testing config"
}
resource "bluecat_ipv4block" "block_record" {
configuration = "terraform_demo"
name = "block1"
parent_block = ""
address = "30.0.0.0"
cidr = "24"
properties = "allowDuplicateHost=enable"
depends_on = [bluecat_configuration.conf_record]
}
resource "bluecat_ipv4network" "net_record" {
configuration = "terraform_demo"
name = "network1"
cidr = "30.0.0.0/24"
gateway = "30.0.0.12"
reserve_ip = 3
properties = ""
depends_on = [bluecat_ipv4block.block_record]
}
resource "bluecat_ipv4network" "next_available_net_record" {
configuration = "terraform_demo"
name = "next available network1"
reserve_ip = 3
parent_block = "30.0.0.0/24"
size = 256
allocated_id = timestamp()
properties = ""
depends_on = [bluecat_ipv4block.block_record]
}
resource "bluecat_ip_allocation" "host_allocate" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
name = "testhost"
network = "30.0.0.0/24"
ip4_address = "30.0.0.22"
mac_address = "223344556688"
properties = ""
depends_on = [bluecat_ipv4network.net_record]
}
resource "bluecat_ip_allocation" "address_allocate" {
configuration = "terraform_demo"
view = "gg"
zone = ""
name = "testaddress"
network = "30.0.0.0/24"
ip4_address = "30.0.0.22"
mac_address = "223344556688"
properties = ""
depends_on = [bluecat_ipv4network.net_record]
}
resource "bluecat_ip_association" "address_associaion" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
name = "testaddress"
network = "30.0.0.0/24"
ip4_address = "30.0.0.22"
mac_address = "223344556688"
properties = ""
depends_on = [bluecat_ip_allocation.host_allocate]
}
resource "bluecat_host_record" "host_record" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
absolute_name = "testhost"
ip4_address = "30.0.0.124"
ttl = 123
properties = ""
depends_on = [bluecat_ipv4network.net_record]
}
resource "bluecat_ptr_record" "ptr_record" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
name = "host30"
ip4_address = "30.0.0.30"
ttl = 1
reverse_record = "True"
properties = ""
depends_on = [bluecat_ipv4network.net_record]
}
resource "bluecat_cname_record" "cname_record" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
absolute_name = "cname2"
linked_record = "host1.gateway.com"
ttl = 123
properties = ""
depends_on = [bluecat_host_record.host_record]
}
resource "bluecat_txt_record" "txt_record" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
absolute_name = "txt"
text = "text"
ttl = 123
properties = ""
}
resource "bluecat_generic_record" "generic_record" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
type = "NS"
absolute_name = "test_NS"
data = "text"
ttl = 123
properties = ""
}
resource "bluecat_dhcp_range" "dhcp_range" {
configuration = "terraform_demo"
network = "30.0.0.0/24"
start = "30.0.0.20"
end = "30.0.0.30"
properties = ""
template = "testtemplate"
depends_on = [bluecat_ipv4network.net_record]
}
resource "bluecat_zone" "sub_zone" {
configuration = "terraform_demo"
view = "Internal"
zone = "example.com"
deployable = "True"
server_roles = [“primary, server1”, “secondary, server2”]
properties = ""
}
data "bluecat_ipv4block" "test_ip4block" {
configuration = "terraform_demo"
cidr = "20.0.0.0/24"
}
output "output_block" {
value = data.bluecat_ipv4block.test_ip4block
}
data "bluecat_ipv4network" "test_ip4network" {
configuration = "terraform_demo"
cidr = "20.0.0.0/24"
}
output "output_network" {
value = data.bluecat_ipv4network.test_ip4network
}
data "bluecat_host_record" "test_record" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
fqdn = "host"
}
output "output_host" {
value = data.bluecat_host_record.test_record
}
data "bluecat_cname_record" "test_cname" {
configuration = "terraform_demo"
view = "gg"
zone = "gateway.com"
linked_record = "host.gateway.com"
canonical = "cname"
}
output "output_cname" {
value = data.bluecat_cname_record.test_cname
}
data "bluecat_zone" "sub_zone" {
configuration="terraform_demo"
view="Internal"
zone="example.com"
}
output "sub_zone_data" {
value = data.bluecat_zone.sub_zone
}
output "id" {
value = data.bluecat_zone.sub_zone.id
}
output "deployable" {
value = data.bluecat_zone.sub_zone.deployable
}
output "server_roles" {
value = data.bluecat_zone.sub_zone.server_roles
}
In case of you're using the local build of the provider, you need to prepare the structure to be able to installing the provider as below. Otherwise, just run the terraform init
.
- Create the directory to store the providers: <HOME_DIR>/providers
- Create the provider structure for the provider under the directory at step 1: /////<PROVIDER_BINARY>. For example: test.com/hashicorp/bluecat/1.0.0/windows_amd64/terraform-provider-bluecat.exe
- Add the block of configuration for the provider
For example:
terraform { required_providers { <TYPE> = { version = ">= <VERSION>" source = "<HOSTNAME>/<NAMESPACE>/<TYPE>" } } }
terraform { required_providers { bluecat = { version = ">= 1.0.0" source = "test.com/hashicorp/bluecat" } } }
- Install your provider:
terraform init -plugin-dir=<HOME_DIR>/providers
terraform plan
terraform apply
terraform destroy