|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -locals { |
18 | | - cluster_endpoint = "https://${var.cluster_endpoint}" |
19 | | - token = data.google_client_config.default.access_token |
20 | | - cluster_ca_certificate = data.google_container_cluster.primary.master_auth.0.cluster_ca_certificate |
21 | | - private_key = var.create_ssh_key && var.ssh_auth_key == null ? tls_private_key.git_creds[0].private_key_pem : var.ssh_auth_key |
22 | | - download_operator = var.operator_path == null ? true : false |
23 | | - operator_path = local.download_operator ? "${path.module}/config-management-operator.yaml" : var.operator_path |
24 | | -} |
25 | | - |
26 | | -data "google_container_cluster" "primary" { |
27 | | - name = var.cluster_name |
28 | | - project = var.project_id |
29 | | - location = var.location |
30 | | -} |
31 | | - |
32 | | -data "google_client_config" "default" { |
33 | | -} |
34 | | - |
35 | | -resource "tls_private_key" "git_creds" { |
36 | | - count = var.create_ssh_key ? 1 : 0 |
37 | | - algorithm = "RSA" |
38 | | - rsa_bits = 4096 |
39 | | -} |
40 | | - |
41 | | -module "acm_operator_config" { |
42 | | - source = "terraform-google-modules/gcloud/google" |
43 | | - version = "~> 0.5" |
44 | | - enabled = local.download_operator |
45 | | - |
46 | | - create_cmd_entrypoint = "gsutil" |
47 | | - create_cmd_body = "cp gs://config-management-release/released/latest/config-management-operator.yaml ${path.module}/config-management-operator.yaml" |
48 | | - destroy_cmd_entrypoint = "rm" |
49 | | - destroy_cmd_body = "-f ${path.module}/config-management-operator.yaml" |
50 | | -} |
51 | | - |
52 | 17 | module "acm_operator" { |
53 | | - source = "terraform-google-modules/gcloud/google" |
54 | | - version = "~> 0.5" |
55 | | - module_depends_on = [module.acm_operator_config.wait, data.google_client_config.default.project, data.google_container_cluster.primary.name] |
56 | | - additional_components = ["kubectl"] |
57 | | - |
58 | | - create_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh" |
59 | | - create_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl apply -f ${local.operator_path}" |
60 | | - destroy_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh" |
61 | | - destroy_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl delete -f ${local.operator_path}" |
62 | | -} |
63 | | - |
64 | | -module "git_creds_secret" { |
65 | | - source = "terraform-google-modules/gcloud/google" |
66 | | - version = "~> 0.5" |
67 | | - module_depends_on = [module.acm_operator.wait] |
68 | | - additional_components = ["kubectl"] |
69 | | - |
70 | | - create_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh" |
71 | | - create_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl create secret generic git-creds -n=config-management-system --from-literal=ssh='${local.private_key}'" |
72 | | - destroy_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh" |
73 | | - destroy_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl delete secret git-creds -n=config-management-system" |
74 | | -} |
75 | | - |
76 | | -data "template_file" "acm_config" { |
77 | | - template = file("${path.module}/templates/acm-config.yml.tpl") |
78 | | - |
79 | | - vars = { |
80 | | - cluster_name = var.cluster_name |
81 | | - sync_repo = var.sync_repo |
82 | | - sync_branch = var.sync_branch |
83 | | - policy_dir = var.policy_dir |
84 | | - secret_type = var.create_ssh_key ? "ssh" : "none" |
85 | | - enable_policy_controller = var.enable_policy_controller ? "true" : "false" |
86 | | - install_template_library = var.install_template_library ? "true" : "false" |
87 | | - } |
88 | | -} |
89 | | - |
90 | | -module "acm_config" { |
91 | | - source = "terraform-google-modules/gcloud/google" |
92 | | - version = "~> 0.5" |
93 | | - module_depends_on = [module.acm_operator.wait, module.git_creds_secret.wait] |
94 | | - additional_components = ["kubectl"] |
95 | 18 |
|
96 | | - create_cmd_entrypoint = "echo" |
97 | | - create_cmd_body = "'${data.template_file.acm_config.rendered}' | ${path.module}/scripts/kubectl_wrapper.sh ${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl apply -f -" |
98 | | - destroy_cmd_entrypoint = "echo" |
99 | | - destroy_cmd_body = "'${data.template_file.acm_config.rendered}' | ${path.module}/scripts/kubectl_wrapper.sh ${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl delete -f -" |
| 19 | + source = "../k8s-operator-crd-support" |
| 20 | + |
| 21 | + cluster_name = var.cluster_name |
| 22 | + project_id = var.project_id |
| 23 | + location = var.location |
| 24 | + operator_path = var.operator_path |
| 25 | + sync_repo = var.sync_repo |
| 26 | + sync_branch = var.sync_branch |
| 27 | + policy_dir = var.policy_dir |
| 28 | + cluster_endpoint = var.cluster_endpoint |
| 29 | + create_ssh_key = var.create_ssh_key |
| 30 | + secret_type = var.secret_type |
| 31 | + ssh_auth_key = var.ssh_auth_key |
| 32 | + enable_policy_controller = var.enable_policy_controller |
| 33 | + install_template_library = var.install_template_library |
| 34 | + skip_gcloud_download = var.skip_gcloud_download |
| 35 | + |
| 36 | + operator_latest_manifest_url = "gs://config-management-release/released/latest/config-management-operator.yaml" |
| 37 | + operator_cr_template_path = "${path.module}/templates/acm-config.yml.tpl" |
| 38 | + operator_credential_namespace = "config-management-system" |
| 39 | + operator_credential_name = "git-creds" |
100 | 40 | } |
0 commit comments