clo*_*che 5 amazon-s3 amazon-web-services amazon-vpc terraform
我正在尝试为 EC2 节点创建一个 VPC 端点,以访问 us-east-1 中同一 VPC 内的 S3 存储桶,而无需通过 NAT 网关。当我通过浏览器用户界面手动设置时,一切似乎都工作正常。然后我删除了它,并在我的 terraform 配置中将其定义为 aws_vpc_endpoint,如下所示:
resource "aws_vpc_endpoint" "vpc-s3-endpoint-dev" {
vpc_id = "${aws_vpc.dev.id}"
service_name = "com.amazonaws.us-east-1.s3"
route_table_ids = ["${aws_route_table.dev-us-east-1-private.id}"]
}
Run Code Online (Sandbox Code Playgroud)
计划进展顺利,当我尝试申请时,我得到了这个:
Error: Error applying plan:
1 error(s) occurred:
* aws_vpc_endpoint.vpc-s3-endpoint-dev: 1 error(s) occurred:
* aws_vpc_endpoint.vpc-s3-endpoint-dev: Error creating VPC Endpoint: InvalidServiceName: The Vpc Endpoint Service 'com.amazonaws.us-east-1.s3' does not exist
status code: 400, request id: b062c637-ec55-4da4-8527-73b24c10fa3d
Run Code Online (Sandbox Code Playgroud)
据我所知,我做的一切都是正确的。该路由表与我手动成功创建的测试 VPC 终端节点关联的路由表相同。我尝试过将关联的路由表分解为单独的 aws_vpc_endpoint_route_table_association ,甚至根本没有。我还尝试了 us-east-1 S3 服务端点的其他别名(com.amazonaws.s3 等)。我只是不断地遇到同样令人沮丧的错误,而且我已经没有主意了。
编辑:更多上下文
provider "aws" {
alias = "dev"
version = "= 2.12.0"
profile = "development"
region = "us-east-1"
}
Run Code Online (Sandbox Code Playgroud)
resource "aws_vpc" "dev" {
provider = "aws.dev"
cidr_block = "10.201.0.0/16"
enable_dns_support = "true"
enable_dns_hostnames = "true"
}
Run Code Online (Sandbox Code Playgroud)
将特定提供者添加到aws_vpc_endpoint资源似乎有效。
aws_vpc_endpoint.vpc-s3-endpoint-dev-xxx-xxxxx: Creation complete after 6s (ID: vpce-xxxxxxxxxxxxx)
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Run Code Online (Sandbox Code Playgroud)
小智 2
这个问题已经在评论中解决了,但我将把它留在这里以供将来参考,因为它是问题的症结所在。
如果您alias在provider块中使用 an ,则不会使用该提供程序,除非您在资源级别明确指定它(如上面在 中所做的那样provider = "aws.dev")。如果您没有明确指定,则默认提供程序将是provider "aws"没有与其关联的别名的提供程序,如果不存在,则它将假定为隐含的aws提供程序。
这个故事的寓意是,除非有充分的理由,否则不要在您的提供商中使用别名;拥有一个可发布到多个单独的 AWS 账户的代码库是一个很好的理由。
| 归档时间: |
|
| 查看次数: |
9799 次 |
| 最近记录: |