diff --git a/modules/aws/README.md b/modules/aws/README.md index 33e5b2f..6b3af68 100644 --- a/modules/aws/README.md +++ b/modules/aws/README.md @@ -53,6 +53,7 @@ No modules. | [aws_security_group_rule.ssh](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource | | [local_sensitive_file.signing-key](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource | | [null_resource.signing-key-fingerprint](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.update_kernel](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [tls_private_key.rsa-4096](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource | | [http_http.cblogin](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | | [http_http.my-public-ip](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | diff --git a/modules/aws/terraform.tf b/modules/aws/terraform.tf index b51fb48..f9f0894 100644 --- a/modules/aws/terraform.tf +++ b/modules/aws/terraform.tf @@ -5,5 +5,8 @@ terraform { source = "hashicorp/aws" version = ">= 6.0" } + null = { + source = "hashicorp/null" + } } } \ No newline at end of file diff --git a/modules/aws/update-kernel.tf b/modules/aws/update-kernel.tf new file mode 100644 index 0000000..409f956 --- /dev/null +++ b/modules/aws/update-kernel.tf @@ -0,0 +1,23 @@ +resource "null_resource" "update_kernel" { + depends_on = [aws_instance.cvm] + + triggers = { + instance_id = aws_instance.cvm.id + } + + connection { + type = "ssh" + user = var.cvm_username + private_key = file(trimsuffix(var.cvm_ssh_pubkey, ".pub")) + host = aws_instance.cvm.public_ip + } + + provisioner "remote-exec" { + inline = [ + "cloud-init status --wait", + "sudo env DEBIAN_FRONTEND=noninteractive apt-get update", + "sudo env DEBIAN_FRONTEND=noninteractive apt-get install --yes --install-recommends linux-generic", + "if [ -f /var/run/reboot-required ]; then sudo shutdown -r +1 'Kernel update completed'; fi", + ] + } +} diff --git a/modules/azure/README.md b/modules/azure/README.md index 0f62e0e..8b4a960 100644 --- a/modules/azure/README.md +++ b/modules/azure/README.md @@ -58,6 +58,7 @@ No modules. | [azurerm_virtual_network.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) | resource | | [local_sensitive_file.signing-key](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource | | [null_resource.signing-key-fingerprint](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.update_kernel](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [tls_private_key.rsa-4096](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource | | [azurerm_resource_group.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source | | [http_http.cblogin](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | diff --git a/modules/azure/terraform.tf b/modules/azure/terraform.tf index 3dd083c..1248c4b 100644 --- a/modules/azure/terraform.tf +++ b/modules/azure/terraform.tf @@ -2,11 +2,18 @@ terraform { required_version = ">= 1.0" required_providers { azurerm = { - source = "hashicorp/azurerm" + source = "hashicorp/azurerm" version = ">= 4.50" } time = { source = "hashicorp/time" } + null = { + source = "hashicorp/null" + } } +} + +provider "azurerm" { + features {} } \ No newline at end of file diff --git a/modules/azure/update-kernel.tf b/modules/azure/update-kernel.tf new file mode 100644 index 0000000..da987db --- /dev/null +++ b/modules/azure/update-kernel.tf @@ -0,0 +1,23 @@ +resource "null_resource" "update_kernel" { + depends_on = [azurerm_linux_virtual_machine.cvm] + + triggers = { + instance_id = azurerm_linux_virtual_machine.cvm.id + } + + connection { + type = "ssh" + user = var.cvm_username + private_key = file(trimsuffix(var.cvm_ssh_pubkey, ".pub")) + host = azurerm_linux_virtual_machine.cvm.public_ip_address + } + + provisioner "remote-exec" { + inline = [ + "cloud-init status --wait", + "sudo env DEBIAN_FRONTEND=noninteractive apt-get update", + "sudo env DEBIAN_FRONTEND=noninteractive apt-get install --yes --install-recommends linux-generic", + "if [ -f /var/run/reboot-required ]; then sudo shutdown -r +1 'Kernel update completed'; fi", + ] + } +} diff --git a/modules/gcp/README.md b/modules/gcp/README.md index 00b9684..5aeac68 100644 --- a/modules/gcp/README.md +++ b/modules/gcp/README.md @@ -56,6 +56,7 @@ No modules. | [google_compute_network.cvm](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network) | resource | | [local_sensitive_file.signing-key](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/sensitive_file) | resource | | [null_resource.signing-key-fingerprint](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.update_kernel](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [tls_private_key.rsa-4096](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource | | [http_http.cblogin](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | | [http_http.my-public-ip](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | diff --git a/modules/gcp/terraform.tf b/modules/gcp/terraform.tf index 44e4df2..c76d1eb 100644 --- a/modules/gcp/terraform.tf +++ b/modules/gcp/terraform.tf @@ -2,8 +2,11 @@ terraform { required_version = ">= 1.0" required_providers { google = { - source = "hashicorp/google" + source = "hashicorp/google" version = ">= 7.0" } + null = { + source = "hashicorp/null" + } } } \ No newline at end of file diff --git a/modules/gcp/update-kernel.tf b/modules/gcp/update-kernel.tf new file mode 100644 index 0000000..0eab7f2 --- /dev/null +++ b/modules/gcp/update-kernel.tf @@ -0,0 +1,23 @@ +resource "null_resource" "update_kernel" { + depends_on = [google_compute_instance.cvm] + + triggers = { + instance_id = google_compute_instance.cvm.id + } + + connection { + type = "ssh" + user = var.cvm_username + private_key = file(trimsuffix(var.cvm_ssh_pubkey, ".pub")) + host = google_compute_instance.cvm.network_interface[0].access_config[0].nat_ip + } + + provisioner "remote-exec" { + inline = [ + "cloud-init status --wait", + "sudo env DEBIAN_FRONTEND=noninteractive apt-get update", + "sudo env DEBIAN_FRONTEND=noninteractive apt-get install --yes --install-recommends linux-generic", + "if [ -f /var/run/reboot-required ]; then sudo shutdown -r +1 'Kernel update completed'; fi", + ] + } +}