Create a certificate by using Terraform
Terraform is an open-source software tool that lets you create and manage your CA Service resources using its infrastructure-as-code paradigm.
Objective
This page describes how you can use Terraform to perform the following operations with Certificate Authority Service:
- Create a certificate authority (CA) pool.
- Create a CA in the new CA pool.
- Generate a new Certificate Signing Request (CSR).
- Use the generated CSR to request a certificate from the new CA pool.
This tutorial uses the Google Cloud Terraform Provider for Terraform.
Before you begin
Make sure that you have the CA Service Admin (roles/privateca.admin
)
IAM role. If you don't have this IAM role, read
Grant a single role
for information about granting this role.
Create a Google Cloud project
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.
-
Enable the CA Service API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.
-
Enable the CA Service API.
Install the Google Cloud CLI
If you haven't already, install the Google Cloud CLI. When prompted, choose the project that you selected or created earlier.
If you already have the Google Cloud CLI installed, update it using the following Google Cloud CLI command:
gcloud components update
For more information about this gcloud CLI command, see gcloud components update.
Create a Terraform configuration file
To create a Terraform configuration file that you can use to perform operations on CA Service, do the following:
Create a new directory for the project to live.
In this new directory, create a
main.tf
file for the Terraform configuration.Copy the following Terraform configuration, and paste it in the
main.tf
file.For information about operating CA Service with Terraform, see Using Terraform with CA Service.
For more information about setting up Terraform with Google Cloud, see Getting started with the Google Cloud Provider.
Run the Terraform configuration file
To run the Terraform configuration file you created, run the following commands in Cloud Shell.
For information about running gcloud CLI commands using Cloud Shell, see Running gcloud commands with Cloud Shell.
Initialize Terraform in the directory where you have stored the
main.tf
file.terraform init
Run the created Terraform configuration file.
terraform apply
When prompted to confirm if you want to run the configuration file, enter yes.
What's next
- Learn how to use Terraform with Google Cloud.
- Read the Terraform documentation about CA Service support.
- Get started with the Google Cloud Provider.
- Use Terraform with CA Service.