Skip to content

Commit

Permalink
code modified
Browse files Browse the repository at this point in the history
  • Loading branch information
VIKAS KUMAR committed Sep 20, 2023
1 parent 6e3f4b9 commit c02e80b
Show file tree
Hide file tree
Showing 47 changed files with 615 additions and 16 deletions.
44 changes: 44 additions & 0 deletions Terraform/0-ec2-with-sg-eip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
Resources:
MyInstance:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: us-east-1a
ImageId: ami-a4c7edb2
InstanceType: t2.micro
SecurityGroups:
- !Ref SSHSecurityGroup
- !Ref ServerSecurityGroup

MyEIP:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html
Type: AWS::EC2::EIP
Properties:
InstanceId: !Ref MyInstance

SSHSecurityGroup:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 22
IpProtocol: tcp
ToPort: 22

ServerSecurityGroup:
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: allow connections from specified CIDR ranges
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 192.168.1.1/32
16 changes: 16 additions & 0 deletions Terraform/Intrinsic-Function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
AWSTemplateFormatVersion: 2010-09-09
Description: Using intrinsic Functions and parameters
Parameters:
s3NamePrefix:
Description: Enter the unique prefix to the name of the S3 bucket you need to create
Type: String
Default: mybucket
Resources:
s3Bucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Join
- '-'
- - !Ref s3NamePrefix
- !Ref 'AWS::StackName'
- !Ref 'AWS::Region'
57 changes: 57 additions & 0 deletions Terraform/helper-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
AWSTemplateFormatVersion: 2010-09-09
Resources:
myInstance:
Type: 'AWS::EC2::Instance'
Metadata:
'AWS::CloudFormation::Init':
config:
packages:
yum:
httpd: []
files:
/var/www/html/index.html:
content: !Join
- ''
- - This is created by cfn-init
mode: '000644'
owner: root
group: root
commands:
StartApache:
command: service httpd start
Properties:
KeyName: predefined-kp-nagios
ImageId: ami-0b0dcb5067f052a63
SecurityGroupIds:
- sg-0cb18b26f2c93a0e7
InstanceType: t2.micro
UserData: !Base64
'Fn::Join':
- ''
- - |
#!/bin/bash -ex
- |
yum install -y aws-cfn-bootstrap
- |
# Install the files and packages from the metadata
- '/opt/aws/bin/cfn-init -v '
- ' --stack '
- !Ref 'AWS::StackName'
- ' --resource myInstance '
- ' --region '
- !Ref 'AWS::Region'
- |+
- |
# Signal the status from cfn-init
- '/opt/aws/bin/cfn-signal -e $? '
- ' --stack '
- !Ref 'AWS::StackName'
- ' --resource myInstance'
- ' --region '
- !Ref 'AWS::Region'
- |+
CreationPolicy:
ResourceSignal:
Timeout: PT5M
173 changes: 173 additions & 0 deletions Terraform/sample-cfmt-code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
AWSTemplateFormatVersion: 2010-09-09
Metadata:
'AWS::CloudFormation::Designer':
ee59f526-783c-4e22-a540-9387a8a711dc:
size:
width: 60
height: 60
position:
x: 430
'y': 50
z: 0
embeds: []
df569c93-fd6f-4629-9755-bb4d53f32c16:
size:
width: 60
height: 60
position:
x: 288
'y': 49
z: 0
embeds: []
isassociatedwith:
- ee59f526-783c-4e22-a540-9387a8a711dc
a429408b-bfc8-4dab-bfa6-c0577d202cda:
size:
width: 710
height: 230
position:
x: 148
'y': 142
z: 0
embeds:
- b90e9fcb-6787-4032-8b8a-5dab1d67813f
- 32659fa8-5a86-4b09-a2f9-d1491f5e033a
b90e9fcb-6787-4032-8b8a-5dab1d67813f:
size:
width: 220
height: 150
position:
x: 180
'y': 200
z: 1
parent: a429408b-bfc8-4dab-bfa6-c0577d202cda
embeds:
- 61ca9ad8-8357-4dd3-852b-dc5b7184089d
- a76443f8-4f7d-4c6b-8726-cba284bef6fa
iscontainedinside:
- a429408b-bfc8-4dab-bfa6-c0577d202cda
- a429408b-bfc8-4dab-bfa6-c0577d202cda
32659fa8-5a86-4b09-a2f9-d1491f5e033a:
size:
width: 80
height: 80
position:
x: 440
'y': 230
z: 1
parent: a429408b-bfc8-4dab-bfa6-c0577d202cda
dependson:
- aee90b98-7e71-4856-89f5-a11b8ec65a0e
aee90b98-7e71-4856-89f5-a11b8ec65a0e:
size:
width: 60
height: 60
position:
x: 800
'y': 230
z: 0
61ca9ad8-8357-4dd3-852b-dc5b7184089d:
size:
width: 60
height: 60
position:
x: 197
'y': 236
z: 2
parent: b90e9fcb-6787-4032-8b8a-5dab1d67813f
iscontainedinside:
- b90e9fcb-6787-4032-8b8a-5dab1d67813f
a76443f8-4f7d-4c6b-8726-cba284bef6fa:
size:
width: 60
height: 60
position:
x: 312
'y': 237
z: 2
parent: b90e9fcb-6787-4032-8b8a-5dab1d67813f
dependson:
- 61ca9ad8-8357-4dd3-852b-dc5b7184089d
40244b57-595f-4e2c-98c0-8096e16ab21c:
source:
id: a76443f8-4f7d-4c6b-8726-cba284bef6fa
target:
id: 61ca9ad8-8357-4dd3-852b-dc5b7184089d
z: 11
9aa95c4f-6437-461d-91df-0ab95022482e:
source:
id: 32659fa8-5a86-4b09-a2f9-d1491f5e033a
target:
id: b90e9fcb-6787-4032-8b8a-5dab1d67813f
z: 12
018c5753-7464-464e-b746-0bae439189f6:
source:
id: 32659fa8-5a86-4b09-a2f9-d1491f5e033a
target:
id: aee90b98-7e71-4856-89f5-a11b8ec65a0e
z: 13
Resources:
samplebucket15112021:
Type: 'AWS::S3::Bucket'
Properties: {}
Metadata:
'AWS::CloudFormation::Designer':
id: ee59f526-783c-4e22-a540-9387a8a711dc
S3BP56RT6:
Type: 'AWS::S3::BucketPolicy'
Properties:
Bucket: !Ref samplebucket15112021
Metadata:
'AWS::CloudFormation::Designer':
id: df569c93-fd6f-4629-9755-bb4d53f32c16
EC2VPC5CBX:
Type: 'AWS::EC2::VPC'
Properties: {}
Metadata:
'AWS::CloudFormation::Designer':
id: a429408b-bfc8-4dab-bfa6-c0577d202cda
EC2S541S9:
Type: 'AWS::EC2::Subnet'
Properties:
VpcId: !Ref EC2VPC5CBX
Metadata:
'AWS::CloudFormation::Designer':
id: b90e9fcb-6787-4032-8b8a-5dab1d67813f
EC2RT3Z4BU:
Type: 'AWS::EC2::RouteTable'
Properties: {}
Metadata:
'AWS::CloudFormation::Designer':
id: 32659fa8-5a86-4b09-a2f9-d1491f5e033a
DependsOn:
- EC2IG4HIT1
EC2IG4HIT1:
Type: 'AWS::EC2::InternetGateway'
Properties: {}
Metadata:
'AWS::CloudFormation::Designer':
id: aee90b98-7e71-4856-89f5-a11b8ec65a0e
EC2I3N0M9:
Type: 'AWS::EC2::Instance'
Properties:
NetworkInterfaces:
- SubnetId: !Ref EC2S541S9
Metadata:
'AWS::CloudFormation::Designer':
id: 61ca9ad8-8357-4dd3-852b-dc5b7184089d
EC2SG4D1MZ:
Type: 'AWS::EC2::SecurityGroup'
Properties: {}
Metadata:
'AWS::CloudFormation::Designer':
id: a76443f8-4f7d-4c6b-8726-cba284bef6fa
DependsOn:
- EC2I3N0M9
EC2SRTAD0SG:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref EC2RT3Z4BU
SubnetId: !Ref EC2S541S9
Metadata:
'AWS::CloudFormation::Designer':
id: 9aa95c4f-6437-461d-91df-0ab95022482e
10 changes: 10 additions & 0 deletions common-cmds
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform show -- > better visualization of state file
terraform show | grep public_ip
terraform output -- > see final output
terraform taint will mark the resource for refresh
terraform refresh to just refresh the state
terraform import aws_instance.name <id>
terraform get
terraform remote

