_Resource Importer for Confluent Terraform Provider_ enables importing your existing Confluent Cloud resources to Terraform Configuration (main.tf
) and Terraform State (terraform.tfstate
) files to a local directory named imported_confluent_infrastructure
.
These are the importable resources:
In this guide, you will:
tf_runner
in Confluent CloudOrganizationAdmin
role to the tf_runner
service accounttf_runner
service accountTerraform (0.14+) installed:
Run the following command to ensure that you're using a compatible version of Terraform.
terraform version
Your output should resemble:
Terraform v0.14.0 # any version >= v0.14.0 is OK
...
tf_runner
), then click Next.tf_runner
service account. Save your Cloud API key and secret in a secure location. You will need this API key and secret to use the Confluent Terraform Provider.OrganizationAdmin
role to the tf_runner
service account by following this guide.Clone the repository containing the example configurations:
git clone https://github.com/confluentinc/terraform-provider-confluent.git
Navigate into the configurations
subdirectory:
cd terraform-provider-confluent/examples/configurations
The configurations
directory has a subdirectory for each of the following configurations:
cloud-importer
: Import _Cloud_ resources (for example, Service Accounts, Environments)kafka-importer
: Import _Kafka_ resources (for example, ACLs, Topics)schema-registry-importer
: Import _Schema Registry_ resources (for example, Schemas)Select the target configuration and navigate into its directory:
# Using the example configuration #1 as an example
cd cloud-importer
Download and install the providers defined in the configuration:
terraform init
Use the saved Cloud API Key of the tf_runner
service account to set values to the confluent_cloud_api_key
and confluent_cloud_api_secret
input variables using environment variables:
export TF_VAR_confluent_cloud_api_key="<cloud_api_key>"
export TF_VAR_confluent_cloud_api_secret="<cloud_api_secret>"
Ensure the configuration is syntactically valid and internally consistent:
terraform validate
Apply the configuration:
terraform apply
You have now imported Confluent Cloud infrastructure using Terraform under cloud-importer/imported_confluent_infrastructure
! The terraform apply
command created a new folder called cloud-importer/imported_confluent_infrastructure
that contains 2 files: Terraform Configuration (main.tf
) and Terraform State (terraform.tfstate
) files.
Navigate into its directory:
# Using the example configuration #1 as an example
cd imported_confluent_infrastructure
Download and install the providers defined in the configuration:
terraform init
Your output should resemble:
...
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Refresh the configuration:
terraform refresh
Your output should resemble:
...
confluent_service_account.test_account: Refreshing state... [id=sa-oz5q19]
...
Ensure that import is successful by running terraform plan
:
terraform plan
Your output should resemble:
...
confluent_service_account.test_account: Refreshing state... [id=sa-oz5q19]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
You've successfully imported your Confluent Cloud infrastructure to Terraform. Terraform also compared your real infrastructure against your imported configuration and found no differences, so no changes are needed.