Skip to content

Commit

Permalink
fix: store connection value directly into objects
Browse files Browse the repository at this point in the history
This avoid to depends on external values and remove "Deprecated" errors
  • Loading branch information
xunleii committed May 30, 2020
1 parent bdadd80 commit 97e1b2e
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 188 deletions.
194 changes: 100 additions & 94 deletions agent_nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ resource null_resource k3s_agents_install {
provisioner "remote-exec" {
inline = [
"INSTALL_K3S_VERSION=${local.k3s_version} sh /tmp/k3s-installer ${data.null_data_source.agents_metadata[each.key].outputs.flags}",
"until kubectl get nodes | grep -v '[WARN] No resources found'; do sleep 1; done"
"until kubectl get nodes; do sleep 5; done"
]
}
}
Expand All @@ -124,51 +124,53 @@ resource null_resource k3s_agents_annotation {

depends_on = [null_resource.k3s_agents_install]
triggers = {
agent_name = split(var.separator, each.key)[0]
annotation_name = split(var.separator, each.key)[1]
agent_name = data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name
annotation_name = split(var.separator, each.key)[1]
connection_json = base64encode(jsonencode(local.root_server_connection))

on_install = null_resource.k3s_agents_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value
}

connection {
type = local.root_server_connection.type

host = local.root_server_connection.host
user = local.root_server_connection.user
password = local.root_server_connection.password
port = local.root_server_connection.port
timeout = local.root_server_connection.timeout

script_path = local.root_server_connection.script_path
private_key = local.root_server_connection.private_key
certificate = local.root_server_connection.certificate
agent = local.root_server_connection.agent
agent_identity = local.root_server_connection.agent_identity
host_key = local.root_server_connection.host_key

https = local.root_server_connection.https
insecure = local.root_server_connection.insecure
use_ntlm = local.root_server_connection.use_ntlm
cacert = local.root_server_connection.cacert

bastion_host = local.root_server_connection.bastion_host
bastion_host_key = local.root_server_connection.bastion_host_key
bastion_port = local.root_server_connection.bastion_port
bastion_user = local.root_server_connection.bastion_user
bastion_password = local.root_server_connection.bastion_password
bastion_private_key = local.root_server_connection.bastion_private_key
bastion_certificate = local.root_server_connection.bastion_certificate
type = jsondecode(base64decode(self.triggers.connection_json)).type

host = jsondecode(base64decode(self.triggers.connection_json)).host
user = jsondecode(base64decode(self.triggers.connection_json)).user
password = jsondecode(base64decode(self.triggers.connection_json)).password
port = jsondecode(base64decode(self.triggers.connection_json)).port
timeout = jsondecode(base64decode(self.triggers.connection_json)).timeout

script_path = jsondecode(base64decode(self.triggers.connection_json)).script_path
private_key = jsondecode(base64decode(self.triggers.connection_json)).private_key
certificate = jsondecode(base64decode(self.triggers.connection_json)).certificate
agent = jsondecode(base64decode(self.triggers.connection_json)).agent
agent_identity = jsondecode(base64decode(self.triggers.connection_json)).agent_identity
host_key = jsondecode(base64decode(self.triggers.connection_json)).host_key

https = jsondecode(base64decode(self.triggers.connection_json)).https
insecure = jsondecode(base64decode(self.triggers.connection_json)).insecure
use_ntlm = jsondecode(base64decode(self.triggers.connection_json)).use_ntlm
cacert = jsondecode(base64decode(self.triggers.connection_json)).cacert

bastion_host = jsondecode(base64decode(self.triggers.connection_json)).bastion_host
bastion_host_key = jsondecode(base64decode(self.triggers.connection_json)).bastion_host_key
bastion_port = jsondecode(base64decode(self.triggers.connection_json)).bastion_port
bastion_user = jsondecode(base64decode(self.triggers.connection_json)).bastion_user
bastion_password = jsondecode(base64decode(self.triggers.connection_json)).bastion_password
bastion_private_key = jsondecode(base64decode(self.triggers.connection_json)).bastion_private_key
bastion_certificate = jsondecode(base64decode(self.triggers.connection_json)).bastion_certificate
}

provisioner remote-exec {
inline = [
"kubectl annotate --overwrite node ${data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name} ${split(var.separator, each.key)[1]}=${each.value}"]
"kubectl annotate --overwrite node ${self.triggers.agent_name} ${self.triggers.annotation_name}=${self.triggers.on_value_changes}"]
}

