|
| 1 | +resource "null_resource" "this" { |
| 2 | + triggers = { |
| 3 | + connection = jsonencode(var.connection) |
| 4 | + create = var.create |
| 5 | + destroy = var.destroy |
| 6 | + } |
| 7 | + |
| 8 | + connection { |
| 9 | + type = try(jsondecode(self.triggers.connection).type, null) |
| 10 | + host = try(jsondecode(self.triggers.connection).host, null) |
| 11 | + port = try(jsondecode(self.triggers.connection).port, null) |
| 12 | + user = try(jsondecode(self.triggers.connection).user, null) |
| 13 | + password = try(jsondecode(self.triggers.connection).password, null) |
| 14 | + timeout = try(jsondecode(self.triggers.connection).timeout, null) |
| 15 | + script_path = try(jsondecode(self.triggers.connection).script_path, null) |
| 16 | + private_key = try(jsondecode(self.triggers.connection).private_key, null) |
| 17 | + certificate = try(jsondecode(self.triggers.connection).certificate, null) |
| 18 | + agent = try(jsondecode(self.triggers.connection).agent, null) |
| 19 | + agent_identity = try(jsondecode(self.triggers.connection).agent_identity, null) |
| 20 | + host_key = try(jsondecode(self.triggers.connection).host_key, null) |
| 21 | + https = try(jsondecode(self.triggers.connection).https, null) |
| 22 | + insecure = try(jsondecode(self.triggers.connection).insecure, null) |
| 23 | + use_ntlm = try(jsondecode(self.triggers.connection).use_ntlm, null) |
| 24 | + cacert = try(jsondecode(self.triggers.connection).cacert, null) |
| 25 | + bastion_host = try(jsondecode(self.triggers.connection).bastion_host, null) |
| 26 | + bastion_host_key = try(jsondecode(self.triggers.connection).bastion_host_key, null) |
| 27 | + bastion_port = try(jsondecode(self.triggers.connection).bastion_port, null) |
| 28 | + bastion_user = try(jsondecode(self.triggers.connection).bastion_user, null) |
| 29 | + bastion_password = try(jsondecode(self.triggers.connection).bastion_password, null) |
| 30 | + bastion_private_key = try(jsondecode(self.triggers.connection).bastion_private_key, null) |
| 31 | + bastion_certificate = try(jsondecode(self.triggers.connection).bastion_certificate, null) |
| 32 | + } |
| 33 | + |
| 34 | + provisioner "remote-exec" { |
| 35 | + when = create |
| 36 | + inline = [ |
| 37 | + "echo '${try(jsondecode(self.triggers.connection).password, "")}' | sudo -S -v", |
| 38 | + "echo ${base64encode(self.triggers.create)} | base64 -d | sudo sh" |
| 39 | + ] |
| 40 | + } |
| 41 | + |
| 42 | + provisioner "remote-exec" { |
| 43 | + when = destroy |
| 44 | + inline = [ |
| 45 | + "echo '${try(jsondecode(self.triggers.connection).password, "")}' | sudo -S -v", |
| 46 | + "echo ${base64encode(self.triggers.destroy)} | base64 -d | sudo sh" |
| 47 | + ] |
| 48 | + } |
| 49 | +} |
0 commit comments