Search code examples
google-cloud-platformterraformgoogle-cloud-storageterraform-provider-gcp

Cannot crerate Google Storage Transfer Job with Terraform


I am trying to create a Storage Transfer job via Terraform as:

resource "google_storage_transfer_job" "goout_storage_backup" {
  description = "my-transfer-job"
  project = "my-project"
  transfer_spec {
    object_conditions {
      max_time_elapsed_since_last_modification = "86400s"
    }
    transfer_options {
      delete_objects_from_source_after_transfer  = false
      delete_objects_unique_in_sink              = false
      overwrite_objects_already_existing_in_sink = true
    }
    gcs_data_source {
      bucket_name = "source"
    }
    gcs_data_sink {
      bucket_name = "target"
    }
  }
  schedule {
    schedule_start_date {
      year  = 1970
      month = 01
      day   = 1
    }
    start_time_of_day {
      hours   = 4
      minutes = 27
      seconds = 0
      nanos   = 42
    }
  }
}

My existing jobs are easily manageable with this script, however Terraform refuses to create any new transfer jobs:

Error: googleapi: Error 400: Failed to obtain the location of the Google Cloud Storage (GCS) bucket source due to insufficient permissions. Please verify that the necessary permissions have been granted., failedPrecondition

However my user is an owner and I also tried to assign Storage Transfer Admin and Storage Admin with no luck.


Solution

  • When creating a transfer job via Terraform, the target buckets must have assigned the transfer-service-account before. Assigning these fixed the issue.