Google CloudCloud Tasksgoogle_cloud_tasks_queuePro

How to Import an Google Cloud Tasks Queue into Terraform

To import an existing Google Cloud Tasks Queue into Terraform, scan it with Terraback and run terraback gcp import --method bulk. Terraback writes the matching google_cloud_tasks_queue 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 full path projects/{project}/locations/{location}/queues/{name} (for example, projects/my-project/locations/us-central1/queues/emails).

Import Google Cloud Tasks Queue with Terraback (recommended)

Terraback reverse-engineers your live infrastructure: it reads the Cloud Tasks resource with read-only credentials, generates the HCL, and produces the exact import block. Two commands take you from a live Google Cloud Tasks Queue to managed Terraform.

1

Scan your Google Cloud account

terraback scan all gcp --project my-gcp-project
2

Generate import blocks and import into state

terraback gcp import --method bulk

The 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_cloud_tasks_queue.emails
  id = "projects/my-project/locations/us-central1/queues/emails"
}

Example google_cloud_tasks_queue configuration

Here is a realistic Google Cloud Tasks Queue block. Terraback generates a fuller version from your actual resource attributes; this is a minimal, valid starting point.

resource "google_cloud_tasks_queue" "emails" {
  name     = "emails"
  location = "us-central1"

  rate_limits {
    max_dispatches_per_second = 100
    max_concurrent_dispatches = 50
  }

  retry_config {
    max_attempts = 5
  }
}

Gotchas when importing a Google Cloud Tasks Queue

  • A Cloud Tasks queue location is tied to the App Engine region of the project and cannot be changed after creation.
  • rate_limits and retry_config have server-applied defaults; if you omit them Terraform may show a diff against the live values.
  • Tasks themselves are runtime objects and are never imported; only the queue configuration is managed.
  • Durations such as max_retry_duration and min_backoff are seconds strings like 3600s, not plain integers.

Doing it manually with terraform import

The native approach is to write the google_cloud_tasks_queue block by hand, then run terraform import google_cloud_tasks_queue.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 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.