How to Import an Google KMS Key Ring IAM Member into Terraform
terraback gcp import --method bulk. Terraback writes the matching google_kms_key_ring_iam_member resource block and the Terraform 1.5+ import block for you, so you do not have to run terraform import by hand. The import ID is the key ring path, role, and member separated by spaces: "projects/{project}/locations/{location}/keyRings/{key_ring} {role} {member}".Import Google KMS Key Ring IAM Member with Terraback (recommended)
Terraback reverse-engineers your live infrastructure: it reads the Google Cloud KMS resource with read-only credentials, generates the HCL, and produces the exact import block. Two commands take you from a live Google KMS Key Ring IAM Member to managed Terraform.
Scan your Google Cloud account
terraback scan all gcp --project my-gcp-projectGenerate import blocks and import into state
terraback gcp import --method bulkThe Terraform import block
Terraback emits a Terraform 1.5+ import block like the one below. Because the block lives in your configuration, the import is reviewable in a pull request and repeatable across environments.
import {
to = google_kms_key_ring_iam_member.viewer
id = "projects/my-project/locations/us-central1/keyRings/my-ring roles/cloudkms.viewer user:jane@example.com"
}Example google_kms_key_ring_iam_member configuration
Here is a realistic Google KMS Key Ring IAM Member block. Terraback generates a fuller version from your actual resource attributes; this is a minimal, valid starting point.
resource "google_kms_key_ring_iam_member" "viewer" {
key_ring_id = google_kms_key_ring.main.id
role = "roles/cloudkms.viewer"
member = "user:jane@example.com"
}Gotchas when importing a Google KMS Key Ring IAM Member
- An iam_member grants one member a role additively without overwriting other members; google_kms_key_ring_iam_binding would instead make Terraform authoritative for the whole role.
- Roles granted at the key-ring level are inherited by all crypto keys in the ring; grant at the key level when you need finer scope.
- The import ID is three space-separated parts: the full keyRings path, the role, and the single member (with its type prefix).
- Mixing an authoritative binding and an additive member for the same role on the same key ring causes them to overwrite each other on every apply.
Doing it manually with terraform import
The native approach is to write the google_kms_key_ring_iam_member block by hand, then run terraform import google_kms_key_ring_iam_member.example <import-id> for every resource, one at a time. That works for a handful of resources, but it does not scale: you author all the HCL yourself and repeat the command for each item. Terraback generates the HCL and the import blocks for your whole account in one pass.
Import other Google Cloud resources
Import your whole Google Cloud account in minutes
Terraback scans 80+ Google Cloud resource types and emits clean Terraform plus import blocks, running locally with read-only credentials. $499 once, no SaaS.