Setting up Terraform for DNS Services
Terraform on IBM Cloud® enables predictable and consistent provisioning of IBM Cloud services so that you can rapidly build complex, multi-tier cloud environments following Infrastructure as Code (IaC) principles. Similar to using the IBM Cloud CLI or API and SDKs, you can automate the provisioning, update, and deletion of your IBM Cloud® DNS Services instances by using HashiCorp Configuration Language (HCL).
Looking for a managed Terraform on IBM Cloud® solution? Try out IBM Cloud® Schematics. With Schematics, you can use the Terraform scripting language that you are familiar with, but you don't have to worry about setting up and maintaining the Terraform command line and the IBM Cloud® Provider plug-in. Schematics also provides pre-defined Terraform templates that you can easily install from the IBM Cloud® catalog.
Installing Terraform and configuring resources for DNS Services
Before you begin, make sure that you have the required access to create and work with DNS Services resources.
- Install the Terraform CLI and configure the IBM Cloud Provider plug-in for Terraform. For more information, see the tutorial for Getting started with Terraform on IBM Cloud®. The plug-in abstracts the IBM Cloud APIs that are used to complete this task.
- Create a Terraform configuration file that is named
main.tf
. In this file, you add the configuration to create a DNS Services service instance and to assign a user an access policy in Identity and Access Management (IAM) for that instance by using HashiCorp Configuration Language (HCL). For more information, see the Terraform documentation.
-
Create a DNS Services instance by using the
ibm_resource_instance
resource argument in yourmain.tf
file.The DNS Services DNS zone in the following example is named
my-dns-zone
and is created with the instance ID ofp-dns-instance-id
.data "ibm_resource_group" "rg" { is_default = true } resource "ibm_resource_instance" "test-pdns-instance" { name = "private-dns-instance-example" resource_group_id = data.ibm_resource_group.rg.id location = "global" service = "dns-svcs" plan = "standard-dns" } resource "ibm_dns_zone" "pdns-1-zone" { name = "my-dns-zone" instance_id = ibm_resource_instance.test-pdns-cr-instance.guid description = "testdescription" label = "testlabel" }
-
After you finish building your configuration file, initialize the Terraform CLI. For more information, see Initializing Working Directories.
terraform init
-
Provision the resources from the
main.tf
file. For more information, see Provisioning Infrastructure with Terraform.-
Run
terraform plan
to generate a Terraform execution plan to preview the proposed actions.terraform plan
-
Run
terraform apply
to create the resources that are defined in the plan.terraform apply
-
-
From the IBM Cloud resource list, select the DNS Services instance that you created and note the instance ID.
-
Verify that the access policy is successfully assigned. For more information, see Reviewing assigned access in the console.
What's next?
Now that you successfully created your first DNS Services service instance with Terraform on IBM Cloud, you can visit the DNS Services Terraform registry to perform additional tasks using Terraform.