小编yda*_*coR的帖子

使用Terraform将多个S3路径添加到胶履带

我正在使用Terraform在AWS中构建一些基础架构。我创建了几个S3存储桶,并希望Glue搜寻器每小时对这些存储桶进行一次爬网。我的Terraform Glue目录数据库,角色和策略都构建良好,但是当我尝试通过向爬网程序的s3_target{}一部分添加四个S3路径来创建爬网程序资源时,出现了故障:

resource "aws_glue_crawler" "datalake_crawler" {
  database_name = "${var.glue_db_name}"
  name          = "${var.crawler_name}"
  role          = "${aws_iam_role.glue.id}" 

  s3_target {
#    count = "${length(var.data_source_path)}"
    path = "${var.data_source_path}"#"${formatlist("%s", var.data_source_path)}"
  }
}
Run Code Online (Sandbox Code Playgroud)

这会导致错误:

Error: aws_glue_crawler.datalake_crawler: s3_target.0.path must be a single value, not a list
Run Code Online (Sandbox Code Playgroud)

我尝试在中添加一条count语句,s3_target但这失败。我也尝试添加

"${formatlist("%s", var.data_source_path)}"
Run Code Online (Sandbox Code Playgroud)

path争论中,但这也失败了。

我可以s3使用Terraform向Glue履带添加多个路径吗?我可以通过AWS控制台实现这一点,但这需要使用基础架构作为代码来完成。

amazon-s3 amazon-web-services terraform aws-glue terraform-provider-aws

2
推荐指数
1
解决办法
627
查看次数

使用 Terraform 的 CloudWatch 指标警报

当尝试使用 Terraform 设置某些 CloudWatch 警报时,由于某种原因,它找不到指标,并且警报仍然陷入数据不足的状态。Terraform 不会输出任何错误,如果我在 AWS 中手动搜索,我可以找到指标。我在这里缺少什么?

指向目标组的简单健康主机警报示例:

#healthy host alarm
resource "aws_cloudwatch_metric_alarm" "health" {
  alarm_name          = "${var.tag_app}_healthy_host"
  comparison_operator = "LessThanThreshold"
  evaluation_periods  = "1"
  metric_name         = "HealthyHostCount"
  namespace           = "AWS/ApplicationELB"
  period              = "60"
  statistic           = "Maximum"
  threshold           = "1"
  alarm_description   = "Healthy host count for EC2 machine"
  alarm_actions       = ["${data.aws_sns_topic.blabla.arn}"]
  ok_actions          = ["${data.aws_sns_topic.blabla.arn}"]

  dimensions = {
    TargetGroup  = "${aws_lb_target_group.alb_target.arn_suffix}"
  }
}
Run Code Online (Sandbox Code Playgroud)

当我选择另一个资源(EC2、RDS)和另一个指标时,我会收到指向正确指标的 CloudWatch 警报,并且它不会陷入数据不足的困境。

amazon-web-services amazon-cloudwatch terraform terraform-provider-aws

2
推荐指数
1
解决办法
7125
查看次数

如何在资源更新/创建后运行 AWS Glue Crawler?

我在 Terraform 中定义了一个资源来创建我不想安排的 Glue Crawler。但我希望它在创建和更新后运行。我在文档中找不到有关如何触发此操作的任何内容。

resource "aws_glue_crawler" "my_crawler" {
  database_name = "my_db"
  name          = "my_crawler"
  role          = "arn:aws:iam::111111111111:role/service-role/someRole"

  s3_target {
    path = "s3://my_bucket/key/prefix"
  }

}
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform aws-glue terraform-provider-aws

2
推荐指数
1
解决办法
2685
查看次数

通过 Terraform 传递文件夹中的所有文件

我正在为我们的内部项目构建一个监控堆栈。我希望他们能够设计自己的监控仪表板以在 Grafana 内部使用,所以我无法预测这些仪表板的名称。

我创建了一个名为 的文件夹grafana_dashboard,我将在其中指示他们将仪表板存储为 JSON 文件,并且我希望将该文件夹的所有内容传递到 Grafana 实例。

我尝试过很多变体:

