我想编写一个 terraform 模块来创建 dynamoDb 表。这些属性应该从.tfvars默认变量中读取,而不是像此处的.tf资源指南中那样已命名
为了进一步解释,假设使用属性列表来实现此伪代码:
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "GameScores"
... #Other required feilds
...
...
# attributes is a list of names
for(attribute_name:${length(var.attributes)}){
attribute {
name = "${var.attributes[i]}"
type = "N"
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何在 terraform plan/apply 期间迭代属性列表并创建属性{ } ?属性块的数量不能像 terraform 文档中所示的那样是静态的,并且它们的名称必须从变量中读取。
我是 Terraform 新手,有没有任何直接的方法可以使用 Terraform 管理和创建 Google Cloud Composer 环境?
我检查了 GCP 支持的组件列表,似乎 Google Cloud Composer 目前还不存在。作为解决办法,我正在考虑创建一个 shell 脚本,包括所需的 gcloud Composer cli 命令并使用 Terraform 运行它,这是正确的方法吗?请提出替代方案。
我曾经设置了 terraform 并做了terraform init并且terraform apply(以及plan)并且它们工作得很好。然后我不小心删除了terraform.tfstate我的 s3 存储桶中的文件。所以我重做terraform init,效果很好,但遇到了一些麻烦terraform apply。我遇到了一堆错误
aws_dynamodb_table.****: ResourceInUseException: Table already exists: ****
status code: 400, request id: ****
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
附:我试过了terraform refresh。它不能解决问题。
太感谢了。
我正在创建一个 EC2 实例并为其加载一些“启动时”脚本以及安装所需的软件。这将成为启动新实例时要使用的基础映像。
创建后,我将创建一个 AMI。此时,无需保留用于创建 AMI 的 EC2 映像。
所以,顺序是:
Create EC2
Install packages
Configure packages
Create AMI
Destroy EC2
Run Code Online (Sandbox Code Playgroud)
如何告诉 Terraform 在最后一步中删除 EC2?
amazon-ec2 amazon-web-services terraform terraform-provider-aws
我正在尝试创建一个包含多个安全规则的网络安全组。这个想法是创建一个列表变量(端口范围)并在 .tf 文件中插入列表项。下面的脚本抛出一个错误“priority.
"Error: azurerm_network_security_group.k8hway: security_rule.0: invalid or unknown key: count"
Run Code Online (Sandbox Code Playgroud)
下面是 Terraform 代码:
resource "azurerm_network_security_group" "NSG" {
name = "NSG-Demo"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
security_rule {
count = "${length(var.inbound_port_ranges)}"
name = "sg-rule-${count.index}"
direction = "Inbound"
access = "Allow"
priority = "(100 * (${count.index} + 1))"
source_address_prefix = "*"
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = "${element(var.inbound_port_ranges, count.index)}"
protocol = "TCP"
}
}
Run Code Online (Sandbox Code Playgroud) 我参考了github代码。请找到下面的URL
我修改了脚本并执行了 terraform init。我收到以下错误。
读取 azurerm_network_interface[main] 的配置时出错:在 1:18 处解析错误:预期为“)”,但发现为“.”[0m
我的脚本:
# Configure the Microsoft Azure Provider
provider "azurerm" {
subscription_id = "xxxxxxxx"
client_id = "xxxxxxxx"
client_secret = "xxxxxxxx"
tenant_id = "xxxxxxxx"
}
# Locate the existing custom/golden image
data "azurerm_image" "search" {
name = "AZLXSPTDEVOPS01_Image"
resource_group_name = "RG-PLATFORM"
}
output "image_id" {
value = "/subscriptions/4f5c9f2a-3584-4bbd-a26e-bbf69ffbfbe6/resourceGroups/RG-EASTUS-SPT-PLATFORM/providers/Microsoft.Compute/images/AZLXSPTDEVOPS01_Image"
}
# Create a Resource Group for the new Virtual Machine.
resource "azurerm_resource_group" "main" {
name = "RG-TEST"
location = "eastus"
}
# Create …Run Code Online (Sandbox Code Playgroud) 我有以下azurerm_function_appterform 部分:
resource "azurerm_function_app" "main" {
name = "${var.storage_function_name}"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
app_service_plan_id = "${azurerm_app_service_plan.main.id}"
storage_connection_string = "${azurerm_storage_account.main.primary_connection_string}"
https_only = true
app_settings {
"APPINSIGHTS_INSTRUMENTATIONKEY" = "${azurerm_application_insights.main.instrumentation_key}"
}
}
Run Code Online (Sandbox Code Playgroud)
如何指定操作系统是linux?
这里没有使用任何云资源。 我是使用 Terraform 的新手。
我正在使用 Terraform 0.12 在服务器上安装软件。该软件期望远程 MariaDB 数据库为空,这是手动完成的。(如果数据库不为空,软件将导致 Terraform 中止。)现在都是虚拟数据。
我想在销毁数据库之前使用 Terraform mysqldump数据库,以便可以在terraform apply. 最终,在软件升级之间需要保留数据库的内容。
我有 Terraform 代码来创建和销毁服务器并安装软件。效果很好。目前数据库是手动处理的。当取消注释时,连接到数据库的 Terraform 代码可以工作,但我没有足够的经验来执行除此之外的任何操作。
provider "mysql" {
endpoint = "10.0.1.2"
username = "terraform"
password = "changeme"
version = "~> 1.6"
}
resource "mysql_database" "default" {
default_character_set = "utf8"
name = "terraform_test_db"
}
Run Code Online (Sandbox Code Playgroud) 尝试使用此处列出的 Virtualbox 提供程序插件 ( https://github.com/terra-farm/terraform-provider-virtualbox )让 Terraform 在 Windows 10 64 位上工作。我已经验证该插件存在于 %APPData%/terraform.d/plugins/windows_amd64 中,但它说它不存在。已尝试以下但没有运气
没有一个有效。它的行为就好像它所说的放置插件的文件夹和它所查找的位置不匹配,但我怀疑类似的东西是否会使其发布,所以我不知道为什么它没有看到该插件。
Terraform 是最新版本。在我的 example.tf 中使用以下内容(我执行 terraform 表单的目录中唯一的 tf 文件)
resource "virtualbox_vm" "node" {
count = 2
name = format("node-%02d", count.index + 1)
image = "https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20180903.0.0/providers/virtualbox.box"
cpus = 2
memory = "512 mib"
user_data = file("user_data")
network_adapter {
type = "hostonly"
host_interface = "vboxnet1"
}
}
output "IPAddr" {
value = element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 terraform 创建一个数据库,这对于一个糟糕的查询来说似乎非常复杂......
请问你能帮帮我吗?
我已经尝试过 null_resource 与 local-exec 和数据“外部”Python ...我想我看错了方式
ex 在 terraform 0.12 中不起作用
resource "null_resource" "create-endpoint" {
provisioner "local-exec" {
query = <<EOF
{
CREATE EXTERNAL TABLE `dashboard_loading_time`(
`timestamp_iso` string,
`app_identification` struct<service:string,app_name:string,app_type:string,stage:string>,
`user` struct<api_gateway_key:struct<id:string,name:string>,mashery_key:struct<id:string,name:string>,employee:struct<id:string,name:string>>,
`action` struct<action_type:string,path:string>,
`result` struct<status:string,http_status:string,response:struct<response:string>>)
PARTITIONED BY (
`year` int)
ROW FORMAT SERDE
'org.openx.data.jsonserde.JsonSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
's3://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/dev'
}
EOF
command = "aws athena start-query-execution --query-string "query""
}
}
Run Code Online (Sandbox Code Playgroud)
我想找到使用 terraform 执行此操作的最简单方法。
terraform ×10
azure ×3
amazon-ec2 ×1
aws-glue ×1
azure-cli ×1
creation ×1
database ×1
image ×1
mariadb ×1
mysql ×1
virtualbox ×1
windows-10 ×1