terraform apply -var ENV=dev
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 0 additions & 11 deletions others/terraform-wards/first-steps/instance.tf

This file was deleted.

4 changes: 0 additions & 4 deletions others/terraform-wards/tf-instance-script/versions.tf

This file was deleted.

Binary file not shown.
59 changes: 59 additions & 0 deletions presentation+installation/edward/Code.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Data Types in Terraform:
1. string
2. number
3. bool
4. List(type) == [1,2,3,4] -> List with unique values is called tuple
5. Set(type) == order is not maintained and has unique values only
6. Map(type) == {"Key": "value"}
7. Object({<ATTR Name>=<Type>,..})



main.tf
=======
variable "myvar"{
type= "string"
default = "my first variable"
}

variable "mymap"{
type= "map(string)"
default = {
my-key: "my first key"
}
}

variable "mylist"{
type= list
default = [1,2,3]
}
terraform console
var.myvar
"${var.myvar}"
var.mymap["my-key"]
var.mylist[0]
element(var.mylist, 0)
slice(var.mylist, 0, 2)

resources.tf
============
provider "aws" {
access_key = "ACCESS_KEY_HERE"
secret_key = "SECRET_KEY_HERE"
}

variable "AMIS"{
type= "map(string)"
default = {
us-east-1 = "my ami"
}
}

resource "aws_instance" "example" {
ami = var.AMIS[var.AWS_REGION]
instance_type = "t2.micro"
}

terraform.tfvars
================
AWS_REGION="us-east-1"
Loading

0 comments on commit c02e80b

Please sign in to comment.