Skip to content

Commit 070ad96

Browse files
authored
Merge pull request thombergs#76 from pratikdas/aws-terraform
updated git ignore to exclude DS-Store and uploaded Terraform aws source
2 parents 43b9c83 + aaa07d4 commit 070ad96

File tree

20 files changed

+242
-0
lines changed

20 files changed

+242
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
**/.idea/
22
**/*.iml
3+
**/.DS_Store
4+
**/.terraform
35

aws/aws-terraform/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Terraform for creating Ads Resources
2+
3+
Example code to create/update AWS resources with Terraform.
4+
Examples include Terraform capabilities of using modules, input variables and using Terraform cloud.
5+
6+
## Blog posts
7+
8+
Blog posts about this topic:
9+
10+
* [Using Terraform to create AWS resources](https://reflectoring.io/terraform-aws/)
11+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
terraform {
2+
3+
backend "remote" {
4+
hostname = "app.terraform.io"
5+
organization = "pratikorg"
6+
token = "pj7p59JFwSC4jQ.atlasv1.qfmTxLjTfaM5zKyaQrcGzuTojv6oCyLIoIAO7DkA2ieQY7OyINjINGGMiTczt62p1bs"
7+
workspaces {
8+
name = "my-tf-workspace"
9+
}
10+
}
11+
required_providers {
12+
aws = {
13+
source = "hashicorp/aws"
14+
version = "~> 3.36"
15+
}
16+
}
17+
}
18+
19+
provider "aws" {
20+
profile = "default"
21+
region = "us-west-2"
22+
}
23+
24+
module "app_server" {
25+
source = "./modules/application"
26+
27+
ec2_instance_type = "t2.micro"
28+
ami = "ami-830c94e3"
29+
tags = {
30+
Name = "server for web"
31+
Env = "dev"
32+
}
33+
}
34+
35+
module "app_storage" {
36+
source = "./modules/storage/"
37+
38+
bucket_name = "io.pratik.tf-example-bucket"
39+
env = "dev"
40+
}
41+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "aws_instance" "vm-web" {
2+
ami = var.ami
3+
instance_type = var.ec2_instance_type
4+
tags = var.tags
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "instanceID" {
2+
description = "ID of ec2 instance"
3+
value = aws_instance.vm-web.id
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
variable "ec2_instance_type" {
2+
description = "Instance type"
3+
type = string
4+
}
5+
6+
variable "ami" {
7+
description = "ami id"
8+
type = string
9+
}
10+
11+
variable "tags" {
12+
description = "Tags to set on the bucket."
13+
type = map(string)
14+
default = {Name = "server for web"
15+
Env = "dev"}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "aws_s3_bucket" "s3_bucket" {
2+
bucket = format("%s-%s",var.bucket_name,var.env)
3+
acl = "private"
4+
5+
tags = {
6+
Name = var.bucket_name
7+
Environment = var.env
8+
}
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "arn" {
2+
description = "ARN of the bucket"
3+
value = aws_s3_bucket.s3_bucket.arn
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Input variable definitions
2+
3+
variable "bucket_name" {
4+
description = "Name of bucket"
5+
type = string
6+
}
7+
8+
variable "env" {
9+
description = "Environment like dev, prod"
10+
type = string
11+
}
12+
13+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 3.27"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
profile = "default"
12+
region = "us-west-2"
13+
}
14+
15+
resource "aws_instance" "vm-web" {
16+
ami = "ami-830c94e3"
17+
instance_type = var.ec2_instance_type
18+
19+
tags = {
20+
Name = "server for web"
21+
Env = "dev"
22+
}
23+
}
24+

0 commit comments

Comments
 (0)