我一直在为 AWS 基础设施编写可重用的模块。在创建安全组时,我的方法是为安全组创建一个通用模块并在控制代码中提供端口列表。但是,在使用count它时,会为每个端口创建一个安全组。有没有办法像在这种情况下那样迭代特定部分?
SG模块
resource "aws_security_group" "this" {
name = var.sg_name
description = var.description
vpc_id = var.vpc_id
count = min(length(var.ingress_ports))
ingress {
from_port = var.ingress_ports[count.index]
to_port = var.ingress_ports[count.index]
protocol = "tcp"
cidr_blocks = ["10.0.0.0/8"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
Run Code Online (Sandbox Code Playgroud)
控制代码
module "qliksense_sg" {
source = "modules/aws-sg"
sg_name = "My-SG"
description = "A security group"
vpc_id = module.vpc.vpc_id
ingress_ports = ["80", "443"]
}
Run Code Online (Sandbox Code Playgroud) amazon-web-services terraform aws-security-group terraform-provider-aws
我已经通过 DigiCert 创建了一个 SSL 证书并导入到 ACM。(我需要将相同的 SSL 应用于 ALB 和应用程序,并且由于无法导入 ACM 证书,因此我必须遵循这种方式)
我已经成功导入了 SSL 并且可以在控制台中看到它。但是,我无法将其应用于 ALB 443 侦听器。
我向 CloudFormation 模板提供了证书 ARN,但它未能说明证书不存在。
我尝试手动更新 443 侦听器,但未列出证书
由于两者都失败了,我尝试在 ALB 侦听器控制台中导入证书,但收到以下错误消息。(但是,证书被导入,我可以在控制台中看到它)
更新侦听器失败。导入的证书的配置不兼容,不会出现在您的侦听器的可用证书列表中。选择或上传不同的证书,然后重试。
ssl certificate ssl-certificate amazon-web-services amazon-elb
我需要将经典 ELB 的 ARN 作为输出才能导出。关于如何实现这一目标的任何想法?
我尝试了以下错误的代码。
Outputs:
LoadBalancer:
Description: A reference to the Application Load Balancer/ARN
Value:
'Fn::GetAtt': [ LoadBalancer, Arn ]
Run Code Online (Sandbox Code Playgroud)
错误模板验证错误:模板错误:资源 LoadBalancer 不支持 Fn::GetAtt 中的属性类型 Arn
对于ALB,以下代码有效。但是对于经典 ELB,它只返回名称。
Outputs:
LoadBalancer:
Description: A reference to the Application Load Balancer/ARN
Value: !Ref LoadBalancer
Export:
Name: SO-LoadBalancer
Run Code Online (Sandbox Code Playgroud)