我正在 Azure 中部署 Web 应用程序,我想忽略对site_config块中scm_type属性的更改。
在部署期间,scm_type属性设置为None,稍后我们将在 Azure 门户中将其更改为不同的内容。
我当前的 TF 代码如下所示:
resource "azurerm_app_service" "web_app" {
count = length(var.app_names)
name = var.app_names[count.index]
location = data.azurerm_resource_group.app_resource_group.location
resource_group_name = data.azurerm_resource_group.app_resource_group.name
app_service_plan_id = azurerm_app_service_plan.app_plan.id
tags = var.tags
app_settings = var.app_settings[count.index]
site_config {
always_on = true
websockets_enabled = var.websockets_enabled[count.index]
use_32_bit_worker_process = var.use_32_bit_worker_process
scm_type = "None"
}
lifecycle {
ignore_changes = [
site_config.0.scm_type
]
}
}
Run Code Online (Sandbox Code Playgroud)
我希望 terraform 计划在基础设施更新期间忽略scm_type 的变化,但它试图将其恢复为None。来自地形计划输出的行:
~ scm_type …
我正在开发一个 terraform 项目。在其中,我想要一个文件包含许多变量。我希望可以从项目的任何模块访问这些变量。我已经查看了文档和 udemy 课程,但仍然不知道如何做到这一点。在 Terraform 中如何做到这一点?谢谢!
当我使用 terraform 创建 vpc 流日志模块到 s3 存储桶时,它会抛出如下错误:
An argument named "flow_log_destination_type" is not expected here.
An argument named "flow_log_destination_arn" is not expected here.
Run Code Online (Sandbox Code Playgroud)
在 Terraform 文档中,我可以看到要填写的详细信息,例如log_destination_type & log_destination_arn,并且我在 GitHub 上找到了一些文档,这些文档完全相同,但在尝试时它对我不起作用
产生以下错误:
Error: Unsupported argument
on main.tf line 52, in module "vpc_with_flow_logs_s3_bucket":
52: flow_log_destination_type = "s3"
An argument named "flow_log_destination_type" is not expected here.
Error: Unsupported argument
on main.tf line 53, in module "vpc_with_flow_logs_s3_bucket":
53: flow_log_destination_arn = "${aws_s3_bucket.terra-test2-lifecycle.arn}"
An argument named "flow_log_destination_arn" is not expected here.
Error: Unsupported argument …Run Code Online (Sandbox Code Playgroud) 有没有办法在Terraform中使用这样的东西?
count ="$ {var.I_am_true}"&&"$ {var.I_am_false}"
我试图在 Terraform 中做一个相当简单的任务,但它不起作用:
变量:
hosted_zone = "example.com"
domain = "my.${var.hosted_zone}"
Run Code Online (Sandbox Code Playgroud)
route_53_record:
resource "aws_route53_record" "regional" {
zone_id = "${data.aws_route53_zone.selected.zone_id}"
name = "${var.domain}"
type = "A"
ttl = "300"
records = ["4.4.4.4"]
}
Run Code Online (Sandbox Code Playgroud)
当我跑步时,terraform plan我得到了这个:
+ aws_route53_record.regional
id: <computed>
allow_overwrite: "true"
fqdn: <computed>
name: "my.${var.hosted_zone}"
records.#: "1"
records.3178571330: "4.4.4.4"
ttl: "300"
type: "A"
zone_id: "REDACTED"
Run Code Online (Sandbox Code Playgroud)
域应该是my.example.com. 如何加入变量 hosts_zoned 和一个字符串以形成域?
我正在尝试将文件从 A 帐户中的存储桶复制到 B 帐户中的另一个存储桶。当我尝试使用命令同步文件时
aws s3 sync s3://BUCKET_A s3://BUCKET_B
它返回以下输出:
copy failed: s3://BUCKET_A to s3://BUCKET_B An error occurred (AccessDenied) when calling the CopyObject operation: Access Denied
Run Code Online (Sandbox Code Playgroud)
这是附加到在 B 帐户中创建的用户的策略(将从存储桶 A 中复制文件):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::BUCKET_A",
"arn:aws:s3::: BUCKET_A/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::BUCKET_B",
"arn:aws:s3:::BUCKET_B/*"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
也许我缺少一些许可?CopyObject我在我的用户/存储桶策略中找不到添加权限
我需要 terraform 来访问我的 S3 存储桶,但它无法在指定区域找到存储桶。
我的主要.tf:
provider "aws" {
region = "eu-west-2"
}
terraform {
backend "s3" {
bucket = "xyz-state-blog"
key = "dev/terraform"
region = "eu-west-2"
}
}
locals {
azs = ["eu-west-2a", "eu-west-2b", "eu-west-2c"]
environment = "dev"
kops_state_bucket_name = "${local.environment}-kops-state"
// Needs to be a FQDN
kubernetes_cluster_name = "k8s-dev0.domain.com"
ingress_ips = ["10.0.0.100/32", "10.0.0.101/32"]
vpc_name = "${local.environment}-vpc"
tags = {
environment = "${local.environment}"
terraform = true
}
}
data "aws_region" "current" {}
Run Code Online (Sandbox Code Playgroud)
以下是我收到terraform init命令的错误:
Error inspecting states …Run Code Online (Sandbox Code Playgroud) 我aws_cloudwatch_event_target在 terraform 中定义了一个从cloudwatch. 该input字段是事件参数,例如:
resource "aws_cloudwatch_event_target" "data" {
rule = "${aws_cloudwatch_event_rule.scheduler.name}"
target_id = "finance_producer_cloudwatch"
arn = "${aws_lambda_function.finance_data_producer.arn}"
input = "{\"test\": [\"111\"]}"
}
Run Code Online (Sandbox Code Playgroud)
我想知道如何input从外部文件加载json 数据。
我正在尝试在 AWS Lambda 层上运行 python 函数,但我没有找到有关 terraform 的任何文档来使用 AWS 提供的 lambda 层。如何使用 AWS 提供的 lambda 层 AWSLambda-Python27-SciPy1x和运行时Python 2.7?
#----compute/lambda.tf----
data "archive_file" "lambda_zip" {
type = "zip"
source_file = "index.py"
output_path = "check_foo.zip"
}
resource "aws_lambda_function" "check_foo" {
filename = "check_foo.zip"
function_name = "checkFoo"
role = "${aws_iam_role.iam_for_lambda_tf.arn}"
handler = "index.handler"
source_code_hash = "${data.archive_file.lambda_zip.output_base64sha256}"
# i want to use lambda layer - AWSLambda-Python27-SciPy1x and run this function on it
runtime = "python2.7"
}
Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-lambda terraform terraform-provider-aws
示例:在 Azure 中,我正在同一区域中部署多个资源组、托管磁盘、网络接口等。
我想声明一个“区域”原语(“常量”),所有这些资源都将引用它。其中哪一个遵循惯例?
a)变量.tf:
variable "region" {
type = string
default = "a-place"
}
Run Code Online (Sandbox Code Playgroud)
b) 当地人.tf
locals {
region = "a-place"
}
Run Code Online (Sandbox Code Playgroud)
我自然会选择声明为本地人。仅当我期望从环境变量、命令行获得(或被覆盖)一个值,或者我正在创建一个模块时,我才会使用变量。然而,我还没有在任何示例中看到 local 被用于“声明常量”,这使我认为存在使用范围非常有限的 local 的约定(例如,主要用于创建可与 和count结构一起使用的结构for_each)。
在有人将此标记为基于意见之前掩饰我的背部:我问的是公约是什么,而不是您认为公约应该是什么。
后续问题:如果此示例涵盖 IP 地址、资源名称前缀等而不是区域,答案是否会有所不同?(该公约是否只涵盖特定领域?)