【发布时间】:2021-05-15 02:56:05
【问题描述】:
我是 terraform 的新手。我有一个 Dockerized 应用程序,可以使用 docker-compose 文件进行部署。
我编写了一个 terraform 脚本,它创建了一个安全组、一台 EC2 机器,并运行了一个下载 docker 和 docker-compose 的脚本,我正在尝试将此 docker-compose 文件从本地机器上传到远程机器。每当 terraform 到达这一步时,都会产生以下错误:
aws_instance.docker_swarm: Provisioning with 'file'...
Error: host for provisioner cannot be empty
下面是 terraform 模板:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 2.70"
}
}
}
provider "aws" {
profile = var.profile
region = var.region
}
resource "aws_security_group" "allow_ssh_http" {
name = "allow_ssh_http"
description = "Allow SSH and HTTP access to ports 22 and 1337"
ingress {
description = "SSH from everywhere"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "Access Port 1337 from Everywhere"
from_port = 1337
to_port = 1337
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "allow_ssh_http"
}
}
resource "aws_instance" "docker_swarm" {
ami = var.amis[var.region]
instance_type = var.instance_type
key_name = var.key_name
vpc_security_group_ids = [aws_security_group.allow_ssh_http.id]
user_data = "${file("deployServices.sh")}"
provisioner "file" {
source = "./docker-compose.yml"
destination = "/home/ubuntu/docker-compose.yml"
}
tags = {
Name = "NK Microservices Stack"
}
}
output "ec2_id" {
value = aws_instance.docker_swarm.id
}
output "ec2_ip" {
value = aws_instance.docker_swarm.public_ip
}
【问题讨论】:
标签: amazon-web-services docker terraform infrastructure-as-code