resource "grafana_dashboard" "dashboards" {
  for_each = fileset(path.module, "grafana_dashboard/*.json")
  config_json = "${each.key}"
  depends_on = [aiven_service.grafana]
}
Run Code Online (Sandbox Code Playgroud)

但不断收到此错误:

Error: invalid character 'g' looking for beginning of value

  on ../modules/monitoring/grafana.tf line 139, in resource "grafana_dashboard" "dashboards":
 139: resource "grafana_dashboard" "dashboards" {
Run Code Online (Sandbox Code Playgroud)

你们谁能看出我做错了什么吗?

这是我尝试传递的 .json 文件之一的示例:

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": …
Run Code Online (Sandbox Code Playgroud)

monitoring grafana terraform

2
推荐指数
1
解决办法
4651
查看次数

如何将多个 IAM 角色附加到 AWS 上的实例配置文件?

我正在使用 Terraform 创建 IAM 和 EC2,如下所示。

我想将一个名为ec2_roleEC2 实例配置文件的角色附加到该 EC2 实例配置文件中。但它似乎只能附加由 . 创建的一个aws_iam_instance_profile

resource "aws_instance" "this" {
  # ..
  iam_instance_profile    = aws_iam_instance_profile.this.name
}

resource "aws_iam_instance_profile" "this" {
  name = "ec2-profile"
  role = aws_iam_role.ec2_role.name
}
Run Code Online (Sandbox Code Playgroud)

关于ec2_role,它使用ec2_role_policy. 但如果我设置source_json = data.aws_iam_policy.amazon_ssm_managed_instance_core.policydata "aws_iam_policy_document" "ec2_role_policy" {,它会引发错误。

resource "aws_iam_role" "ec2_role" {
  name               = "ec2-role"
  assume_role_policy = data.aws_iam_policy_document.ec2_role_policy.json
}

resource "aws_iam_policy" "ec2_policy" {
  name   = "ec2-policy"
  policy = data.aws_iam_policy_document.ec2_use_role_policy.json
}

resource "aws_iam_role_policy_attachment" "attach" {
  role       = …
Run Code Online (Sandbox Code Playgroud)

amazon-ec2 amazon-iam terraform terraform-provider-aws

2
推荐指数
2
解决办法
2107
查看次数

Ansible ec2_elb_lb HTTPS到HTTP错误

我已成功使用此剧本创建了一个ELB:

 - name: Create VPC network
      ec2_elb_lb:
        aws_access_key: "{{ aws_access_key }}"
        aws_secret_key: "{{ aws_secret_key }}"
        name: "ElasticLoadBalancer"
        region: us-east-1
        state: present
        subnets: "{{ Subnet.SubnetId }}"
        listeners:
           - protocol: http
             load_balancer_port: 80
             instance_port: 80
      register: elb
    - debug: msg="{{ elb }}"
Run Code Online (Sandbox Code Playgroud)

但我还需要添加HTTPS入站和HTTP出站,因此我根据ec2_elb_lb模块示例添加了一个额外的侦听:

- name: Create VPC network
      ec2_elb_lb:
        aws_access_key: "{{ aws_access_key }}"
        aws_secret_key: "{{ aws_secret_key }}"
        name: "ElasticLoadBalancer"
        region: us-east-1
        state: present
        subnets: "{{ Subnet.SubnetId }}"
        listeners:
           - protocol: http
             load_balancer_port: 80
             instance_port: 80
           - protocol: …
Run Code Online (Sandbox Code Playgroud)

amazon-ec2 amazon-web-services ansible ansible-playbook

1
推荐指数
1
解决办法
678
查看次数

Terraform-具有相同aws_instance资源的多个子网

我试图部署多个EC2实例,每个实例使用相同的aws_instance资源块在不同的子网中。

当我将count参数设置为多个服务器时,它将在同一子网中全部建立它们。

有没有办法通过Terraform做到这一点?

在下面,您将找到我的Terraform块:

resource "aws_instance" "ec2-instance" {
  ami                    = "${var.ec2_ami}"
  instance_type          = "${var.instance_type}"
  key_name               = "${var.key_name}"
  vpc_security_group_ids = ["${var.security_group}"]

  subnet_id = "${var.subnet_id}"
  count     = "${var.count}"

  root_block_device {
    volume_size = "${var.root_volume_size}"
    volume_type = "${var.root_volume_type}"
  }

  tags {
    Name = "${var.app_name}"
  }
}
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform

1
推荐指数
1
解决办法
3178
查看次数

aws_lb 的动态子网映射

我正在尝试使用 Terraform 创建一个网络负载平衡器,重要的是它与防止被破坏的弹性 IP 相关联。

我有如下代码:

resource "aws_lb" "balancer" {
  name = "${var.name}-nlb"

  internal           = "${var.internal}"
  load_balancer_type = "network"
  subnets            = ["${data.aws_subnet_ids.selected.ids}"]

  subnet_mapping {
    subnet_id     = "someid"
    allocation_id = "someid"
  }

  subnet_mapping {
    subnet_id     = "someid"
    allocation_id = "someid"
  }

  subnet_mapping {
    subnet_id     = "someid"
    allocation_id = "someid"
  }

  tags = "${merge(var.tags,
    map("Terraform", "true"),
    map("Environment", var.environment))}"
}
Run Code Online (Sandbox Code Playgroud)

我所追求的是subnet_mapping动态地制作块,因为这段代码位于一个模块中,我想根据传入的子网数量创建映射数量。要么是,要么是传入预定义的块。

有没有办法做到这一点?对我来说重要的是相关的弹性 IP 需要坚持下去。

amazon-web-services terraform terraform-provider-aws

1
推荐指数
1
解决办法
2068
查看次数

地形变量文件

我正在尝试使用变量文件在 Azure 中使用 Terraform 部署资源组,但如果我只有一个变量,它就可以工作。如果我使用两个,我会收到一个错误:

“标志-var-file 的无效值“variables.tf”:变量不支持多个映射声明”

变量文件如下:

variable "resource_group_name" {
  description = "The name of the resource group in which the resources will be created"
  default     = "im-from-the-variables-file"
}

variable "location" {
  description = "The location/region where the virtual network is created. Changing this forces a new resource to be created."
  default     = "west europe"
}
Run Code Online (Sandbox Code Playgroud)

用于部署的主要文件如下:

resource "azurerm_resource_group" "vm" {
  name     = "${var.resource_group_name}"
  location = "${var.location}"
}
Run Code Online (Sandbox Code Playgroud)

azure terraform

1
推荐指数
1
解决办法
1746
查看次数

尝试将对象放入存储桶时出现间歇性 Terraform 故障

我看到间歇性的 Terraform 故障在我看来就像是 Terraform 本身内部的竞争条件:

21:31:37 aws_s3_bucket.jar: Creation complete after 1s 
(ID: automatictester.co.uk-my-bucket)
...
21:31:38 * aws_s3_bucket_object.jar: Error putting object in S3 bucket
(automatictester.co.uk-my-bucket): NoSuchBucket: The specified bucket 
does not exist
Run Code Online (Sandbox Code Playgroud)

正如您在上面的日志中看到的那样,TF 首先声称它在 21:31:37 创建了一个存储桶,然后说它不能将对象放入该存储桶中,因为它在 21:31:38 不存在。

上述错误背后的代码:

resource "aws_s3_bucket" "jar" {
  bucket               = "${var.s3_bucket_jar}"
  acl                  = "private"
}
...
resource "aws_s3_bucket_object" "jar" {
  bucket               = "${var.s3_bucket_jar}"
  key                  = "my.jar"
  source               = "${path.module}/../target/my.jar"
  etag                 = "${md5(file("${path.module}/../target/my.jar"))}"
}
Run Code Online (Sandbox Code Playgroud)

显然,这两者之间定义了一种隐式依赖关系,因此我想到的失败的唯一原因是 Amazon S3 的最终一致性。

如何处理此类错误?我相信显式定义的依赖depends-on不会为已经存在的隐式依赖提供任何价值。

amazon-s3 amazon-web-services terraform terraform-provider-aws

1
推荐指数
1
解决办法
920
查看次数