Skip to content
Open
Show file tree
Hide file tree
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
Empty file added first-steps/.gitignore
Empty file.
24 changes: 24 additions & 0 deletions first-steps/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions first-steps/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
instance_type = "t3.micro"
63 changes: 57 additions & 6 deletions first-steps/instance.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,62 @@
provider "aws" {
access_key = "ACCESS_KEY_HERE"
secret_key = "SECRET_KEY_HERE"
region = "us-east-1"

region = "us-east-1"
}
data "aws_ami" "amazon_linux" {
most_recent = true

resource "aws_instance" "example" {
ami = "ami-0d729a60"
instance_type = "t2.micro"
owners = ["137112412989"] # Amazon

filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
}
}
resource "aws_instance" "web" {
ami = data.aws_ami.amazon_linux.id
instance_type = var.instance_type["example"]

subnet_id = module.vpc.public_subnets[0]
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
key_name = aws_key_pair.mykey.key_name
user_data = templatefile("${path.module}/templates/web.tpl", {
"region" = var.aws_region
})




tags = {
Name = "example"
}
}

resource "aws_security_group" "allow_ssh" {
name = "allow_ssh"
description = "Allow ssh inbound traffic and all outbound traffic"
vpc_id = module.vpc.vpc_id

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["81.26.206.4/32"]
ipv6_cidr_blocks = ["::/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

tags = {
Name = "allow_ssh"
}
}
resource "aws_key_pair" "mykey" {
key_name = "demo-mykey"
public_key = file("${path.module}/mykey.pub")

}
1 change: 1 addition & 0 deletions first-steps/my.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi, {myvar}
7 changes: 7 additions & 0 deletions first-steps/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "public_ip" {
value = aws_instance.web.public_ip

}
output "public_subnets" {
value = module.vpc.public_subnets
}
2 changes: 2 additions & 0 deletions first-steps/templates/web.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yum update -y
yum install -y nginx
254 changes: 254 additions & 0 deletions first-steps/terraform.tfstate.1777687290.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
{
"version": 4,
"terraform_version": "1.14.8",
"serial": 2,
"lineage": "4b87a9dd-5c2a-9f98-9bd4-11220b937510",
"outputs": {
"public_ip": {
"value": "54.91.84.211",
"type": "string"
}
},
"resources": [
{
"mode": "data",
"type": "aws_ami",
"name": "amazon_linux",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"allow_unsafe_filter": null,
"architecture": "x86_64",
"arn": "arn:aws:ec2:us-east-1::image/ami-02b9a589195146a8f",
"block_device_mappings": [
{
"device_name": "/dev/xvda",
"ebs": {
"delete_on_termination": "true",
"encrypted": "false",
"iops": "0",
"snapshot_id": "snap-00d62ba04fd82e23f",
"throughput": "0",
"volume_initialization_rate": "0",
"volume_size": "8",
"volume_type": "gp2"
},
"no_device": "",
"virtual_name": ""
}
],
"boot_mode": "",
"creation_date": "2026-04-27T17:30:18.000Z",
"deprecation_time": "2026-07-26T17:36:00.000Z",
"description": "Amazon Linux 2 AMI 2.0.20260427.1 x86_64 HVM gp2",
"ena_support": true,
"executable_users": null,
"filter": [
{
"name": "name",
"values": [
"amzn2-ami-hvm-*-x86_64-gp2"
]
}
],
"hypervisor": "xen",
"id": "ami-02b9a589195146a8f",
"image_id": "ami-02b9a589195146a8f",
"image_location": "amazon/amzn2-ami-hvm-2.0.20260427.1-x86_64-gp2",
"image_owner_alias": "amazon",
"image_type": "machine",
"imds_support": "",
"include_deprecated": false,
"kernel_id": "",
"last_launched_time": "",
"most_recent": true,
"name": "amzn2-ami-hvm-2.0.20260427.1-x86_64-gp2",
"name_regex": null,
"owner_id": "137112412989",
"owners": [
"137112412989"
],
"platform": "",
"platform_details": "Linux/UNIX",
"product_codes": [],
"public": true,
"ramdisk_id": "",
"region": "us-east-1",
"root_device_name": "/dev/xvda",
"root_device_type": "ebs",
"root_snapshot_id": "snap-00d62ba04fd82e23f",
"sriov_net_support": "simple",
"state": "available",
"state_reason": {
"code": "UNSET",
"message": "UNSET"
},
"tags": {},
"timeouts": null,
"tpm_support": "",
"uefi_data": null,
"usage_operation": "RunInstances",
"virtualization_type": "hvm"
},
"sensitive_attributes": [],
"identity_schema_version": 0
}
]
},
{
"mode": "managed",
"type": "aws_instance",
"name": "example",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 2,
"attributes": {
"ami": "ami-02b9a589195146a8f",
"arn": "arn:aws:ec2:us-east-1:891377214153:instance/i-0cdd6fe3b9649a42e",
"associate_public_ip_address": true,
"availability_zone": "us-east-1b",
"capacity_reservation_specification": [
{
"capacity_reservation_preference": "open",
"capacity_reservation_target": []
}
],
"cpu_options": [
{
"amd_sev_snp": "",
"core_count": 1,
"nested_virtualization": "",
"threads_per_core": 1
}
],
"credit_specification": [
{
"cpu_credits": "standard"
}
],
"disable_api_stop": false,
"disable_api_termination": false,
"ebs_block_device": [],
"ebs_optimized": false,
"enable_primary_ipv6": null,
"enclave_options": [
{
"enabled": false
}
],
"ephemeral_block_device": [],
"force_destroy": false,
"get_password_data": false,
"hibernation": false,
"host_id": "",
"host_resource_group_arn": null,
"iam_instance_profile": "",
"id": "i-0cdd6fe3b9649a42e",
"instance_initiated_shutdown_behavior": "stop",
"instance_lifecycle": "",
"instance_market_options": [],
"instance_state": "running",
"instance_type": "t2.micro",
"ipv6_address_count": 0,
"ipv6_addresses": [],
"key_name": "",
"launch_template": [],
"maintenance_options": [
{
"auto_recovery": "default"
}
],
"metadata_options": [
{
"http_endpoint": "enabled",
"http_protocol_ipv6": "disabled",
"http_put_response_hop_limit": 1,
"http_tokens": "optional",
"instance_metadata_tags": "disabled"
}
],
"monitoring": false,
"network_interface": [],
"outpost_arn": "",
"password_data": "",
"placement_group": "",
"placement_group_id": "",
"placement_partition_number": 0,
"primary_network_interface": [
{
"delete_on_termination": true,
"network_interface_id": "eni-07f46c736b3076d8b"
}
],
"primary_network_interface_id": "eni-07f46c736b3076d8b",
"private_dns": "ip-172-31-29-218.ec2.internal",
"private_dns_name_options": [
{
"enable_resource_name_dns_a_record": false,
"enable_resource_name_dns_aaaa_record": false,
"hostname_type": "ip-name"
}
],
"private_ip": "172.31.29.218",
"public_dns": "ec2-54-91-84-211.compute-1.amazonaws.com",
"public_ip": "54.91.84.211",
"region": "us-east-1",
"root_block_device": [
{
"delete_on_termination": true,
"device_name": "/dev/xvda",
"encrypted": true,
"iops": 100,
"kms_key_id": "arn:aws:kms:us-east-1:891377214153:key/2d23d82e-832f-48c0-8ece-5818262b5308",
"tags": {},
"tags_all": {},
"throughput": 0,
"volume_id": "vol-0af99ee0742adcfc3",
"volume_size": 8,
"volume_type": "gp2"
}
],
"secondary_network_interface": [],
"secondary_private_ips": [],
"security_groups": [
"default"
],
"source_dest_check": true,
"spot_instance_request_id": "",
"subnet_id": "subnet-03c722d92a42f83df",
"tags": {
"Name": "example"
},
"tags_all": {
"Name": "example"
},
"tenancy": "default",
"timeouts": null,
"user_data": null,
"user_data_base64": null,
"user_data_replace_on_change": false,
"volume_tags": null,
"vpc_security_group_ids": [
"sg-04bc4c5f45b61beed"
]
},
"sensitive_attributes": [],
"identity_schema_version": 0,
"identity": {
"account_id": "891377214153",
"id": "i-0cdd6fe3b9649a42e",
"region": "us-east-1"
},
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6MTIwMDAwMDAwMDAwMCwicmVhZCI6OTAwMDAwMDAwMDAwLCJ1cGRhdGUiOjYwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMiJ9",
"dependencies": [
"data.aws_ami.amazon_linux"
]
}
]
}
],
"check_results": null
}
Binary file added first-steps/var.instance_type
Binary file not shown.
11 changes: 11 additions & 0 deletions first-steps/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "instance_type" {
type = map #map perdoret kur ke me shume se nje instance
default = {
"example" = "t2.micro" #emri i instances
"other instance" = "t3.micro"
}
}

variable "aws_region" {
default = "us-east-1"
}
Loading