Исправление ошибки при terraform init
This commit is contained in:
@@ -42,6 +42,13 @@ The project should implement the following functionality:
|
|||||||
Use only null and local providers for this infrastructure. All operations should be performed using SSH connections and local-exec/remote-exec provisioners.
|
Use only null and local providers for this infrastructure. All operations should be performed using SSH connections and local-exec/remote-exec provisioners.
|
||||||
|
|
||||||
Please implement each file with complete, working code that follows Terraform best practices.
|
Please implement each file with complete, working code that follows Terraform best practices.
|
||||||
|
|
||||||
|
IMPORTANT CONSIDERATIONS:
|
||||||
|
1. Avoid duplicate local value declarations across files. If you create local values in env.tf, don't create variables with the same name in main.tf.
|
||||||
|
2. For destroy-time provisioners, remember that they can only reference attributes of the related resource using 'self', 'count.index', or 'each.key'. Store any paths or values needed during destroy in the resource's triggers, and then reference them using self.triggers.<name>.
|
||||||
|
3. Ensure proper dependency management between resources to maintain correct deployment sequence.
|
||||||
|
4. Use resource-specific variables in destroy provisioners rather than module-level locals.
|
||||||
|
5. Implement validation for input variables where appropriate.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Modifying the Infrastructure
|
## Modifying the Infrastructure
|
||||||
|
|||||||
@@ -1,13 +1,3 @@
|
|||||||
locals {
|
|
||||||
# Load environment variables if .env file exists
|
|
||||||
env_vars = fileexists("${path.module}/.env") ? {
|
|
||||||
for line in [
|
|
||||||
for line in split("\n", file("${path.module}/.env"))
|
|
||||||
: line if length(regexall("^[A-Za-z][A-Za-z0-9_]*=.*$", line)) > 0
|
|
||||||
] : split("=", line)[0] => join("=", slice(split("=", line), 1, length(split("=", line))))
|
|
||||||
} : {}
|
|
||||||
}
|
|
||||||
|
|
||||||
module "k3s_cluster" {
|
module "k3s_cluster" {
|
||||||
source = "../../modules/k3s-install"
|
source = "../../modules/k3s-install"
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ resource "null_resource" "setup_ssh_config" {
|
|||||||
worker_ips = join(",", var.worker_ips)
|
worker_ips = join(",", var.worker_ips)
|
||||||
ssh_user = var.ssh_user
|
ssh_user = var.ssh_user
|
||||||
ssh_private_key = var.ssh_private_key
|
ssh_private_key = var.ssh_private_key
|
||||||
|
ssh_config_path = local.ssh_config_path
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "local-exec" {
|
provisioner "local-exec" {
|
||||||
@@ -73,6 +74,7 @@ resource "null_resource" "install_k3s_server" {
|
|||||||
ssh_config_path = local.ssh_config_path
|
ssh_config_path = local.ssh_config_path
|
||||||
k3s_version = var.k3s_version
|
k3s_version = var.k3s_version
|
||||||
k3s_extra_args = var.k3s_extra_server_args
|
k3s_extra_args = var.k3s_extra_server_args
|
||||||
|
temporary_dir = local.temporary_dir
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install K3s server
|
# Install K3s server
|
||||||
@@ -104,7 +106,7 @@ resource "null_resource" "install_k3s_server" {
|
|||||||
|
|
||||||
inline = [
|
inline = [
|
||||||
"/usr/local/bin/k3s-uninstall.sh || true",
|
"/usr/local/bin/k3s-uninstall.sh || true",
|
||||||
"rm -rf ${local.temporary_dir} || true"
|
"rm -rf ${self.triggers.temporary_dir} || true"
|
||||||
]
|
]
|
||||||
on_failure = continue
|
on_failure = continue
|
||||||
}
|
}
|
||||||
@@ -233,6 +235,7 @@ resource "null_resource" "install_k3s_worker" {
|
|||||||
ssh_config_path = local.ssh_config_path
|
ssh_config_path = local.ssh_config_path
|
||||||
k3s_version = var.k3s_version
|
k3s_version = var.k3s_version
|
||||||
k3s_extra_args = var.k3s_extra_agent_args
|
k3s_extra_args = var.k3s_extra_agent_args
|
||||||
|
temporary_dir = local.temporary_dir
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install K3s agent on worker
|
# Install K3s agent on worker
|
||||||
@@ -263,7 +266,7 @@ resource "null_resource" "install_k3s_worker" {
|
|||||||
|
|
||||||
inline = [
|
inline = [
|
||||||
"/usr/local/bin/k3s-agent-uninstall.sh || true",
|
"/usr/local/bin/k3s-agent-uninstall.sh || true",
|
||||||
"rm -rf ${local.temporary_dir} || true"
|
"rm -rf ${self.triggers.temporary_dir} || true"
|
||||||
]
|
]
|
||||||
on_failure = continue
|
on_failure = continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user