Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create EC2 resource using terraform #24

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions terraform/aws/aws.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
variable "access_key" {
type = string
}

variable "secret_key" {
type = string
}

variable "region" {
type = string
default = "us-west-2"
}

variable "ami" {
type = string
default = "ami-0569ce8a44f2351be"
}

variable "instance_type" {
type = string
default = "c6in.2xlarge"
}


# Specify the cloud provider
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Specify the cloud provider

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
region = var.region
}


resource "aws_instance" "web" {
ami = var.ami
instance_type = var.instance_type
security_groups = ["ssh", "https", "api"]
tags = {
Name = "web"
}
}

# Create a resource of type "aws_security_group" to enable SSH
Copy link
Author

@guy9050 guy9050 Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Create a resource of type "aws_security_group" to enable SSH

resource "aws_security_group" "ssh" {
name = "ssh"
description = "Allow SSH access"

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 6443
to_port = 6443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_security_group" "https" {
name = "https"
description = "Allow HTTPS access"

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_security_group" "API" {
name = "api"
description = "Allow API access"

ingress {
from_port = 6443
to_port = 6443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}


output "public_ip" {
value = aws_instance.web.public_ip
}