Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gcloud module in ACM #442

Merged
merged 6 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ steps:
- converge beta-cluster-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify beta-cluster-local']
#- id: destroy beta-cluster-local
# waitFor:
# - verify beta-cluster-local
# name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
# args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy beta-cluster-local']
- id: destroy beta-cluster-local
waitFor:
- verify beta-cluster-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy beta-cluster-local']
- id: create deploy-service-local
waitFor:
- prepare
Expand Down
93 changes: 36 additions & 57 deletions modules/acm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,51 +38,39 @@ resource "tls_private_key" "git_creds" {
rsa_bits = 4096
}

resource "null_resource" "acm_operator_config" {
count = local.download_operator ? 1 : 0

provisioner "local-exec" {
command = "gsutil cp gs://config-management-release/released/latest/config-management-operator.yaml ${path.module}/config-management-operator.yaml"
}

provisioner "local-exec" {
when = destroy
command = "rm -f ${path.module}/config-management-operator.yaml"
}
module "acm_operator_config" {
source = "terraform-google-modules/gcloud/google"
version = "~> 0.5"
enabled = local.download_operator

create_cmd_entrypoint = "gsutil"
create_cmd_body = "cp gs://config-management-release/released/latest/config-management-operator.yaml ${path.module}/config-management-operator.yaml"
destroy_cmd_entrypoint = "rm"
destroy_cmd_body = "-f ${path.module}/config-management-operator.yaml"
}

resource "null_resource" "acm_operator" {
provisioner "local-exec" {
command = "${path.module}/scripts/kubectl_wrapper.sh ${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl apply -f ${local.operator_path}"
}
module "acm_operator" {
source = "terraform-google-modules/gcloud/google"
version = "~> 0.5"
module_depends_on = [module.acm_operator_config.wait, data.google_client_config.default.project, data.google_container_cluster.primary.name]
additional_components = ["kubectl"]

provisioner "local-exec" {
when = destroy
command = "${path.module}/scripts/kubectl_wrapper.sh ${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl delete -f ${local.operator_path}"
}

depends_on = [
null_resource.acm_operator_config,
data.google_client_config.default,
data.google_container_cluster.primary,
]
create_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh"
create_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl apply -f ${local.operator_path}"
destroy_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh"
destroy_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl delete -f ${local.operator_path}"
}

resource "null_resource" "git_creds_secret" {
count = var.create_ssh_key ? 1 : 0

provisioner "local-exec" {
command = "${path.module}/scripts/kubectl_wrapper.sh ${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}'"
}
module "git_creds_secret" {
source = "terraform-google-modules/gcloud/google"
version = "~> 0.5"
module_depends_on = [module.acm_operator.wait]
additional_components = ["kubectl"]

provisioner "local-exec" {
when = destroy
command = "${path.module}/scripts/kubectl_wrapper.sh ${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl delete secret git-creds -n=config-management-system"
}

depends_on = [
null_resource.acm_operator
]
create_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh"
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}'"
destroy_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh"
destroy_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl delete secret git-creds -n=config-management-system"
}

data "template_file" "acm_config" {
Expand All @@ -99,23 +87,14 @@ data "template_file" "acm_config" {
}
}

resource "null_resource" "acm_config" {
triggers = {
config = data.template_file.acm_config.rendered
}

provisioner "local-exec" {
command = "echo '${data.template_file.acm_config.rendered}' | ${path.module}/scripts/kubectl_wrapper.sh ${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl apply -f -"
}

provisioner "local-exec" {
when = destroy
command = "echo '${data.template_file.acm_config.rendered}' | ${path.module}/scripts/kubectl_wrapper.sh ${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl delete -f -"
}
module "acm_config" {
source = "terraform-google-modules/gcloud/google"
version = "~> 0.5"
module_depends_on = [module.acm_operator.wait, module.git_creds_secret.wait]
additional_components = ["kubectl"]

depends_on = [
null_resource.acm_operator,
null_resource.git_creds_secret,
]
create_cmd_entrypoint = "echo"
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 -"
destroy_cmd_entrypoint = "echo"
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 -"
}

2 changes: 1 addition & 1 deletion test/integration/beta_cluster/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
end

it "has the expected nodeMetadata conseal config" do
expect(data['nodeConfig']['workloadMetadataConfig']).to eq({
expect(data['nodeConfig']['workloadMetadataConfig']).to include({
"nodeMetadata" => 'EXPOSE',
})
end
Expand Down