provisioner remote-exec {
when = destroy
inline = [
"kubectl annotate node ${data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name} ${split(var.separator, each.key)[1]}-"]
"kubectl annotate node ${self.triggers.agent_name} ${self.triggers.annotation_name}-"]
}
}

Expand All @@ -178,51 +180,53 @@ resource null_resource k3s_agents_label {

depends_on = [null_resource.k3s_agents_install]
triggers = {
agent_name = split(var.separator, each.key)[0]
label_name = split(var.separator, each.key)[1]
agent_name = data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name
label_name = split(var.separator, each.key)[1]
connection_json = base64encode(jsonencode(local.root_server_connection))

on_install = null_resource.k3s_agents_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value
}

connection {
type = local.root_server_connection.type

host = local.root_server_connection.host
user = local.root_server_connection.user
password = local.root_server_connection.password
port = local.root_server_connection.port
timeout = local.root_server_connection.timeout

script_path = local.root_server_connection.script_path
private_key = local.root_server_connection.private_key
certificate = local.root_server_connection.certificate
agent = local.root_server_connection.agent
agent_identity = local.root_server_connection.agent_identity
host_key = local.root_server_connection.host_key

https = local.root_server_connection.https
insecure = local.root_server_connection.insecure
use_ntlm = local.root_server_connection.use_ntlm
cacert = local.root_server_connection.cacert

bastion_host = local.root_server_connection.bastion_host
bastion_host_key = local.root_server_connection.bastion_host_key
bastion_port = local.root_server_connection.bastion_port
bastion_user = local.root_server_connection.bastion_user
bastion_password = local.root_server_connection.bastion_password
bastion_private_key = local.root_server_connection.bastion_private_key
bastion_certificate = local.root_server_connection.bastion_certificate
type = jsondecode(base64decode(self.triggers.connection_json)).type

host = jsondecode(base64decode(self.triggers.connection_json)).host
user = jsondecode(base64decode(self.triggers.connection_json)).user
password = jsondecode(base64decode(self.triggers.connection_json)).password
port = jsondecode(base64decode(self.triggers.connection_json)).port
timeout = jsondecode(base64decode(self.triggers.connection_json)).timeout

script_path = jsondecode(base64decode(self.triggers.connection_json)).script_path
private_key = jsondecode(base64decode(self.triggers.connection_json)).private_key
certificate = jsondecode(base64decode(self.triggers.connection_json)).certificate
agent = jsondecode(base64decode(self.triggers.connection_json)).agent
agent_identity = jsondecode(base64decode(self.triggers.connection_json)).agent_identity
host_key = jsondecode(base64decode(self.triggers.connection_json)).host_key

https = jsondecode(base64decode(self.triggers.connection_json)).https
insecure = jsondecode(base64decode(self.triggers.connection_json)).insecure
use_ntlm = jsondecode(base64decode(self.triggers.connection_json)).use_ntlm
cacert = jsondecode(base64decode(self.triggers.connection_json)).cacert

bastion_host = jsondecode(base64decode(self.triggers.connection_json)).bastion_host
bastion_host_key = jsondecode(base64decode(self.triggers.connection_json)).bastion_host_key
bastion_port = jsondecode(base64decode(self.triggers.connection_json)).bastion_port
bastion_user = jsondecode(base64decode(self.triggers.connection_json)).bastion_user
bastion_password = jsondecode(base64decode(self.triggers.connection_json)).bastion_password
bastion_private_key = jsondecode(base64decode(self.triggers.connection_json)).bastion_private_key
bastion_certificate = jsondecode(base64decode(self.triggers.connection_json)).bastion_certificate
}

provisioner remote-exec {
inline = [
"kubectl label --overwrite node ${data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name} ${split(var.separator, each.key)[1]}=${each.value}"]
"kubectl label --overwrite node ${self.triggers.agent_name} ${self.triggers.label_name}=${self.triggers.on_value_changes}"]
}

provisioner remote-exec {
when = destroy
inline = [
"kubectl label node ${data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name} ${split(var.separator, each.key)[1]}-"]
"kubectl label node ${self.triggers.agent_name} ${self.triggers.label_name}-"]
}
}

