Files

55 lines
2.1 KiB
Terraform

provider "aws" {
region = "ap-south-1"
}
# EC2 instance
resource "aws_instance" "ec2_t2-micro" {
ami = "ami-0861f4e788f5069dd" # Amazon Linux
instance_type = "t2.micro" # Instance type
key_name = "kshitij-personal-ed25519" # SSH keys
subnet_id = "subnet-0f2515644bbe8e603" # VPC -> Subnet ID
associate_public_ip_address = true # Public IP for SSH
vpc_security_group_ids = [aws_security_group.ec2_ssh_security.id] # VPC security group
tags = {
Name = "Test-EC2" # Instance name
}
}
# Security group (firewall) for allowing incoming SSH connections
resource "aws_security_group" "ec2_ssh_security" {
name = "allow_ssh" # Firewall rule name
ingress {
# Ingress rules (incoming)
from_port = 22 # Starting port range
to_port = 22 # End port range
protocol = "tcp" # Allowed protocol
cidr_blocks = ["${var.ssh_ingress}"] # Allowed IP ranges
}
egress {
from_port = 0 # Starting port range; 0 implies all ports
to_port = 0 # End port range; 0 implies all ports
protocol = -1 # Allowed protocol; -1 implies all protocols (in HCL)
cidr_blocks = ["0.0.0.0/0"] # Allowed IP ranges
}
# For each protocol, new block; eg. egress { from... to... protocol = "icmp" cidr...}
}
# DynamoDB Table
resource "aws_dynamodb_table" "dynamo-test" {
name = "testTable" # Table name
billing_mode = "PROVISIONED" # Specify billing type; PROVISIONED (provisioned billing mode) / PAY_PER_REQUEST (on-demand billing mode)
read_capacity = 1 # no. of reads per sec.
write_capacity = 1 # no. of writes per sec.
# Attribute
attribute {
name = "username" # Col. name
type = "S" # Col. type;
# S -> String, N -> Number, B -> Binary, BOOL -> Boolean, List -> L (ordered collection of values), Map ->M (key-value pairs), Null -> NULL
}
hash_key = "username" # Primary key
}