我们希望Bitbucket webhooks触发我们的CI工具,该工具在亚马逊网络服务EC2实例上运行,受入口规则保护,不受一般访问的影响。
Bitbucket提供了一个页面,列出了他们在https://support.atlassian.com/bitbucket-cloud/docs/what-are-the-bitbucket-cloud-ip-addresses-i-should-use-to-configure-my-corporate-firewall/上的IP地址
他们还在https://ip-ranges.atlassian.com/上为亚特兰大的in提供了一个机器可用的版本。
我想知道,在亚马逊网络服务EC2安全组中添加和维护此列表的有效方法是什么,例如通过terraform。
发布于 2021-01-21 19:47:10
我最终从他们的页面中删除了机器可用的json,剩下的让terraform来管理。获取json的步骤保留为手动任务。
resource "aws_security_group_rule" "bitbucket-ips-sgr" {
security_group_id = "your-security-group-id"
type = "ingress"
from_port = 443
to_port = 443
protocol = "TCP"
cidr_blocks = local.bitbucket_cidrs_ipv4
ipv6_cidr_blocks = local.bitbucket_cidrs_ipv6
}
locals {
bitbucket_cidrs_ipv4 = [for item in local.bitbucket_ip_ranges_source.items:
# see https://stackoverflow.com/q/47243474/1242922
item.cidr if length(regexall(":", item.cidr)) == 0
]
bitbucket_cidrs_ipv6 = [for item in local.bitbucket_ip_ranges_source.items:
# see https://stackoverflow.com/q/47243474/1242922
item.cidr if length(regexall(":", item.cidr)) > 0
]
# the list originates from https://ip-ranges.atlassian.com/
bitbucket_ip_ranges_source = jsondecode(
<<JSON
the json output from the above URL
JSON
)
}发布于 2021-01-28 04:26:11
我改进了Richard的回答,并希望添加TF的http提供程序可以为您获取JSON,并且对jsondecode()调用稍作调整后,仍然可以使用相同的for循环。
provider "http" {}
data "http" "bitbucket_ips" {
url = "https://ip-ranges.atlassian.com/"
request_headers = {
Accept = "application/json"
}
}
locals {
bitbucket_ipv4_cidrs = [for c in jsondecode(data.http.bitbucket_ips.body).items : c.cidr if length(regexall(":", c.cidr)) == 0]
bitbucket_ipv6_cidrs = [for c in jsondecode(data.http.bitbucket_ips.body).items : c.cidr if length(regexall(":", c.cidr)) > 0]
}
output "ipv4_cidrs" {
value = local.bitbucket_ipv4_cidrs
}
output "ipv6_cidrs" {
value = local.bitbucket_ipv6_cidrs
}https://stackoverflow.com/questions/65826698
复制相似问题