the input hcl to the module
terraform {
source = "../path-to-my-terraform-module"
}
inputs = {
project = dependency.project.outputs.project_id
jobs = {
"job_name_a" = {
"description" = "job description A",
"transfer_spec" = {
"posix_data_source": {
"root_directory": "/mnt/job"
},
"gcs_data_sink": {
"bucket_name": "my-bucket"
},
"transfer_options": {
"overwrite_when": "DIFFERENT",
"delete_objects_from_source_after_transfer": true
}
},
"schedule" = {
"schedule_start_date" = {
"year" = 2024,
"month" = 8,
"day" = 12
},
"repeat_interval" = "3600s"
}
}
}
}
terraform module
variable "jobs" {
description = "Map of jobs with their respective configurations"
type = any
}
resource "google_storage_transfer_job" "jobs" {
for_each = var.jobs
project = var.project
description = lookup(each.value, "description", "")
transfer_spec {
dynamic "posix_data_source" {
for_each = lookup(each.value.transfer_spec, "posix_data_source", [])
content {
root_directory = posix_data_source.value.root_directory
}
}
dynamic "gcs_data_sink" {
for_each = lookup(each.value.transfer_spec, "gcs_data_sink", [])
content {
bucket_name = gcs_data_sink.value.bucket_name
}
}
dynamic "transfer_options" {
for_each = lookup(each.value.transfer_spec, "transfer_options", [])
content {
overwrite_objects_already_existing_in_sink = lookup(transfer_options.value, "overwrite_when", "DIFFERENT") != "NEVER"
delete_objects_from_source_after_transfer = lookup(transfer_options.value, "delete_objects_from_source_after_transfer", false)
}
}
}
schedule {
dynamic "schedule_start_date" {
for_each = lookup(each.value.schedule, "schedule_start_date", [])
content {
year = schedule_start_date.value.year
month = schedule_start_date.value.month
day = schedule_start_date.value.day
}
}
repeat_interval = lookup(each.value.schedule, "repeat_interval", "")
}
}
output "jobs_id_list" {
value = [for job in google_storage_transfer_job.jobs : job.name]
description = "List of all job names created."
}
errors are
in resource "google_storage_transfer_job" "storage_transfer":
│ 15: root_directory = posix_data_source.value.root_directory
│ ├────────────────
│ │ posix_data_source.value is "/mnt/job"
│
│ Can't access attributes on a primitive-typed value (string)
please let me know how can i correct this error on string?
Also like posix_data_source we can have gcs_data_source block as well. So How do we specify this choice in the terraform module and make sure that only one source is generated by the module(either posix_data_source or gcs_data_source)?