问题标签 [terraform]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1095 浏览

shell - Terraform 插值错误:替换错误

我正在尝试在 AWS 上使用 terraform 设置 puppet 主从设置。我有 2 个 EC2 实例,一个是主实例,第二个是从属实例。

我已将脚本编写为 setup.tf

我用于安装 puppet master 和 slave 的脚本是:

对于奴隶:

当我运行这个脚本时,我得到了从 shell 脚本中的插值错误:

{aws_instance.puppet_master.private_ip}:插值错误

我想用主私有 IP 代替这个插值字符串,以便在我需要主 IP 的木偶中设置主从。

有什么解决方法吗?

0 投票
1 回答
1260 浏览

networking - Terraform 和 docker 网络

我已经用这样的 docker 配置器定义了一个 terraform 配方:

我希望容器将仅连接到动态创建的网络(使用变量 customer_name)。但我看到的是容器也连接到默认的桥接网络(172.17.0.0/16),所以它连接到两个网络。

有没有办法在 terraform 中配置容器,使其仅连接到我在网络列表中指定的网络?

0 投票
1 回答
2899 浏览

amazon-web-services - Terraform 在尝试获取多个实例的 IP 地址时停止?

所以我使用 terraform 来配置 ec2 实例和 openstack 实例。我正在尝试引用我正在创建的实例的 IP 地址,因为我需要运行使用它们的命令(以设置领事)。然而,在添加对这些变量的引用之后,terraform 就会停止运行,并且在我运行 a terraform applyor后完全什么都不做terraform plan

这是我要运行的资源块的示例:

更新:所以我尝试使用我的 openstack 云运行类似的命令并遇到了同样的问题:

所以我发现如果我只使用一个 IP 地址,那么在创建第一个实例之前甚至不会创建其他实例,如下面的块中所示:

我需要同时创建我的所有实例,并在创建后立即访问所有其他实例的 IP 地址。

0 投票
1 回答
1210 浏览

ssh - 集成 Terraform 和 Serverspec

我正在使用 Terraform 自动构建基于 AWS EC2 的 docker 主机,然后使用其远程 exec 选项下载 docker 文件,构建并运行它。

我希望将其与 Serverspec 集成,但我正在努力解决两件事:

  1. 将新创建的 AWS EC2 实例的外部 dns 传递给 Serverspec 的最佳方式。

  2. 如何为 Serverspec 配置 SSH 选项,以便它使用 ec2-user 账户在 Amazon Linux AMI 上正确执行。

我通常会使用预定义的密钥对连接到 EC2 实例,并且从不使用密码,但是 ServerSpec 似乎使用 sudo -p 格式在服务器上运行命令。

非常感谢任何建议。

spec_helper.rb 的内容

还使用如下编辑的 rakefile 来强制纠正 EC2 外部 dns(屏蔽):

0 投票
3 回答
13383 浏览

sudo - 如何在 terraform 中运行 sudo 命令?

我的问题类似于这个 git hub 帖子,但不幸的是它没有解决:

https://github.com/hashicorp/terraform/issues/550

provisioner "remote-exec" { }我想要一种简单的方法来为在我的 terraform 脚本块中运行的命令提供 sudo 权限。

我来自 ansible 背景,在我的 ansible-playbook 运行命令中sudo: yes使用可选选项时,该选项允许任何命令 ansible 运行以 sudo 权限运行命令。--ask-sudo-pass我想在provisioner "remote-exec"我的 terraform 脚本块中做类似的事情。

这是provisioner "remote-exec"我要运行的块:

当我在我的中运行它时,我terraform apply看到以下行出现在此命令的输出中:

然后它只是给了我无限数量的这些:

那么我该如何解决这个问题并让 terraform 运行 sudo 命令呢?

注意:我的provisioner "remote-exec"块的连接不能是 root,所以即使这是一个简单的解决方案,它也不是我可以使用的。

0 投票
2 回答
7541 浏览

openstack - Terraform,如何在现有资源上运行配置器?

我的问题类似于这个 git hub 帖子:

https://github.com/hashicorp/terraform/issues/745

它也与我的另一个堆栈交换帖子有关:

Terraform 在尝试获取多个实例的 IP 地址时停止?

我正在尝试引导多台服务器,并且需要在我的实例上运行一些命令,这些命令需要所有其他实例的 IP 地址。但是,在创建新实例之前,我无法访问保存新创建实例的 IP 地址的变量。因此,当我尝试运行这样的provisioner "remote-exec"块时:

什么都没有发生,因为所有实例都在等待所有其他实例完成创建,所以一开始什么都没有创建。所以我需要一种方法来创建我的资源,然后在创建provisioner "remote-exec"它们之后运行我的块命令,并且 terraform 可以访问我所有实例的 IP 地址。

0 投票
1 回答
15462 浏览

provisioning - Terraform,正在寻找一种在命令中使用双引号的简单方法?

"我需要一种在provisioner "remote-exec"terraform 脚本块中使用常规引号的简单方法。只有"对我想做的事情有用,而只是尝试\"是行不通的。让 terraform 从字面上解释我的命令的最简单方法是什么。供参考的是我正在尝试运行的内容:

0 投票
2 回答
11211 浏览

terraform - Terraform: invalid characters in heredoc anchor

I am trying to use a multiline string in the provisioner "remote-exec" block of my terraform script. Yet whenever I use the EOT syntax as outlined in the documentation and various examples I get an error that complains about having: invalid characters in heredoc anchor.

Here is an example of a simple provisioner "remote-exec" that received this error (both types of EOT receive this error when attempted separately):

Update: Here is the working solution, read carefully if you are having this issue because terraform is very picky when it comes to EOF:

Note that if you want to use EOF all the commands you use in a provisioner "remote-exec" block must be inside the EOF. You cannot have both EOF and non EOF its one or the other.

The first line of EOF must begin like this, and you cannot have any whitespace in this line after <<EOF or else it will complain about having invalid characters in heredoc anchor:

Your EOF must then end like this with the EOF at the same indentation as the ]

0 投票
5 回答
14204 浏览

terraform - 在终端中打印 terraform 模板呈现的输出?

在 terraform 文档中,它展示了如何使用模板。有没有办法在控制台上记录这个渲染输出?

https://www.terraform.io/docs/configuration/interpolation.html#templates

0 投票
2 回答
5813 浏览

provisioning - Terraform,如何在配置时忽略失败的服务器?

我正在使用私有 openstack 云运行 terraform 来引导新服务器。当我在最繁忙的操作时间(工作日的下午)尝试创建新服务器(使用任何方法)时,通常有一半的服务器会失败(这与 terraform 无关)。问题是,当我尝试配置的其中一个服务器无法完成一个provisioner "remote-exec"没有错误的块时(因为我的私有云),我的整个过程都terraform apply停止了。

我希望 terraform 在我运行时完全忽略这些失败的服务器,terraform apply这样如果我尝试配置 20 个服务器并且其中只有一个成功启动,那么该服务器将运行我在资源块中指定的所有命令。

有没有类似的东西ignore_failed_resources = true可以添加到我的资源中,以便 terraform 将忽略失败的服务器并运行成功的服务器以完成?