|
| 1 | +resource "cloudflare_workers_domain" "worker_project_domain" { |
| 2 | + account_id = var.cloudflare_account_id |
| 3 | + hostname = "${var.project_name}.${var.environment}.${var.domain}" |
| 4 | + service = "${var.project_name}-${var.environment}" |
| 5 | + zone_id = var.cloudflare_zone_id |
| 6 | + |
| 7 | + depends_on = [cloudflare_workers_script.project_script] |
| 8 | +} |
| 9 | + |
| 10 | +resource "cloudflare_workers_route" "project_route" { |
| 11 | + zone_id = var.cloudflare_zone_id |
| 12 | + pattern = "${var.project_name}.${var.environment}.${var.domain}/*" |
| 13 | + script_name = cloudflare_workers_script.project_script.name |
| 14 | +} |
| 15 | + |
| 16 | +resource "cloudflare_workers_kv_namespace" "settings" { |
| 17 | + account_id = var.cloudflare_account_id |
| 18 | + title = "${var.project_name}-${var.environment}-settings" |
| 19 | +} |
| 20 | + |
| 21 | +resource "cloudflare_workers_script" "project_script" { |
| 22 | + account_id = var.cloudflare_account_id |
| 23 | + name = "${var.project_name}-${var.environment}" |
| 24 | + content = file("${path.module}/dist/index.mjs") |
| 25 | + compatibility_date = "2023-08-28" |
| 26 | + module = true |
| 27 | + |
| 28 | + kv_namespace_binding { |
| 29 | + name = "SETTINGS" |
| 30 | + namespace_id = cloudflare_workers_kv_namespace.settings.id |
| 31 | + } |
| 32 | + |
| 33 | + plain_text_binding { |
| 34 | + name = "CORS_DOMAINS" |
| 35 | + text = var.ALLOWED_HOSTS |
| 36 | + } |
| 37 | + |
| 38 | + plain_text_binding { |
| 39 | + name = "DOMAIN" |
| 40 | + text = var.domain |
| 41 | + } |
| 42 | + |
| 43 | + plain_text_binding { |
| 44 | + name = "ENVIRONMENT" |
| 45 | + text = var.environment |
| 46 | + } |
| 47 | + |
| 48 | + plain_text_binding { |
| 49 | + name = "GCP_LOGGING_PROJECT_ID" |
| 50 | + text = var.GCP_LOGGING_PROJECT_ID |
| 51 | + } |
| 52 | + |
| 53 | + plain_text_binding { |
| 54 | + name = "GCP_BIGQUERY_PROJECT_ID" |
| 55 | + text = var.GCP_BIGQUERY_PROJECT_ID |
| 56 | + } |
| 57 | + plain_text_binding { |
| 58 | + name = "LOG_NAME" |
| 59 | + text = "${var.project_name}_${var.environment}_worker_log" |
| 60 | + } |
| 61 | + |
| 62 | + plain_text_binding { |
| 63 | + name = "VERSION" |
| 64 | + text = var.VERSION |
| 65 | + } |
| 66 | + |
| 67 | + secret_text_binding { |
| 68 | + name = "GCP_LOGGING_CREDENTIALS" |
| 69 | + text = var.GCP_LOGGING_CREDENTIALS |
| 70 | + } |
| 71 | + |
| 72 | + secret_text_binding { |
| 73 | + name = "GCP_BIGQUERY_CREDENTIALS" |
| 74 | + text = var.GCP_BIGQUERY_CREDENTIALS |
| 75 | + } |
| 76 | + |
| 77 | + secret_text_binding { |
| 78 | + name = "GCP_USERINFO_CREDENTIALS" |
| 79 | + text = var.GCP_USERINFO_CREDENTIALS |
| 80 | + } |
| 81 | + |
| 82 | + secret_text_binding { |
| 83 | + name = "GLOBAL_SHARED_SECRET" |
| 84 | + text = var.GLOBAL_SHARED_SECRET |
| 85 | + } |
| 86 | + |
| 87 | + d1_database_binding { |
| 88 | + name = "${var.project_name}_${var.environment}_cache" |
| 89 | + database_id = "${data.local_file.load_api_gateway_cache_id.content}" |
| 90 | + } |
| 91 | +} |
0 commit comments