我有以下回购结构。
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .cosmos\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 .config\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .github\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 workflows\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 plan.yml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 update.yml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .gitignore\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.md\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 assets\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 1.png\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 2.png\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 3.png\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 us-west-2\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 applications\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test.json\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 cluster-config.json\nRun Code Online (Sandbox Code Playgroud)\n以及以下 GH Action yaml 文件。
\n计划.yml
\nname: Cosmos Plan\n\non:\n pull_request:\n paths:\n - "**/applications/*.json"\n - "**/cluster-config.json"\n\njobs:\n find:\n name: Find edited clusters\n runs-on: ubuntu-latest\n outputs:\n new: ${{ steps.find.outputs.new }}\n modified: ${{ steps.find.outputs.modified }}\n anyNew: ${{ steps.find.outputs.anyNew }}\n anyModified: ${{ steps.find.outputs.anyModified }}\n steps:\n - name: Checkout\n uses: actions/checkout@v2\n\n - name: …Run Code Online (Sandbox Code Playgroud) 我正在账户的每个 AWS 区域中部署 Lambda 函数,但遇到了奇怪的问题:某些 AWS 区域的应用失败并显示以下错误消息
\nTerraform 应用时出错
\nError: Error creating Lambda function: ResourceConflictException: Function already exist: log-forwarder\n{\n RespMetadata: {\n StatusCode: 409,\n RequestID: "8cfd7260-7c4a-42d2-98c6-6619c7b2804f"\n },\n Message_: "Function already exist: log-forwarder",\n Type: "User"\n}\nRun Code Online (Sandbox Code Playgroud)\n上述 Lambda 函数刚刚由失败的同一个 Terraform Apply 创建。
\nterraform plan 和 init 不会抛出任何有关 TF 配置问题的错误。
\nplan 和 init 均成功运行。
\n下面是我的目录结构
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 log_forwarder.tf\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 log_forwarder_lambdas\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.tf\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 providers.tf\nRun Code Online (Sandbox Code Playgroud)\n下面是我的providers.tf文件
provider "aws" {\n region = "us-east-1"\n version = "3.9.0"\n}\nprovider "aws" {\n …Run Code Online (Sandbox Code Playgroud) 我提出了aws_ecs_task_defintion以下 terraform 配置。
我local.image_tag作为变量传递来通过 terraform 控制 ecr 图像的部署。
我能够在初始 terraform 计划/应用周期中调出 ecs_cluster 。
然而,在随后的 terraform plan/apply 周期中,terraform 强制使用新的容器定义,这就是为什么即使我们的 ecr 映像也要重新部署整个任务定义local.image_tag保持不变也要重新部署整个任务定义
这种行为会导致意外的任务定义回收,而无需对 ecr 图像进行任何更改,而只是使用默认值强制 terraform 值。
TF配置
resource "aws_ecs_task_definition" "this_task" {
family = "this-service"
execution_role_arn = var.this_role
task_role_arn = var.this_role
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = 256
memory = var.env != "prod" ? 512 : 1024
tags = local.common_tags
# Log the to datadog if it's running in the prod account.
container_definitions = …Run Code Online (Sandbox Code Playgroud) 我正在为字符串变量的给定值中的每个服务创建一个route53运行状况检查services。
tfvars当我传递 services 变量的值时,我的文件如下所示
services = "servicea serviceb serviced"
我只需要进行这些健康检查,如果var.env == prod。
有一种经过尝试和测试的方法可以使用,并且将会使用,count = var.env == prod ? 1:0但由于我已经使用 count 来计算和迭代服务字符串,我无法count在同一资源块中再次使用,因为 terraform 0.12 给了我以下错误如果我想这样做,请留言。
在同一资源块中使用多个计数时出错
Error: Attribute redefined
on <stdin> line 514: (source code not available)
The argument "count" was already set at <stdin>:513,2-7. Each argument may be set only once.
Run Code Online (Sandbox Code Playgroud)
地形配置
variable "services" {
default = ""
}
resource aws_route53_health_check "app_healthcheck" {
count = length(split(",", replace(var.services, "/\\s/", ",")))
fqdn = …Run Code Online (Sandbox Code Playgroud) 我找不到 terraform 模块来创建 AWS SNS 主题订阅。例如:我使用“terraform-aws-modules/sns/aws”来创建 SNS 主题。有人可以指出我要订阅的源模块吗?