对 Terraform 非常陌生,因此请给出您得到的所有简单建议。
我想使用/获取 Digital Ocean 新创建的 droplet IP 地址来设置 RKE-Cluster。我已经设置了一个 local_file 来在 RKE 模块中创建一个 txt 文件(这是一种非常奇怪的方法,但不确定我还能做什么。)当我尝试 terraform plan 时,我得到了
on modules/rke/rke.tf line 14, in data "template_file" "rkeip":
│ 14: template = file("${path.module}/rkeip.txt")
│ ├────────────────
│ │ path.module is "modules/rke"
│
│ Invalid value for "path" parameter: no file exists at modules/rke/rkeip.txt; this function works only with files
│ that are distributed as part of the configuration source code, so if this file will be created by a resource in
│ this configuration you must instead obtain this result from an attribute of that resource.
这是我的液滴文件的样子
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}
variable "do_token" {}
variable "ssh_key_name" {}
provider "digitalocean" {
token = var.do_token
}
data "digitalocean_ssh_key" "default" {
name = "${var.ssh_key_name}"
}
#this installs Docker
data "template_file" "cloud-yaml" {
template = file("${path.module}/modules/cloud.yaml")
}
resource "digitalocean_droplet" "terra" {
image = "ubuntu-20-04-x64"
name = "terra"
region = "sfo3"
size = "s-1vcpu-1gb"
ssh_keys = ["${data.digitalocean_ssh_key.default.fingerprint}"]
user_data = data.template_file.cloud-yaml.rendered
}
resource "local_file" "rkeip" {
content = "${digitalocean_droplet.terra.ipv4_address}"
filename = "${path.module}/modules/rke/rkeip.txt"
}
module "RKE" {
source = "./modules/rke/"
}
和我的 RKE 模块
terraform {
required_providers {
rke = {
source = "rancher/rke"
version = "1.2.4"
}
}
}
data "template_file" "rkeip" {
template = file("${path.module}/rkeip.txt")
}
provider "rke" {
log_file = "rke_debug.log"
}
resource "rke_cluster" "test" {
nodes {
address = data.template_file.rkeip.rendered
user = "root"
role = ["controlplane", "etcd", "worker"]
ssh_key = file("~/.ssh/id_rsa")
}
}
我尝试在 rke.tf 和 droplet.tf 中使用depends_on,但仍然出现同样的错误。