在我的 terraform 脚本中,我有以下资源 -
resource "aws_api_gateway_account" "demo" {
cloudwatch_role_arn = var.apigw_cloudwatch_role_arn
}
Run Code Online (Sandbox Code Playgroud)
在应用阶段,我看到以下错误 -
2020/09/21 20:20:48 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: Updating API Gateway Account failed: AccessDeniedException:
status code: 403, request id: abb0662e-ead2-4d95-b987-7d889088a5ef
Run Code Online (Sandbox Code Playgroud)
是否需要向角色附加特定权限才能消除此错误?
我正在使用 terraform,但没有获得正确的参数来创建我的粘合作业。由于我不是 terraform 专业人士(我开始),我想知道它是如何工作的。
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/glue_job#glue_version
我没有使用这些参数对我的胶水作业资源进行良好的更新:
resource "aws_glue_job" "job_name" {
name = "job_name"
description = "job-desc"
role_arn = "${aws_iam_role.service-name.arn}"
max_capacity = 2
max_retries = 1
timeout = 60
command {
script_location = "s3://my_bucket"
python_version = "3"
}
default_arguments = {
"--job-language" = "python"
"--ENV" = "env"
"--spark-event-logs-path" = "s3://my_bucket"
"--job-bookmark-option" = "job-bookmark-enable"
"--glue_version" = "2.0"
"--worker_type" = "G.1X"
"--enable-spark-ui" = "true"
}
execution_property {
max_concurrent_runs = 1
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道这些参数放在哪里以及如何放置。请你帮助我好吗 ?
"--glue_version" = "2.0"
"--worker_type" = "G.1X"
Run Code Online (Sandbox Code Playgroud)
问候。
我正在使用开放策略代理针对 terraform 状态的 JSON 输出编写策略。
这是状态文件的结构:
{
"format_version": "0.1",
"terraform_version": "0.12.28",
"values": {
"root_module": {
"resources": [],
"child_modules": [
{
"resources": [],
"address": "",
"child_modules": [
{
"resources": [],
"address": "",
"child_modules": [
{}
]
}
]
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我定义了这个令人讨厌的规则来实现我想要的,但这显然不是聚合这些资源的理想方式。
resources[resource_type] = all {
some resource_type
resource_types[resource_type]
rm := tfstate.values.root_module
# I think the below can be simplified with the built in "walk" function TODO: do that.
root_resources := [name |
name := rm.resources[_]
name.type == resource_type …Run Code Online (Sandbox Code Playgroud) 我正在使用 VSCode 1.51(此时为最新版本),并且在terraform plan ..从集成 PowerShell(此工作站上为 5.1)运行时,我注意到如果我将输出重定向到文本文件,可以通过运算符 ( .. > .\a.txt) 或通过 Tee-Object ( .. | Tee-Object -FilePath .\a.txt) 生成的输出文件被ASCII 转义序列破坏;特别是通过控制序列引入器 (CSI) 序列,例如 ESC[1m。到目前为止,在我看到的输出文件中,我仅观察到以下 6 个序列:
- ESC[0m
- ESC[1m
- ESC[4m
- ESC[31m
- ESC[32m
- ESC[33m
Run Code Online (Sandbox Code Playgroud)
我正在使用 Notepad++ 7.8.7 读取文件,如何用单个空格字符 (' ') 替换上述序列?
更新
显然,如果能够从terraform plan输出中删除 ASCII 转义序列那就更好了。
据我所知,当我在目录中运行 terraform CLI 时,它会从当前目录中获取所有 terraform 工件。
是否可以让 terraform apply 和 terraform plan 在当前 PWD 以外的目录中查找脚本,这样我就不必不断更改当前目录?
请告诉我如何通过 Terraform 在 GCP 提醒政策中提及多个条件。我尝试了几种创建文档中提到的条件列表的方法,但没有任何效果。
下面是代码片段:
resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "Request count Policy"
combiner = "OR"
conditions = [
display_name = "Request count condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
duration = "60s"
comparison = "COMPARISON_GT"
threshold_value = 5
trigger = {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.response_code_class", "resource.label.revision_name"]
}
},
display_name = "Request latencies condition"
condition_threshold {
filter = "metric.type=\"run.googleapis.com/request_count\" …Run Code Online (Sandbox Code Playgroud) 我尝试根据 IAM 角色是否存在来设置 KMS 密钥策略。yaml 文件如下所示。
data "aws_iam_policy_document" "key_policy" {
statement {
sid = "Give Access to the my Role"
actions = [
"kms:GenerateDateKey",
"kms:Decrypt"
]
resources = ["*"]
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.account_id}:role/myrole"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
此 terraform 脚本的问题是,如果myrole我的帐户中不存在该脚本,它将失败。我们有多个 AWS 账户,但其中只有一部分有这个myrole。我们的 CI 将为所有帐户运行相同的脚本。有没有办法仅在存在时应用此语句myrole?
我试图在服务器列表中设置一些警报,我在本地定义了我的服务器,如下所示:
locals {
my_list = [
"server1",
"server2"
]
}
Run Code Online (Sandbox Code Playgroud)
然后我将我的 cloudwatch 警报定义如下:(这是一个这样的警报)
resource "aws_cloudwatch_metric_alarm" "ec2-high-cpu-warning" {
for_each = toset(local.my_list)
alarm_name = "ec2-high-cpu-warning-for-${each.key}"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
dimensions = {
instanceid = values(data.aws_instances.my_instances)[*].ids
instancename = local.my_list
}
period = "60"
statistic = "Average"
threshold = "11"
alarm_description = "This warning is for high cpu utilization for ${each.key}"
actions_enabled = true
alarm_actions = [data.aws_sns_topic.my_sns.arn]
insufficient_data_actions = []
treat_missing_data = "notBreaching"
}
Run Code Online (Sandbox Code Playgroud)
我还将数据源定义如下:
data …Run Code Online (Sandbox Code Playgroud) 我有一个谷歌存储桶对象,它是通过 terraform 创建的,如下所示:
resource "google_storage_bucket_object" "my_post_startup_script" {
name = "my-script.sh"
source = "${path.module}/my-script.sh"
bucket = my_bucket
}
Run Code Online (Sandbox Code Playgroud)
但在该脚本内部是我想要创建变量的东西。
所以说 my-script.sh 看起来像:
#!/bin/bash
echo "hello ${name}"
Run Code Online (Sandbox Code Playgroud)
有没有办法让我传递一个变量以便进行插值,以便上传的脚本实际上说“你好约翰”
这可能需要一些中间步骤,创建一个带有变量插值的文件,然后我可以将其作为 google_storage_bucket_object 的源传入 - 但不确定如何完成。
terraform ×10
amazon-iam ×1
amazon-kms ×1
ansi-escape ×1
aws-glue ×1
azure ×1
notepad++ ×1
policy ×1
regex ×1
rego ×1