Amazon web services 如何使用terraform在LocalStack上创建EC2实例?
我正在尝试使用Terraform在LocalStack上运行EC2实例 尝试创建实例50分钟后 我从terraform apply得到了以下回复: 错误:获取EC2实例(i-cf4da152ddf3500e1)学分时出错 规格:SerializationError:无法解组错误消息 状态代码:500,请求id:原因:解组错误:未能 由以下原因导致的解组错误消息:预期的元素类型 但是有 在main.tf行的资源“aws_实例”示例中:34: 资源“aws_实例”“示例”{ 对于LocalStack和Terraform v0.12.18,我使用以下配置:Amazon web services 如何使用terraform在LocalStack上创建EC2实例?,amazon-web-services,terraform,localstack,Amazon Web Services,Terraform,Localstack,我正在尝试使用Terraform在LocalStack上运行EC2实例 尝试创建实例50分钟后 我从terraform apply得到了以下回复: 错误:获取EC2实例(i-cf4da152ddf3500e1)学分时出错 规格:SerializationError:无法解组错误消息 状态代码:500,请求id:原因:解组错误:未能 由以下原因导致的解组错误消息:预期的元素类型 但是有 在main.tf行的资源“aws_实例”示例中:34: 资源“aws_实例”“示例”{ 对于LocalStack
provider "aws" {
access_key = "mock_access_key"
region = "us-east-1"
s3_force_path_style = true
secret_key = "mock_secret_key"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
endpoints {
apigateway = "http://localhost:4567"
cloudformation = "http://localhost:4581"
cloudwatch = "http://localhost:4582"
dynamodb = "http://localhost:4569"
es = "http://localhost:4578"
firehose = "http://localhost:4573"
iam = "http://localhost:4593"
kinesis = "http://localhost:4568"
lambda = "http://localhost:4574"
route53 = "http://localhost:4580"
redshift = "http://localhost:4577"
s3 = "http://localhost:4572"
secretsmanager = "http://localhost:4584"
ses = "http://localhost:4579"
sns = "http://localhost:4575"
sqs = "http://localhost:4576"
ssm = "http://localhost:4583"
stepfunctions = "http://localhost:4585"
sts = "http://localhost:4592"
ec2 = "http://localhost:4597"
}
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
当我使用docker compose直接从最新的github()运行LocalStack时
从日志中,我看到与EC2相关的端点已设置
我非常感谢任何能帮助我在LocalStack上运行EC2的建议。可以很好地处理LocalStack下面的docker图像 docker run-it-p4500-4600:4500-4600-p8080:8080-公开4572 localstack/localstack:0.11.1
resource "aws_instance" "web" {
ami = "ami-0d57c0143330e1fa7"
instance_type = "t2.micro"
tags = {
Name = "HelloWorld"
}
}
provider "aws" {
region = "us-east-1"
s3_force_path_style = true
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
endpoints {
apigateway = "http://localhost:4567"
cloudformation = "http://localhost:4581"
cloudwatch = "http://localhost:4582"
dynamodb = "http://localhost:4569"
es = "http://localhost:4578"
firehose = "http://localhost:4573"
iam = "http://localhost:4593"
kinesis = "http://localhost:4568"
lambda = "http://localhost:4574"
route53 = "http://localhost:4580"
redshift = "http://LOCALHOST:4577"
s3 = "http://localhost:4572"
secretsmanager = "http://localhost:4584"
ses = "http://localhost:4579"
sns = "http://localhost:4575"
sqs = "http://localhost:4576"
ssm = "http://localhost:4583"
stepfunctions = "http://localhost:4585"
sts = "http://localhost:4592"
ec2 = "http://localhost:4597"
}
}
地形应用
aws_instance.web: Destroying... [id=i-099392def6b574255]
aws_instance.web: Still destroying... [id=i-099392def6b574255, 10s elapsed]
aws_instance.web: Destruction complete after 10s
aws_instance.web: Creating...
aws_instance.web: Still creating... [10s elapsed]
aws_instance.web: Creation complete after 12s [id=i-9c942d138970d44a4]
Apply complete! Resources: 1 added, 0 changed, 1 destroyed.
注意:它是一个虚拟实例,因此不适用于ssh和所有应用程序。但是,它适合于在ec2上测试terraform apply/destroy用例。LocalStack实际上没有在本地计算机中部署任何AWS服务;只是模拟API事务。因此,这可能是一个错误。请在LocalStack上提交一个问题,以供进一步投资igation。那么它是否应该模拟它,以便即使没有运行真正可访问的实例,我也能够查看和测试我的terraform配置?虽然LocalStack提供模拟库,但这并不意味着每个API调用都成功模拟请求。使用terraform或LocalStack时,您没有做错任何事情;但是,这是LocalStack中的一个bug,我建议使用real service。