File tree Expand file tree Collapse file tree 10 files changed +134
-0
lines changed
Expand file tree Collapse file tree 10 files changed +134
-0
lines changed Original file line number Diff line number Diff line change 1+ data "aws_ami" "aws_ami" {
2+ owners = [" amazon" , " self" ]
3+ most_recent = true
4+
5+ filter {
6+ name = " name"
7+ values = [" amzn-ami-hvm-*-x86_64-gp2" ]
8+ }
9+ }
10+
11+ module "webserver" {
12+ source = " ./modules/web"
13+
14+ instance_type = var. instance_type
15+ ami_id = data. aws_ami . aws_ami . id
16+ }
17+
18+ output "public_ip" {
19+ value = module. webserver . public_ip
20+ }
Original file line number Diff line number Diff line change 1+ <!-- BEGIN_TF_DOCS -->
2+ ## Requirements
3+
4+ | Name | Version |
5+ | ------| ---------|
6+ | <a name =" requirement_terraform " ></a > [ terraform] ( #requirement\_ terraform ) | 1.6.6 |
7+ | <a name =" requirement_aws " ></a > [ aws] ( #requirement\_ aws ) | 5.31.0 |
8+
9+ ## Providers
10+
11+ | Name | Version |
12+ | ------| ---------|
13+ | <a name =" provider_aws " ></a > [ aws] ( #provider\_ aws ) | 5.31.0 |
14+
15+ ## Modules
16+
17+ No modules.
18+
19+ ## Resources
20+
21+ | Name | Type |
22+ | ------| ------|
23+ | [ aws_instance.amzn] ( https://registry.terraform.io/providers/hashicorp/aws/5.31.0/docs/resources/instance ) | resource |
24+ | [ aws_security_group.allow_ssh] ( https://registry.terraform.io/providers/hashicorp/aws/5.31.0/docs/resources/security_group ) | resource |
25+
26+ ## Inputs
27+
28+ | Name | Description | Type | Default | Required |
29+ | ------| -------------| ------| ---------| :--------:|
30+ | <a name =" input_ami_id " ></a > [ ami\_ id] ( #input\_ ami\_ id ) | AMI ID | ` string ` | n/a | yes |
31+ | <a name =" input_instance_type " ></a > [ instance\_ type] ( #input\_ instance\_ type ) | Instance Type | ` string ` | n/a | yes |
32+
33+ ## Outputs
34+
35+ | Name | Description |
36+ | ------| -------------|
37+ | <a name =" output_public_ip " ></a > [ public\_ ip] ( #output\_ public\_ ip ) | Public IP of the EC2 instance |
38+ <!-- END_TF_DOCS -->
Original file line number Diff line number Diff line change 1+ resource "aws_instance" "amzn" {
2+ ami = var. ami_id
3+ instance_type = var. instance_type
4+ security_groups = [aws_security_group . allow_ssh . name ]
5+ }
6+
7+ resource "aws_security_group" "allow_ssh" {
8+ name = " allow_ssh"
9+ description = " Allow SSH inbound traffic"
10+
11+ ingress {
12+ description = " SSH from VPC"
13+ from_port = 22
14+ to_port = 22
15+ protocol = " tcp"
16+ cidr_blocks = [" 0.0.0.0/0" ]
17+ }
18+
19+ egress {
20+ description = " Allow all outbound traffic"
21+ from_port = 0
22+ to_port = 0
23+ protocol = " -1"
24+ cidr_blocks = [" 0.0.0.0/0" ]
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ output "public_ip" {
2+ value = aws_instance. amzn . public_ip
3+ description = " Public IP of the EC2 instance"
4+ }
Original file line number Diff line number Diff line change 1+ variable "instance_type" {
2+ type = string
3+ description = " Instance Type"
4+ }
5+
6+ variable "ami_id" {
7+ type = string
8+ description = " AMI ID"
9+ }
Original file line number Diff line number Diff line change 1+ terraform {
2+ required_version = " 1.6.6"
3+
4+ required_providers {
5+ aws = {
6+ source = " hashicorp/aws"
7+ version = " 5.31.0"
8+ }
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ variable "aws_region" {
2+ type = string
3+ default = " eu-west-1"
4+ }
5+
6+ variable "instance_type" {
7+ type = string
8+ default = " t3.micro"
9+ }
Original file line number Diff line number Diff line change 1+ aws_region = " us-east-1"
2+ instance_type = " m5.large"
Original file line number Diff line number Diff line change 1+ aws_region = " eu-west-1"
2+ instance_type = " t3.micro"
Original file line number Diff line number Diff line change 1+ terraform {
2+ required_version = " 1.6.6"
3+
4+ required_providers {
5+ aws = {
6+ source = " hashicorp/aws"
7+ version = " >= 5.0"
8+ }
9+ }
10+ }
11+
12+ provider "aws" {
13+ region = var. aws_region
14+ }
You can’t perform that action at this time.
0 commit comments