【问题标题】:Terraform not starting the nginx server on AWSTerraform 未在 AWS 上启动 nginx 服务器
【发布时间】:2020-04-22 19:06:13
【问题描述】:

我有以下 terraform 文件,我正在其中启动 Nginx 服务器。 Terraform 正在安装 Nginx,但 Nginx 服务器没有启动。我必须手动登录到 ec2 机器并启动服务。我哪里错了?

terraform {
 required_version = ">=0.12, <0.13"
}

provider "aws" { 
    region = "ap-south-1" 
} 
resource "aws_instance" "ec2-instance" { 
    ami = "ami-04b2519c83e2a7ea5" 
    instance_type = "t2.micro"
    vpc_security_group_ids = [aws_security_group.web_security.id]
    key_name = "kops-keypair"
    user_data = <<-EOF
                    #!/bin/bash
                    sudo yum update -y
                    sudo yum install nginx -y 
                    sudo service start nginx
                EOF
    tags = {
        Name = "nginx-instance",
        created-date = "22-04-2020"
    }
} 

resource "aws_security_group" "web_security" {
    name = "web-security"

  ingress {
     from_port = 22
     to_port = 22
     protocol = "tcp" 
     cidr_blocks = ["0.0.0.0/0"]
  }
  ingress {
     from_port = 80
     to_port = 80
     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"]
  }
}

【问题讨论】:

    标签: nginx amazon-ec2 terraform


    【解决方案1】:

    我的错。命令应该是sudo service nginx start

    【讨论】:

      猜你喜欢
      • 2016-11-14
      • 2020-01-25
      • 2011-08-08
      • 1970-01-01
      • 2016-03-31
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多