diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 6ef21a0..29fb49c 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -5,7 +5,7 @@ provider "registry.terraform.io/hashicorp/aws" { version = "4.15.1" constraints = "~> 4.15.0" hashes = [ - "h1:leEZu+Kv9JIvGpt8SfFkjftdR8KrFMkbUMQVnH0kvFk=", + "h1:KPu3MdNXCScye05Sp4JlE9WwhS9k3yD9KRoRDHg5sDE=", "zh:1d944144f8d613b8090c0c8391e4b205ca036086d70aceb4cdf664856fa8410c", "zh:2a0ca16a6b12c0ac509f64512f80bd2ed6e7ea0ec369212efd4be3fa65e9773d", "zh:3f9efdce4f1c320ffd061e8715e1d031deac1be0b959eaa60c25a274925653e4", @@ -22,20 +22,20 @@ provider "registry.terraform.io/hashicorp/aws" { } provider "registry.terraform.io/hashicorp/random" { - version = "3.3.2" + version = "3.4.3" hashes = [ - "h1:Fu0IKMy46WsO5Y6KfuH9IFkkuxZjE/gIcgtB7GWkTtc=", - "zh:038293aebfede983e45ee55c328e3fde82ae2e5719c9bd233c324cfacc437f9c", - "zh:07eaeab03a723d83ac1cc218f3a59fceb7bbf301b38e89a26807d1c93c81cef8", - "zh:427611a4ce9d856b1c73bea986d841a969e4c2799c8ac7c18798d0cc42b78d32", - "zh:49718d2da653c06a70ba81fd055e2b99dfd52dcb86820a6aeea620df22cd3b30", - "zh:5574828d90b19ab762604c6306337e6cd430e65868e13ef6ddb4e25ddb9ad4c0", - "zh:7222e16f7833199dabf1bc5401c56d708ec052b2a5870988bc89ff85b68a5388", + "h1:xZGZf18JjMS06pFa4NErzANI98qi59SEcBsOcS2P2yQ=", + "zh:41c53ba47085d8261590990f8633c8906696fa0a3c4b384ff6a7ecbf84339752", + "zh:59d98081c4475f2ad77d881c4412c5129c56214892f490adf11c7e7a5a47de9b", + "zh:686ad1ee40b812b9e016317e7f34c0d63ef837e084dea4a1f578f64a6314ad53", "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:b1b2d7d934784d2aee98b0f8f07a8ccfc0410de63493ae2bf2222c165becf938", - "zh:b8f85b6a20bd264fcd0814866f415f0a368d1123cd7879c8ebbf905d370babc8", - "zh:c3813133acc02bbebddf046d9942e8ba5c35fc99191e3eb057957dafc2929912", - "zh:e7a41dbc919d1de800689a81c240c27eec6b9395564630764ebb323ea82ac8a9", - "zh:ee6d23208449a8eaa6c4f203e33f5176fa795b4b9ecf32903dffe6e2574732c2", + "zh:84103eae7251384c0d995f5a257c72b0096605048f757b749b7b62107a5dccb3", + "zh:8ee974b110adb78c7cd18aae82b2729e5124d8f115d484215fd5199451053de5", + "zh:9dd4561e3c847e45de603f17fa0c01ae14cae8c4b7b4e6423c9ef3904b308dda", + "zh:bb07bb3c2c0296beba0beec629ebc6474c70732387477a65966483b5efabdbc6", + "zh:e891339e96c9e5a888727b45b2e1bb3fcbdfe0fd7c5b4396e4695459b38c8cb1", + "zh:ea4739860c24dfeaac6c100b2a2e357106a89d18751f7693f3c31ecf6a996f8d", + "zh:f0c76ac303fd0ab59146c39bc121c5d7d86f878e9a69294e29444d4c653786f8", + "zh:f143a9a5af42b38fed328a161279906759ff39ac428ebcfe55606e05e1518b93", ] } diff --git a/init-script.sh b/init-script.sh index 82f18b3..e585328 100644 --- a/init-script.sh +++ b/init-script.sh @@ -1,10 +1,9 @@ #!/bin/bash yum update -y -yum -y remove httpd -yum -y remove httpd-tools -yum install -y httpd24 php72 mysql57-server php72-mysqlnd -service httpd start -chkconfig httpd on +amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2 +yum install -y httpd mariadb-server +systemctl start httpd +systemctl enable httpd usermod -a -G apache ec2-user chown -R ec2-user:apache /var/www diff --git a/main.tf b/main.tf index c4cda90..86782ab 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ provider "aws" { - region = "us-west-2" + region = var.region_code } provider "random" {} @@ -7,11 +7,30 @@ provider "random" {} resource "random_pet" "name" {} resource "aws_instance" "web" { - ami = "ami-a0cfeed8" - instance_type = "t2.micro" - user_data = file("init-script.sh") - + ami = "ami-0fe472d8a85bc7b0e" + instance_type = "t2.micro" + user_data = file("init-script.sh") + vpc_security_group_ids = [aws_security_group.web-sg.id] tags = { Name = random_pet.name.id } } + + +resource "aws_security_group" "web-sg" { + name = "${random_pet.name.id}-sg" + 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"] + } +} + diff --git a/outputs.tf b/outputs.tf index 9d20d74..d8d22f5 100644 --- a/outputs.tf +++ b/outputs.tf @@ -5,3 +5,7 @@ output "domain-name" { output "application-url" { value = "${aws_instance.web.public_dns}/index.php" } + +output "application-ip-address" { + value = "${aws_instance.web.public_ip}" +} diff --git a/terraform.tf b/terraform.tf index 115c9d5..2f9406c 100644 --- a/terraform.tf +++ b/terraform.tf @@ -19,5 +19,5 @@ terraform { } } - required_version = "~> 1.2.0" + required_version = ">= 1.2.0" } diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..f90ff3b --- /dev/null +++ b/variables.tf @@ -0,0 +1,5 @@ +variable "region_code" { + description = "the deployment aws region" + default = "us-east-1" + type = string +}