Expand All @@ -232,50 +236,52 @@ resource null_resource k3s_agents_taint {

depends_on = [null_resource.k3s_agents_install]
triggers = {
agent_name = split(var.separator, each.key)[0]
taint_name = split(var.separator, each.key)[1]
agent_name = data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name
taint_name = split(var.separator, each.key)[1]
connection_json = base64encode(jsonencode(local.root_server_connection))

on_install = null_resource.k3s_agents_install[split(var.separator, each.key)[0]].id
on_value_changes = each.value
}

connection {
type = local.root_server_connection.type

host = local.root_server_connection.host
user = local.root_server_connection.user
password = local.root_server_connection.password
port = local.root_server_connection.port
timeout = local.root_server_connection.timeout

script_path = local.root_server_connection.script_path
private_key = local.root_server_connection.private_key
certificate = local.root_server_connection.certificate
agent = local.root_server_connection.agent
agent_identity = local.root_server_connection.agent_identity
host_key = local.root_server_connection.host_key

https = local.root_server_connection.https
insecure = local.root_server_connection.insecure
use_ntlm = local.root_server_connection.use_ntlm
cacert = local.root_server_connection.cacert

bastion_host = local.root_server_connection.bastion_host
bastion_host_key = local.root_server_connection.bastion_host_key
bastion_port = local.root_server_connection.bastion_port
bastion_user = local.root_server_connection.bastion_user
bastion_password = local.root_server_connection.bastion_password
bastion_private_key = local.root_server_connection.bastion_private_key
bastion_certificate = local.root_server_connection.bastion_certificate
type = jsondecode(base64decode(self.triggers.connection_json)).type

host = jsondecode(base64decode(self.triggers.connection_json)).host
user = jsondecode(base64decode(self.triggers.connection_json)).user
password = jsondecode(base64decode(self.triggers.connection_json)).password
port = jsondecode(base64decode(self.triggers.connection_json)).port
timeout = jsondecode(base64decode(self.triggers.connection_json)).timeout

script_path = jsondecode(base64decode(self.triggers.connection_json)).script_path
private_key = jsondecode(base64decode(self.triggers.connection_json)).private_key
certificate = jsondecode(base64decode(self.triggers.connection_json)).certificate
agent = jsondecode(base64decode(self.triggers.connection_json)).agent
agent_identity = jsondecode(base64decode(self.triggers.connection_json)).agent_identity
host_key = jsondecode(base64decode(self.triggers.connection_json)).host_key

https = jsondecode(base64decode(self.triggers.connection_json)).https
insecure = jsondecode(base64decode(self.triggers.connection_json)).insecure
use_ntlm = jsondecode(base64decode(self.triggers.connection_json)).use_ntlm
cacert = jsondecode(base64decode(self.triggers.connection_json)).cacert

bastion_host = jsondecode(base64decode(self.triggers.connection_json)).bastion_host
bastion_host_key = jsondecode(base64decode(self.triggers.connection_json)).bastion_host_key
bastion_port = jsondecode(base64decode(self.triggers.connection_json)).bastion_port
bastion_user = jsondecode(base64decode(self.triggers.connection_json)).bastion_user
bastion_password = jsondecode(base64decode(self.triggers.connection_json)).bastion_password
bastion_private_key = jsondecode(base64decode(self.triggers.connection_json)).bastion_private_key
bastion_certificate = jsondecode(base64decode(self.triggers.connection_json)).bastion_certificate
}

provisioner remote-exec {
inline = [
"kubectl taint node ${data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name} ${split(var.separator, each.key)[1]}=${each.value} --overwrite"]
"kubectl taint node ${self.triggers.agent_name} ${self.triggers.taint_name}=${self.triggers.on_value_changes} --overwrite"]
}

provisioner remote-exec {
when = destroy
inline = [
"kubectl taint node ${data.null_data_source.agents_metadata[split(var.separator, each.key)[0]].outputs.name} ${split(var.separator, each.key)[1]}-"]
"kubectl taint node ${self.triggers.agent_name} ${self.triggers.taint_name}-"]
}
}
Loading

0 comments on commit 97e1b2e

Please sign in to comment.