ec2私有云实现的terraform

时间:2019-04-18 18:29:02

标签: amazon-web-services amazon-ec2 terraform private-cloud

已更新:

我们在数据中心托管了一个私有云,该云是简化的AWS版本。我们公开了EC2 API,以允许用户使用awscli创建VM。

我正在尝试使用Terraform创建虚拟机,并且为了进行初始测试,我创建了一个.tf文件,如下所示:

provider "aws" {
  access_key = "<key>"
  secret_key = "<key>"
  region = "us-west-1"
  skip_credentials_validation = true

  endpoints
  {
    ec2 = "https://awsserver/services/api/aws/ec2"
  }
}

resource "aws_instance" "Automation" {
  ami           = "ami-100011201"
  instance_type = "c3.xlarge"
  subnet_id = "subnet1:1"

}

这是运行Terraform Plan后的错误消息

    Error: Error running plan: 1 error(s) occurred:

* provider.aws: AWS account ID not previously found and failed retrieving via all available methods. See https://www.terraform.io/docs/providers/aws/index.html#skip_requesting_account_id for workaround and implications. Errors: 2 errors occurred:
        * error calling sts:GetCallerIdentity: InvalidClientTokenId: The security token included in the request is invalid.
        status code: 403, request id: 58f9d498-6259-11e9-b146-95598aa219b5
        * failed getting account information via iam:ListRoles: InvalidClientTokenId: The security token included in the request is invalid.
        status code: 403, request id: c10f8a06-58b4-4d0c-956a-5c8c684664ea

我们尚未实现sts,并且查询始终转到AWS云而不是私有云API服务器。

我想念什么?

1 个答案:

答案 0 :(得分:0)

这对我创建虚拟机很有帮助。

provider "aws" {
  access_key = "<key>"
  secret_key = "<key>"
  region = "us-west-1"
  skip_credentials_validation =true
  skip_requesting_account_id = true
  skip_metadata_api_check = true

  endpoints
  {
    ec2 = "https://awsserver/services/api/aws/ec2"
  }
}

resource "aws_instance" "Automation" {
  ami           = "ami-100011201"
  instance_type = "c3.xlarge"
  subnet_id = "subnet1:1"

}

它创建了一个VM,但是命令错误出现了

aws_instance.Automation: Still creating... (1h22m4s elapsed)
aws_instance.Automation: Still creating... (1h22m14s elapsed)
aws_instance.Automation: Still creating... (1h22m24s elapsed)

Error: Error applying plan:

1 error(s) occurred:

* aws_instance.Automation: 1 error(s) occurred:

* aws_instance.Automation: Error waiting for instance (i-101149362) to become ready: timeout while waiting for state to become 'running' (last state: 'pending', timeout: 10m0s)

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.