├── .gitignore ├── 01-Infrastructure-as-Code-IaC-Basics └── README.md ├── 02-Terraform-Basics ├── 02-01-Install-Tools-TerraformCLI-AWSCLI-VSCodeIDE │ └── README.md ├── 02-02-Terraform-Command-Basics │ ├── README.md │ └── terraform-manifests │ │ └── ec2-instance.tf └── 02-03-Terraform-Language-Syntax │ ├── README.md │ └── terraform-manifests │ └── top-level-blocks-samples.tf ├── 03-Terraform-Settings-Providers-Resources ├── README.md └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ └── c2-ec2instance.tf ├── 04-Terraform-Variables-and-Datasources ├── README.md └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c2-variables.tf │ ├── c3-ec2securitygroups.tf │ ├── c4-ami-datasource.tf │ ├── c5-ec2instance.tf │ ├── c6-outputs.tf │ └── private-key │ └── terraform-key.pem ├── 05-Terraform-Loops-MetaArguments-SplatOperator ├── 05-01-MetaArgument-Count-For-Loops-Lists-Maps │ ├── README.md │ └── terraform-manifests │ │ ├── app1-install.sh │ │ ├── c1-versions.tf │ │ ├── c2-variables.tf │ │ ├── c3-ec2securitygroups.tf │ │ ├── c4-ami-datasource.tf │ │ ├── c5-ec2instance.tf │ │ ├── c6-outputs.tf │ │ └── private-key │ │ └── terraform-key.pem ├── 05-02-MetaArgument-for_each │ ├── README.md │ └── terraform-manifests │ │ ├── app1-install.sh │ │ ├── c1-versions.tf │ │ ├── c2-variables.tf │ │ ├── c3-ec2securitygroups.tf │ │ ├── c4-ami-datasource.tf │ │ ├── c5-ec2instance.tf │ │ ├── c6-outputs.tf │ │ └── private-key │ │ └── terraform-key.pem ├── 05-03-Utility-Project │ ├── README.md │ └── terraform-manifests │ │ ├── c1-versions.tf │ │ ├── c2-v1-get-instancetype-supported-per-az-in-a-region.tf │ │ ├── c2-v2-get-instancetype-supported-per-az-in-a-region.tf │ │ └── c2-v3-get-instancetype-supported-per-az-in-a-region.tf └── 05-04-for_each-with-az-instancetype-check │ ├── README.md │ └── terraform-manifests │ ├── app1-install.sh │ ├── backup │ └── c5-ec2instance.tf │ ├── c1-versions.tf │ ├── c2-variables.tf │ ├── c3-ec2securitygroups.tf │ ├── c4-ami-datasource.tf │ ├── c5-ec2instance.tf │ ├── c6-outputs.tf │ ├── c7-get-instancetype-supported-per-az-in-a-region.tf │ └── private-key │ └── terraform-key.pem ├── 06-AWS-VPC ├── 06-01-AWS-VPC-using-Mgmt-Console │ └── README.md └── 06-02-AWS-VPC-using-Terraform │ ├── README.md │ └── terraform-manifests │ ├── v1-vpc-module │ ├── c1-versions.tf │ ├── c2-generic-variables.tf │ └── c3-vpc.tf │ └── v2-vpc-module-standardized │ ├── c1-versions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 07-AWS-EC2Instance-and-SecurityGroups ├── README.md ├── terraform-manifests-ec2private-module-version330 │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c6-01-datasource-ami.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ │ ├── backup-demo-kalyan │ │ │ ├── creation-time-vpc-id.txt │ │ │ └── destroy-time-prov.txt │ │ ├── creation-time-vpc-id.txt │ │ └── destroy-time-prov.txt │ ├── private-key │ │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c6-01-datasource-ami.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ └── backup-demo-kalyan │ │ ├── creation-time-vpc-id.txt │ │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 08-AWS-ELB-Classic-LoadBalancer ├── README.md └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c10-01-ELB-classic-loadbalancer-variables.tf │ ├── c10-02-ELB-classic-loadbalancer.tf │ ├── c10-03-ELB-classic-loadbalancer-outputs.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ └── backup-demo-kalyan │ │ ├── creation-time-vpc-id.txt │ │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 09-AWS-ALB-Application-LoadBalancer-Basic ├── README.md └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 10-ALB-Path-Based-Routing ├── README.md └── terraform-manifests │ ├── 14-ALB-Autoscaling-with-Launch-Configuration │ ├── README.md │ └── terraform-manifests │ │ ├── .terraform.lock.hcl │ │ ├── app1-install.sh │ │ ├── c1-versions.tf │ │ ├── c10-acm-certificatemanager.tf │ │ ├── c11-ALB-Application-loadbalancer.tf │ │ ├── c12-route53-dnsregistration.tf │ │ ├── c13-autoscaling-launchconfiguration.tf │ │ ├── c14-o1-asg-outputs.tf │ │ ├── c14-o2-alb-outputs.tf │ │ ├── c14-outputs.tf │ │ ├── c2-variables.tf │ │ ├── c3-local-values.tf │ │ ├── c4-vpc.tf │ │ ├── c5-ec2securitygroup.tf │ │ ├── c6-ami-datasource.tf │ │ ├── c7-ec2instance.tf │ │ ├── c8-elasticip.tf │ │ ├── c9-nullresource-provisioners.tf │ │ ├── private-key │ │ └── terraform-key.pem │ │ └── terraform.tfvars │ ├── app1-install.sh │ ├── app2-install.sh │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private-app1.tf │ ├── c7-05-ec2instance-private-app2.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 11-ALB-Host-Header-Based-Routing ├── README.md ├── terraform-manifests-us-east-2 │ ├── app1-install.sh │ ├── app2-install.sh │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private-app1.tf │ ├── c7-05-ec2instance-private-app2.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── loadbalancer.auto.tfvars │ ├── local-exec-output-files │ │ ├── creation-time-vpc-id.txt │ │ └── destroy-time-prov.txt │ ├── private-key │ │ ├── terraform-key-us-east-2.pem │ │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars └── terraform-manifests │ ├── app1-install.sh │ ├── app2-install.sh │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private-app1.tf │ ├── c7-05-ec2instance-private-app2.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── loadbalancer.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ ├── terraform-key-us-east-2.pem │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 12-ALB-HTTPHeader-QueryString-Redirects ├── README.md └── terraform-manifests │ ├── app1-install.sh │ ├── app2-install.sh │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private-app1.tf │ ├── c7-05-ec2instance-private-app2.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── loadbalancer.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ ├── terraform-key-us-east-2.pem │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 13-DNS-to-DB ├── README.md ├── templatefile-function-demo │ └── app3-ums-install.tmpl └── terraform-manifests │ ├── app1-install.sh │ ├── app2-install.sh │ ├── app3-ums-install.tmpl │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c13-01-rdsdb-variables.tf │ ├── c13-02-rdsdb.tf │ ├── c13-03-rdsdb-outputs.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c5-06-securitygroup-rdsdbsg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c7-04-ec2instance-private-app1.tf │ ├── c7-05-ec2instance-private-app2.tf │ ├── c7-06-ec2instance-private-app3.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── jumpbox-install.sh │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── rdsdb.auto.tfvars │ ├── secrets.tfvars │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 14-Autoscaling-with-Launch-Configuration ├── README.md └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c13-01-autoscaling-with-launchconfiguration-variables.tf │ ├── c13-02-autoscaling-additional-resoures.tf │ ├── c13-03-autoscaling-with-launchconfiguration.tf │ ├── c13-04-autoscaling-with-launchconfiguration-outputs.tf │ ├── c13-05-autoscaling-notifications.tf │ ├── c13-06-autoscaling-ttsp.tf │ ├── c13-07-autoscaling-scheduled-actions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 15-Autoscaling-with-Launch-Templates ├── README.md └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c13-01-autoscaling-with-launchtemplate-variables.tf │ ├── c13-02-autoscaling-launchtemplate-resource.tf │ ├── c13-03-autoscaling-resource.tf │ ├── c13-04-autoscaling-with-launchtemplate-outputs.tf │ ├── c13-05-autoscaling-notifications.tf │ ├── c13-06-autoscaling-ttsp.tf │ ├── c13-07-autoscaling-scheduled-actions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 16-AWS-NLB-Network-Load-Balancer ├── README.md └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c10-01-NLB-network-loadbalancer-variables.tf │ ├── c10-02-NLB-network-loadbalancer.tf │ ├── c10-03-NLB-network-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c13-01-autoscaling-with-launchtemplate-variables.tf │ ├── c13-02-autoscaling-launchtemplate-resource.tf │ ├── c13-03-autoscaling-resource.tf │ ├── c13-04-autoscaling-with-launchtemplate-outputs.tf │ ├── c13-05-autoscaling-notifications.tf │ ├── c13-06-autoscaling-ttsp.tf │ ├── c13-07-autoscaling-scheduled-actions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 17-AWS-CloudWatch ├── README.md ├── cw-synthetics-manifests-v1 │ ├── c1-versions.tf │ ├── c14-05-cloudwatch-synthetics.tf │ └── sswebsite2 │ │ ├── nodejs │ │ └── node_modules │ │ │ └── sswebsite2.js │ │ └── sswebsite2v1.zip ├── cw-synthetics-manifests-v2 │ ├── c1-versions.tf │ ├── c14-05-cloudwatch-synthetics.tf │ ├── c9-import-role.tf │ └── sswebsite2 │ │ ├── nodejs │ │ └── node_modules │ │ │ └── sswebsite2.js │ │ └── sswebsite2v1.zip ├── temp-alarm │ ├── temp-alarm.tf │ ├── terraform.tfstate-file-alb │ └── terraform.tfstate-file-synthetics-canary └── terraform-manifests │ ├── app1-install.sh │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c13-01-autoscaling-with-launchtemplate-variables.tf │ ├── c13-02-autoscaling-launchtemplate-resource.tf │ ├── c13-03-autoscaling-resource.tf │ ├── c13-04-autoscaling-with-launchtemplate-outputs.tf │ ├── c13-05-autoscaling-notifications.tf │ ├── c13-06-autoscaling-ttsp.tf │ ├── c13-07-autoscaling-scheduled-actions.tf │ ├── c14-01-cloudwatch-variables.tf │ ├── c14-02-cloudwatch-asg-alarms.tf │ ├── c14-03-cloudwatch-alb-alarms.tf │ ├── c14-04-cloudwatch-cis-alarms.tf │ ├── c14-05-cloudwatch-synthetics.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ ├── sswebsite2 │ ├── nodejs │ │ └── node_modules │ │ │ └── sswebsite2.js │ └── sswebsite2v1.zip │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 18-Develop-Terraform-Modules-Locally ├── README.md ├── backup-terraform-manifests │ ├── c1-versions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── modules │ │ └── aws-vpc │ │ │ ├── .editorconfig │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── UPGRADE-3.0.md │ │ │ ├── main.tf │ │ │ ├── modules │ │ │ └── vpc-endpoints │ │ │ │ ├── README.md │ │ │ │ ├── main.tf │ │ │ │ ├── outputs.tf │ │ │ │ ├── variables.tf │ │ │ │ └── versions.tf │ │ │ ├── outputs.tf │ │ │ ├── variables.tf │ │ │ ├── versions.tf │ │ │ └── vpc-flow-logs.tf │ ├── terraform.tfvars │ └── vpc.auto.tfvars └── terraform-manifests │ ├── c1-versions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── modules │ └── aws-vpc │ │ ├── .gitignore │ │ ├── README.md │ │ ├── main.tf │ │ ├── modules │ │ └── vpc-endpoints │ │ │ ├── README.md │ │ │ ├── main.tf │ │ │ ├── outputs.tf │ │ │ ├── variables.tf │ │ │ └── versions.tf │ │ ├── outputs.tf │ │ ├── variables.tf │ │ ├── versions.tf │ │ └── vpc-flow-logs.tf │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 19-Develop-Terraform-Module-from-scratch ├── README.md ├── v1-create-static-website-on-s3-using-aws-mgmt-console │ ├── index.html │ └── policy-public-read-access-for-website.json ├── v2-host-static-website-on-s3-using-terraform-manifests │ ├── main.tf │ ├── outputs.tf │ ├── terraform.tfvars │ ├── variables.tf │ └── versions.tf └── v3-build-a-module-to-host-static-website-on-aws-s3 │ ├── c1-versions.tf │ ├── c2-variables.tf │ ├── c3-s3bucket.tf │ ├── c4-outputs.tf │ └── modules │ └── aws-s3-static-website-bucket │ ├── LICENSE │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── 20-Remote-State-Storage-with-AWS-S3-and-DynamoDB ├── README.md └── project-1-aws-vpc │ ├── c1-versions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── terraform.tfvars │ └── vpc.auto.tfvars ├── 21-terraform-remote-state-datasource ├── README.md ├── project-1-aws-vpc │ ├── c1-versions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c4-01-vpc-variables.tf │ ├── c4-02-vpc-module.tf │ ├── c4-03-vpc-outputs.tf │ ├── terraform.tfvars │ └── vpc.auto.tfvars └── project-2-app1-with-asg-and-alb │ ├── app1-install.sh │ ├── c0-terraform-remote-state-datasource.tf │ ├── c1-versions.tf │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ ├── c10-02-ALB-application-loadbalancer.tf │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ ├── c11-acm-certificatemanager.tf │ ├── c12-route53-dnsregistration.tf │ ├── c13-01-autoscaling-with-launchtemplate-variables.tf │ ├── c13-02-autoscaling-launchtemplate-resource.tf │ ├── c13-03-autoscaling-resource.tf │ ├── c13-04-autoscaling-with-launchtemplate-outputs.tf │ ├── c13-05-autoscaling-notifications.tf │ ├── c13-06-autoscaling-ttsp.tf │ ├── c13-07-autoscaling-scheduled-actions.tf │ ├── c2-generic-variables.tf │ ├── c3-local-values.tf │ ├── c5-01-securitygroup-variables.tf │ ├── c5-02-securitygroup-outputs.tf │ ├── c5-03-securitygroup-bastionsg.tf │ ├── c5-04-securitygroup-privatesg.tf │ ├── c5-05-securitygroup-loadbalancersg.tf │ ├── c6-01-datasource-ami.tf │ ├── c6-02-datasource-route53-zone.tf │ ├── c7-01-ec2instance-variables.tf │ ├── c7-02-ec2instance-outputs.tf │ ├── c7-03-ec2instance-bastion.tf │ ├── c8-elasticip.tf │ ├── c9-nullresource-provisioners.tf │ ├── ec2instance.auto.tfvars │ ├── local-exec-output-files │ ├── creation-time-vpc-id.txt │ └── destroy-time-prov.txt │ ├── private-key │ └── terraform-key.pem │ └── terraform.tfvars ├── 22-IaC-DevOps-using-AWS-CodePipeline ├── Git-Repo-Files │ ├── .gitignore │ ├── README.md │ ├── buildspec-dev.yml │ ├── buildspec-stag.yml │ └── terraform-manifests │ │ ├── app1-install.sh │ │ ├── c1-versions.tf │ │ ├── c10-01-ALB-application-loadbalancer-variables.tf │ │ ├── c10-02-ALB-application-loadbalancer.tf │ │ ├── c10-03-ALB-application-loadbalancer-outputs.tf │ │ ├── c11-acm-certificatemanager.tf │ │ ├── c12-route53-dnsregistration.tf │ │ ├── c13-01-autoscaling-with-launchtemplate-variables.tf │ │ ├── c13-02-autoscaling-launchtemplate-resource.tf │ │ ├── c13-03-autoscaling-resource.tf │ │ ├── c13-04-autoscaling-with-launchtemplate-outputs.tf │ │ ├── c13-05-autoscaling-notifications.tf │ │ ├── c13-06-autoscaling-ttsp.tf │ │ ├── c13-07-autoscaling-scheduled-actions.tf │ │ ├── c2-generic-variables.tf │ │ ├── c3-local-values.tf │ │ ├── c4-01-vpc-variables.tf │ │ ├── c4-02-vpc-module.tf │ │ ├── c4-03-vpc-outputs.tf │ │ ├── c5-01-securitygroup-variables.tf │ │ ├── c5-02-securitygroup-outputs.tf │ │ ├── c5-03-securitygroup-bastionsg.tf │ │ ├── c5-04-securitygroup-privatesg.tf │ │ ├── c5-05-securitygroup-loadbalancersg.tf │ │ ├── c6-01-datasource-ami.tf │ │ ├── c6-02-datasource-route53-zone.tf │ │ ├── c7-01-ec2instance-variables.tf │ │ ├── c7-02-ec2instance-outputs.tf │ │ ├── c7-03-ec2instance-bastion.tf │ │ ├── c8-elasticip.tf │ │ ├── c9-nullresource-provisioners.tf │ │ ├── dev.conf │ │ ├── dev.tfvars │ │ ├── private-key │ │ └── terraform-key.pem │ │ ├── stag.conf │ │ ├── stag.tfvars │ │ └── terraform.tfvars └── README.md ├── README.md ├── git-deploy.sh └── presentation └── Terraform-On-AWS-v2.pptx /.gitignore: -------------------------------------------------------------------------------- 1 | /ADDITIONAL-TOPICS 2 | FUTURE-TOPICS 3 | #.gitignore 4 | 5 | # macOS Files 6 | .DS_Store 7 | 8 | # Ignore .sh files 9 | #*.sh 10 | 11 | # Terraform Files and Folders 12 | .terraform 13 | *.tfstate 14 | *.tfstate.backup 15 | #.terraform.lock.hcl 16 | #*.tfvars 17 | 18 | # Ignore .pem files 19 | #*.pem 20 | -------------------------------------------------------------------------------- /01-Infrastructure-as-Code-IaC-Basics/README.md: -------------------------------------------------------------------------------- 1 | # Infrastructure as Code Basics 2 | 3 | ## Step-01: Understand Problems with Traditional way of Managing Infrastructure 4 | - Time it takes for building multiple environments 5 | - Issues we face with different environments 6 | - Scale-Up and Scale-Down On-Demand 7 | 8 | ## Step-02: Discuss how IaC with Terraform Solves them 9 | - Visibility 10 | - Stability 11 | - Scalability 12 | - Security 13 | - Audit -------------------------------------------------------------------------------- /02-Terraform-Basics/02-02-Terraform-Command-Basics/terraform-manifests/ec2-instance.tf: -------------------------------------------------------------------------------- 1 | # Terraform Settings Block 2 | terraform { 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | #version = "~> 3.21" # Optional but recommended in production 7 | } 8 | } 9 | } 10 | 11 | # Provider Block 12 | provider "aws" { 13 | profile = "default" # AWS Credentials Profile configured on your local desktop terminal $HOME/.aws/credentials 14 | region = "us-east-1" 15 | } 16 | 17 | # Resource Block 18 | resource "aws_instance" "ec2demo" { 19 | ami = "ami-0533f2ba8a1995cf9" # Amazon Linux in us-east-1, update as per your region 20 | instance_type = "t2.micro" 21 | } 22 | -------------------------------------------------------------------------------- /03-Terraform-Settings-Providers-Resources/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | # Provider Block 12 | provider "aws" { 13 | region = "us-east-1" 14 | } 15 | 16 | /* 17 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 18 | $HOME/.aws/credentials 19 | */ 20 | 21 | -------------------------------------------------------------------------------- /03-Terraform-Settings-Providers-Resources/terraform-manifests/c2-ec2instance.tf: -------------------------------------------------------------------------------- 1 | # Resource: EC2 Instance 2 | resource "aws_instance" "myec2vm" { 3 | ami = "ami-0742b4e673072066f" 4 | instance_type = "t3.micro" 5 | user_data = file("${path.module}/app1-install.sh") 6 | tags = { 7 | "Name" = "EC2 Demo" 8 | } 9 | } -------------------------------------------------------------------------------- /04-Terraform-Variables-and-Datasources/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /04-Terraform-Variables-and-Datasources/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | } 16 | /* 17 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 18 | $HOME/.aws/credentials 19 | */ 20 | -------------------------------------------------------------------------------- /04-Terraform-Variables-and-Datasources/terraform-manifests/c2-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | 9 | # AWS EC2 Instance Type 10 | variable "instance_type" { 11 | description = "EC2 Instnace Type" 12 | type = string 13 | default = "t3.micro" 14 | } 15 | 16 | # AWS EC2 Instance Key Pair 17 | variable "instance_keypair" { 18 | description = "AWS EC2 Key Pair that need to be associated with EC2 Instance" 19 | type = string 20 | default = "terraform-key" 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /04-Terraform-Variables-and-Datasources/terraform-manifests/c4-ami-datasource.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = ["amazon"] 5 | filter { 6 | name = "name" 7 | values = ["amzn2-ami-hvm-*-gp2"] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = ["ebs"] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = ["hvm"] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = ["x86_64"] 20 | } 21 | } -------------------------------------------------------------------------------- /04-Terraform-Variables-and-Datasources/terraform-manifests/c5-ec2instance.tf: -------------------------------------------------------------------------------- 1 | # EC2 Instance 2 | resource "aws_instance" "myec2vm" { 3 | ami = data.aws_ami.amzlinux2.id 4 | instance_type = var.instance_type 5 | user_data = file("${path.module}/app1-install.sh") 6 | key_name = var.instance_keypair 7 | vpc_security_group_ids = [ aws_security_group.vpc-ssh.id, aws_security_group.vpc-web.id ] 8 | tags = { 9 | "Name" = "EC2 Demo 2" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /04-Terraform-Variables-and-Datasources/terraform-manifests/c6-outputs.tf: -------------------------------------------------------------------------------- 1 | # Terraform Output Values 2 | 3 | # EC2 Instance Public IP 4 | output "instance_publicip" { 5 | description = "EC2 Instance Public IP" 6 | value = aws_instance.myec2vm.public_ip 7 | } 8 | 9 | # EC2 Instance Public DNS 10 | output "instance_publicdns" { 11 | description = "EC2 Instance Public DNS" 12 | value = aws_instance.myec2vm.public_dns 13 | } 14 | -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-01-MetaArgument-Count-For-Loops-Lists-Maps/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | } 16 | /* 17 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 18 | $HOME/.aws/credentials 19 | */ 20 | -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-01-MetaArgument-Count-For-Loops-Lists-Maps/terraform-manifests/c4-ami-datasource.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = ["amazon"] 5 | filter { 6 | name = "name" 7 | values = ["amzn2-ami-hvm-*-gp2"] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = ["ebs"] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = ["hvm"] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = ["x86_64"] 20 | } 21 | } -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-02-MetaArgument-for_each/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | } 16 | /* 17 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 18 | $HOME/.aws/credentials 19 | */ 20 | -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-02-MetaArgument-for_each/terraform-manifests/c2-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | 9 | # AWS EC2 Instance Type 10 | variable "instance_type" { 11 | description = "EC2 Instnace Type" 12 | type = string 13 | default = "t3.micro" 14 | } 15 | 16 | # AWS EC2 Instance Key Pair 17 | variable "instance_keypair" { 18 | description = "AWS EC2 Key Pair that need to be associated with EC2 Instance" 19 | type = string 20 | default = "terraform-key" 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-02-MetaArgument-for_each/terraform-manifests/c4-ami-datasource.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = ["amazon"] 5 | filter { 6 | name = "name" 7 | values = ["amzn2-ami-hvm-*-gp2"] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = ["ebs"] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = ["hvm"] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = ["x86_64"] 20 | } 21 | } -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-03-Utility-Project/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = "us-east-1" 15 | } 16 | /* 17 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 18 | $HOME/.aws/credentials 19 | */ 20 | -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-03-Utility-Project/terraform-manifests/c2-v1-get-instancetype-supported-per-az-in-a-region.tf: -------------------------------------------------------------------------------- 1 | # Datasource 2 | data "aws_ec2_instance_type_offerings" "my_ins_type1" { 3 | filter { 4 | name = "instance-type" 5 | values = ["t3.micro"] 6 | } 7 | filter { 8 | name = "location" 9 | #values = ["us-east-1a"] 10 | values = ["us-east-1e"] 11 | } 12 | location_type = "availability-zone" 13 | } 14 | 15 | 16 | # Output 17 | output "output_v1_1" { 18 | value = data.aws_ec2_instance_type_offerings.my_ins_type1.instance_types 19 | } 20 | 21 | -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-04-for_each-with-az-instancetype-check/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | } 16 | /* 17 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 18 | $HOME/.aws/credentials 19 | */ 20 | -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-04-for_each-with-az-instancetype-check/terraform-manifests/c2-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | 9 | # AWS EC2 Instance Type 10 | variable "instance_type" { 11 | description = "EC2 Instnace Type" 12 | type = string 13 | default = "t3.micro" 14 | } 15 | 16 | # AWS EC2 Instance Key Pair 17 | variable "instance_keypair" { 18 | description = "AWS EC2 Key Pair that need to be associated with EC2 Instance" 19 | type = string 20 | default = "terraform-key" 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /05-Terraform-Loops-MetaArguments-SplatOperator/05-04-for_each-with-az-instancetype-check/terraform-manifests/c4-ami-datasource.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = ["amazon"] 5 | filter { 6 | name = "name" 7 | values = ["amzn2-ami-hvm-*-gp2"] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = ["ebs"] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = ["hvm"] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = ["x86_64"] 20 | } 21 | } -------------------------------------------------------------------------------- /06-AWS-VPC/06-02-AWS-VPC-using-Terraform/terraform-manifests/v1-vpc-module/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | profile = "default" 16 | } 17 | /* 18 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 19 | $HOME/.aws/credentials 20 | */ 21 | -------------------------------------------------------------------------------- /06-AWS-VPC/06-02-AWS-VPC-using-Terraform/terraform-manifests/v1-vpc-module/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | 3 | # AWS Region 4 | variable "aws_region" { 5 | description = "Region in which AWS Resources to be created" 6 | type = string 7 | default = "us-east-1" 8 | } 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /06-AWS-VPC/06-02-AWS-VPC-using-Terraform/terraform-manifests/v2-vpc-module-standardized/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | profile = "default" 16 | } 17 | /* 18 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 19 | $HOME/.aws/credentials 20 | */ 21 | -------------------------------------------------------------------------------- /06-AWS-VPC/06-02-AWS-VPC-using-Terraform/terraform-manifests/v2-vpc-module-standardized/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "SAP" 19 | } 20 | -------------------------------------------------------------------------------- /06-AWS-VPC/06-02-AWS-VPC-using-Terraform/terraform-manifests/v2-vpc-module-standardized/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /06-AWS-VPC/06-02-AWS-VPC-using-Terraform/terraform-manifests/v2-vpc-module-standardized/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "HR" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /06-AWS-VPC/06-02-AWS-VPC-using-Terraform/terraform-manifests/v2-vpc-module-standardized/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = ">= 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "public-bastion-sg" 8 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp"] 12 | ingress_cidr_blocks = ["0.0.0.0/0"] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "private-sg" 8 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp", "http-80-tcp"] 12 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/local-exec-output-files/backup-demo-kalyan/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Mon Apr 12 12:44:45 IST 2021 and VPC ID: vpc-0420c012ebe877808 2 | VPC created on Thu Apr 15 16:38:50 IST 2021 and VPC ID: vpc-06cacba8e6cd418c5 3 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/local-exec-output-files/backup-demo-kalyan/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Thu Apr 15 16:56:54 IST 2021 2 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/local-exec-output-files/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Fri Dec 31 16:47:17 IST 2021 and VPC ID: vpc-0f83c09823d06c558 2 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Fri Dec 31 16:48:41 IST 2021 2 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "HR" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests-ec2private-module-version330/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "public-bastion-sg" 8 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp"] 12 | ingress_cidr_blocks = ["0.0.0.0/0"] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "private-sg" 8 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp", "http-80-tcp"] 12 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/local-exec-output-files/backup-demo-kalyan/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Mon Apr 12 12:44:45 IST 2021 and VPC ID: vpc-0420c012ebe877808 2 | VPC created on Thu Apr 15 16:38:50 IST 2021 and VPC ID: vpc-06cacba8e6cd418c5 3 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/local-exec-output-files/backup-demo-kalyan/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Thu Apr 15 16:56:54 IST 2021 2 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "HR" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /07-AWS-EC2Instance-and-SecurityGroups/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c10-01-ELB-classic-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Classic Load Balancer Variables 2 | # Place holder file for CLB Variables 3 | 4 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "public-bastion-sg" 8 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp"] 12 | ingress_cidr_blocks = ["0.0.0.0/0"] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "private-sg" 8 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp", "http-80-tcp"] 12 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c7-03-ec2instance-bastion.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Module 2 | # Bastion Host - EC2 Instance that will be created in VPC Public Subnet 3 | module "ec2_public" { 4 | source = "terraform-aws-modules/ec2-instance/aws" 5 | version = "2.17.0" 6 | # insert the 10 required variables here 7 | name = "${var.environment}-BastionHost" 8 | #instance_count = 5 9 | ami = data.aws_ami.amzlinux2.id 10 | instance_type = var.instance_type 11 | key_name = var.instance_keypair 12 | #monitoring = true 13 | subnet_id = module.vpc.public_subnets[0] 14 | vpc_security_group_ids = [module.public_bastion_sg.this_security_group_id] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/local-exec-output-files/backup-demo-kalyan/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Mon Apr 12 12:44:45 IST 2021 and VPC ID: vpc-0420c012ebe877808 2 | VPC created on Thu Apr 15 16:38:50 IST 2021 and VPC ID: vpc-06cacba8e6cd418c5 3 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/local-exec-output-files/backup-demo-kalyan/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Thu Apr 15 16:56:54 IST 2021 2 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "HR" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /08-AWS-ELB-Classic-LoadBalancer/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "public-bastion-sg" 8 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp"] 12 | ingress_cidr_blocks = ["0.0.0.0/0"] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "private-sg" 8 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp", "http-80-tcp"] 12 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/local-exec-output-files/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Mon Apr 19 15:00:57 IST 2021 and VPC ID: vpc-0124fbdd659d7c887 2 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Mon Apr 19 15:08:50 IST 2021 2 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /09-AWS-ALB-Application-LoadBalancer-Basic/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/14-ALB-Autoscaling-with-Launch-Configuration/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/14-ALB-Autoscaling-with-Launch-Configuration/terraform-manifests/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | ## DNS Registration - apps.devopsincloud.com 2 | resource "aws_route53_record" "apps_dns" { 3 | zone_id = data.aws_route53_zone.mydomain.id 4 | name = "asg-lc2.devopsincloud.com" 5 | type = "A" 6 | 7 | alias { 8 | name = module.alb.this_lb_dns_name 9 | zone_id = module.alb.this_lb_zone_id 10 | evaluate_target_health = true 11 | } 12 | } -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/14-ALB-Autoscaling-with-Launch-Configuration/terraform-manifests/c14-o1-asg-outputs.tf: -------------------------------------------------------------------------------- 1 | # Launch configuration 2 | output "this_launch_configuration_id" { 3 | description = "The ID of the launch configuration" 4 | value = module.autoscaling.this_launch_configuration_id 5 | } 6 | 7 | # Autoscaling group 8 | output "this_autoscaling_group_id" { 9 | description = "The autoscaling group id" 10 | value = module.autoscaling.this_autoscaling_group_id 11 | } 12 | 13 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/14-ALB-Autoscaling-with-Launch-Configuration/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.environment}-${var.vpc_name}" 6 | common_tags = { 7 | owners = local.owners 8 | environment = local.environment 9 | } 10 | } -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/14-ALB-Autoscaling-with-Launch-Configuration/terraform-manifests/c6-ami-datasource.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/14-ALB-Autoscaling-with-Launch-Configuration/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | resource "aws_eip" "bastion_eip" { 3 | depends_on = [module.ec2_public] 4 | instance = module.ec2_public.id[0] 5 | vpc = true 6 | tags = local.common_tags 7 | } -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/app2-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-2

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app2 9 | sudo echo '

Welcome to Stack Simplify - APP-2

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app2/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app2/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | version = "2.14.0" 5 | 6 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 7 | zone_id = data.aws_route53_zone.mydomain.zone_id 8 | 9 | subject_alternative_names = [ 10 | "*.devopsincloud.com" 11 | ] 12 | tags = local.common_tags 13 | } 14 | 15 | # Output ACM Certificate ARN 16 | output "this_acm_certificate_arn" { 17 | description = "The ARN of the certificate" 18 | value = module.acm.this_acm_certificate_arn 19 | } 20 | 21 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | # DNS Registration 2 | resource "aws_route53_record" "apps_dns" { 3 | zone_id = data.aws_route53_zone.mydomain.zone_id 4 | name = "apps.devopsincloud.com" 5 | type = "A" 6 | alias { 7 | name = module.alb.this_lb_dns_name 8 | zone_id = module.alb.this_lb_zone_id 9 | evaluate_target_health = true 10 | } 11 | } -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "public-bastion-sg" 8 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp"] 12 | ingress_cidr_blocks = ["0.0.0.0/0"] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "private-sg" 8 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp", "http-80-tcp"] 12 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c7-03-ec2instance-bastion.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Module 2 | # Bastion Host - EC2 Instance that will be created in VPC Public Subnet 3 | module "ec2_public" { 4 | source = "terraform-aws-modules/ec2-instance/aws" 5 | version = "2.17.0" 6 | # insert the 10 required variables here 7 | name = "${var.environment}-BastionHost" 8 | #instance_count = 5 9 | ami = data.aws_ami.amzlinux2.id 10 | instance_type = var.instance_type 11 | key_name = var.instance_keypair 12 | #monitoring = true 13 | subnet_id = module.vpc.public_subnets[0] 14 | vpc_security_group_ids = [module.public_bastion_sg.this_security_group_id] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/local-exec-output-files/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Tue Apr 20 13:59:45 IST 2021 and VPC ID: vpc-0325dc1acd7eec103 2 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /10-ALB-Path-Based-Routing/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | # App1 DNS Name 5 | variable "app1_dns_name" { 6 | description = "App1 DNS Name" 7 | } 8 | 9 | # App2 DNS Name 10 | variable "app2_dns_name" { 11 | description = "App2 DNS Name" 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | version = "2.14.0" 5 | 6 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 7 | zone_id = data.aws_route53_zone.mydomain.zone_id 8 | 9 | subject_alternative_names = [ 10 | "*.devopsincloud.com" 11 | ] 12 | tags = local.common_tags 13 | } 14 | 15 | # Output ACM Certificate ARN 16 | output "this_acm_certificate_arn" { 17 | description = "The ARN of the certificate" 18 | value = module.acm.this_acm_certificate_arn 19 | } 20 | 21 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "public-bastion-sg" 8 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp"] 12 | ingress_cidr_blocks = ["0.0.0.0/0"] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "private-sg" 8 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp", "http-80-tcp"] 12 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | #instance_keypair = "terraform-key" 4 | instance_keypair = "terraform-key-us-east-2" 5 | private_instance_count = 2 6 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/loadbalancer.auto.tfvars: -------------------------------------------------------------------------------- 1 | # AWS Load Balancer Variables 2 | app1_dns_name = "app17.devopsincloud.com" 3 | app2_dns_name = "app27.devopsincloud.com" -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/local-exec-output-files/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Tue Apr 20 13:59:45 IST 2021 and VPC ID: vpc-0325dc1acd7eec103 2 | VPC created on Tue Apr 20 15:38:18 IST 2021 and VPC ID: vpc-0ada4f674de70b568 3 | VPC created on Thu Apr 22 11:41:49 IST 2021 and VPC ID: vpc-0ad139001a6b52da6 4 | VPC created on Thu Apr 22 14:12:55 IST 2021 and VPC ID: vpc-0230b618d0cd954ba 5 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | Destroy time prov Tue Apr 20 15:47:43 IST 2021 3 | Destroy time prov Thu Apr 22 12:11:35 IST 2021 4 | Destroy time prov Thu Apr 22 14:24:56 IST 2021 5 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-2" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests-us-east-2/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-2a", "us-east-2b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/app2-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-2

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app2 9 | sudo echo '

Welcome to Stack Simplify - APP-2

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app2/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app2/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | # App1 DNS Name 5 | variable "app1_dns_name" { 6 | description = "App1 DNS Name" 7 | } 8 | 9 | # App2 DNS Name 10 | variable "app2_dns_name" { 11 | description = "App2 DNS Name" 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | version = "2.14.0" 5 | 6 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 7 | zone_id = data.aws_route53_zone.mydomain.zone_id 8 | 9 | subject_alternative_names = [ 10 | "*.devopsincloud.com" 11 | ] 12 | tags = local.common_tags 13 | } 14 | 15 | # Output ACM Certificate ARN 16 | output "this_acm_certificate_arn" { 17 | description = "The ARN of the certificate" 18 | value = module.acm.this_acm_certificate_arn 19 | } 20 | 21 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "public-bastion-sg" 8 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp"] 12 | ingress_cidr_blocks = ["0.0.0.0/0"] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "private-sg" 8 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp", "http-80-tcp"] 12 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c7-03-ec2instance-bastion.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Module 2 | # Bastion Host - EC2 Instance that will be created in VPC Public Subnet 3 | module "ec2_public" { 4 | source = "terraform-aws-modules/ec2-instance/aws" 5 | version = "2.17.0" 6 | # insert the 10 required variables here 7 | name = "${var.environment}-BastionHost" 8 | #instance_count = 5 9 | ami = data.aws_ami.amzlinux2.id 10 | instance_type = var.instance_type 11 | key_name = var.instance_keypair 12 | #monitoring = true 13 | subnet_id = module.vpc.public_subnets[0] 14 | vpc_security_group_ids = [module.public_bastion_sg.this_security_group_id] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/loadbalancer.auto.tfvars: -------------------------------------------------------------------------------- 1 | # AWS Load Balancer Variables 2 | app1_dns_name = "app1.devopsincloud.com" 3 | app2_dns_name = "app2.devopsincloud.com" -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/local-exec-output-files/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Tue Apr 20 13:59:45 IST 2021 and VPC ID: vpc-0325dc1acd7eec103 2 | VPC created on Tue Apr 20 15:38:18 IST 2021 and VPC ID: vpc-0ada4f674de70b568 3 | VPC created on Thu Apr 22 11:41:49 IST 2021 and VPC ID: vpc-0ad139001a6b52da6 4 | VPC created on Thu Apr 22 14:12:55 IST 2021 and VPC ID: vpc-0230b618d0cd954ba 5 | VPC created on Thu Apr 22 14:37:23 IST 2021 and VPC ID: vpc-033920cf9b2dcd7fa 6 | VPC created on Fri Apr 23 10:23:25 IST 2021 and VPC ID: vpc-07f56cbdaa0491e20 7 | VPC created on Tue Apr 27 08:26:43 IST 2021 and VPC ID: vpc-01c5c36461f11275d 8 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | Destroy time prov Tue Apr 20 15:47:43 IST 2021 3 | Destroy time prov Thu Apr 22 12:11:35 IST 2021 4 | Destroy time prov Thu Apr 22 14:24:56 IST 2021 5 | Destroy time prov Thu Apr 22 14:49:18 IST 2021 6 | Destroy time prov Fri Apr 23 10:32:44 IST 2021 7 | Destroy time prov Tue Apr 27 08:41:33 IST 2021 8 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /11-ALB-Host-Header-Based-Routing/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | # App1 DNS Name 5 | variable "app1_dns_name" { 6 | description = "App1 DNS Name" 7 | } 8 | 9 | # App2 DNS Name 10 | variable "app2_dns_name" { 11 | description = "App2 DNS Name" 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | version = "2.14.0" 5 | 6 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 7 | zone_id = data.aws_route53_zone.mydomain.zone_id 8 | 9 | subject_alternative_names = [ 10 | "*.devopsincloud.com" 11 | ] 12 | tags = local.common_tags 13 | } 14 | 15 | # Output ACM Certificate ARN 16 | output "this_acm_certificate_arn" { 17 | description = "The ARN of the certificate" 18 | value = module.acm.this_acm_certificate_arn 19 | } 20 | 21 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "public-bastion-sg" 8 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp"] 12 | ingress_cidr_blocks = ["0.0.0.0/0"] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | version = "3.18.0" 6 | 7 | name = "private-sg" 8 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 9 | vpc_id = module.vpc.vpc_id 10 | # Ingress Rules & CIDR Blocks 11 | ingress_rules = ["ssh-tcp", "http-80-tcp"] 12 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 13 | # Egress Rule - all-all open 14 | egress_rules = ["all-all"] 15 | tags = local.common_tags 16 | } 17 | 18 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/loadbalancer.auto.tfvars: -------------------------------------------------------------------------------- 1 | # AWS Load Balancer Variables 2 | app1_dns_name = "app18.devopsincloud.com" 3 | app2_dns_name = "app28.devopsincloud.com" -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/local-exec-output-files/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Tue Apr 20 13:59:45 IST 2021 and VPC ID: vpc-0325dc1acd7eec103 2 | VPC created on Tue Apr 20 15:38:18 IST 2021 and VPC ID: vpc-0ada4f674de70b568 3 | VPC created on Thu Apr 22 11:41:49 IST 2021 and VPC ID: vpc-0ad139001a6b52da6 4 | VPC created on Thu Apr 22 14:12:55 IST 2021 and VPC ID: vpc-0230b618d0cd954ba 5 | VPC created on Thu Apr 22 14:37:23 IST 2021 and VPC ID: vpc-033920cf9b2dcd7fa 6 | VPC created on Fri Apr 23 10:23:25 IST 2021 and VPC ID: vpc-07f56cbdaa0491e20 7 | VPC created on Fri Apr 23 10:41:27 IST 2021 and VPC ID: vpc-0cb9c7b423bb5df16 8 | VPC created on Tue Apr 27 10:03:02 IST 2021 and VPC ID: vpc-090c52af3ac4bd0d3 9 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | Destroy time prov Tue Apr 20 15:47:43 IST 2021 3 | Destroy time prov Thu Apr 22 12:11:35 IST 2021 4 | Destroy time prov Thu Apr 22 14:24:56 IST 2021 5 | Destroy time prov Thu Apr 22 14:49:18 IST 2021 6 | Destroy time prov Fri Apr 23 10:32:44 IST 2021 7 | Destroy time prov Fri Apr 23 10:52:14 IST 2021 8 | Destroy time prov Tue Apr 27 10:14:39 IST 2021 9 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /12-ALB-HTTPHeader-QueryString-Redirects/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /13-DNS-to-DB/templatefile-function-demo/app3-ums-install.tmpl: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | sudo amazon-linux-extras enable java-openjdk11 3 | sudo yum clean metadata && sudo yum -y install java-11-openjdk 4 | mkdir /home/ec2-user/app3-usermgmt && cd /home/ec2-user/app3-usermgmt 5 | wget https://github.com/stacksimplify/temp1/releases/download/1.0.0/usermgmt-webapp.war -P /home/ec2-user/app3-usermgmt 6 | export DB_HOSTNAME=${rds_db_endpoint} 7 | export DB_PORT=3306 8 | export DB_NAME=webappdb 9 | export DB_USERNAME=dbadmin 10 | export DB_PASSWORD=dbpassword11 11 | java -jar /home/ec2-user/app3-usermgmt/usermgmt-webapp.war > /home/ec2-user/app3-usermgmt/ums-start.log & 12 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/app2-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-2

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app2 9 | sudo echo '

Welcome to Stack Simplify - APP-2

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app2/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app2/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/app3-ums-install.tmpl: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | sudo amazon-linux-extras enable java-openjdk11 3 | sudo yum clean metadata && sudo yum -y install java-11-openjdk 4 | mkdir /home/ec2-user/app3-usermgmt && cd /home/ec2-user/app3-usermgmt 5 | wget https://github.com/stacksimplify/temp1/releases/download/1.0.0/usermgmt-webapp.war -P /home/ec2-user/app3-usermgmt 6 | export DB_HOSTNAME=${rds_db_endpoint} 7 | export DB_PORT=3306 8 | export DB_NAME=webappdb 9 | export DB_USERNAME=dbadmin 10 | export DB_PASSWORD=dbpassword11 11 | java -jar /home/ec2-user/app3-usermgmt/usermgmt-webapp.war > /home/ec2-user/app3-usermgmt/ums-start.log & 12 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | null = { 10 | source = "hashicorp/null" 11 | version = "~> 3.0" 12 | } 13 | } 14 | } 15 | 16 | # Provider Block 17 | provider "aws" { 18 | region = var.aws_region 19 | profile = "default" 20 | } 21 | /* 22 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 23 | $HOME/.aws/credentials 24 | */ 25 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | #version = "2.14.0" 5 | version = "3.0.0" 6 | 7 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 8 | zone_id = data.aws_route53_zone.mydomain.zone_id 9 | 10 | subject_alternative_names = [ 11 | "*.devopsincloud.com" 12 | ] 13 | tags = local.common_tags 14 | } 15 | 16 | # Output ACM Certificate ARN 17 | output "this_acm_certificate_arn" { 18 | description = "The ARN of the certificate" 19 | #value = module.acm.this_acm_certificate_arn 20 | value = module.acm.acm_certificate_arn 21 | } 22 | 23 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | # DNS Registration 2 | resource "aws_route53_record" "apps_dns" { 3 | zone_id = data.aws_route53_zone.mydomain.zone_id 4 | name = "dns-to-db.devopsincloud.com" 5 | type = "A" 6 | alias { 7 | name = module.alb.lb_dns_name 8 | zone_id = module.alb.lb_zone_id 9 | evaluate_target_health = true 10 | } 11 | } -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c13-01-rdsdb-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS RDS Database Variables 2 | # Place holder file for AWS RDS Database 3 | 4 | # DB Name 5 | variable "db_name" { 6 | description = "AWS RDS Database Name" 7 | type = string 8 | } 9 | # DB Instance Identifier 10 | variable "db_instance_identifier" { 11 | description = "AWS RDS Database Instance Identifier" 12 | type = string 13 | } 14 | # DB Username - Enable Sensitive flag 15 | variable "db_username" { 16 | description = "AWS RDS Database Administrator Username" 17 | type = string 18 | } 19 | # DB Password - Enable Sensitive flag 20 | variable "db_password" { 21 | description = "AWS RDS Database Administrator Password" 22 | type = string 23 | sensitive = true 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "public-bastion-sg" 9 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp"] 13 | ingress_cidr_blocks = ["0.0.0.0/0"] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "private-sg" 9 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp", "http-80-tcp", "http-8080-tcp"] 13 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | 19 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c5-06-securitygroup-rdsdbsg.tf: -------------------------------------------------------------------------------- 1 | # Security Group for AWS RDS DB 2 | module "rdsdb_sg" { 3 | source = "terraform-aws-modules/security-group/aws" 4 | #version = "3.18.0" 5 | version = "4.0.0" 6 | 7 | name = "rdsdb-sg" 8 | description = "Access to MySQL DB for entire VPC CIDR Block" 9 | vpc_id = module.vpc.vpc_id 10 | 11 | # ingress 12 | ingress_with_cidr_blocks = [ 13 | { 14 | from_port = 3306 15 | to_port = 3306 16 | protocol = "tcp" 17 | description = "MySQL access from within VPC" 18 | cidr_blocks = module.vpc.vpc_cidr_block 19 | }, 20 | ] 21 | # Egress Rule - all-all open 22 | egress_rules = ["all-all"] 23 | tags = local.common_tags 24 | } 25 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/jumpbox-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | sudo yum update -y 3 | sudo rpm -e --nodeps mariadb-libs-* 4 | sudo amazon-linux-extras enable mariadb10.5 5 | sudo yum clean metadata 6 | sudo yum install -y mariadb 7 | sudo mysql -V 8 | sudo yum install -y telnet -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/local-exec-output-files/creation-time-vpc-id.txt: -------------------------------------------------------------------------------- 1 | VPC created on Tue Apr 20 13:59:45 IST 2021 and VPC ID: vpc-0325dc1acd7eec103 2 | VPC created on Fri Apr 23 14:38:18 IST 2021 and VPC ID: vpc-0159283c216ac75de 3 | VPC created on Tue Apr 27 10:44:49 IST 2021 and VPC ID: vpc-0f27dbec1d02214ac 4 | VPC created on Tue Apr 27 11:43:16 IST 2021 and VPC ID: vpc-0919ae691ce17b447 5 | VPC created on Tue Apr 27 15:46:33 IST 2021 and VPC ID: vpc-0c049ce82c2fef9d3 6 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | Destroy time prov Fri Apr 23 16:06:53 IST 2021 3 | Destroy time prov Tue Apr 27 11:10:39 IST 2021 4 | Destroy time prov Tue Apr 27 13:09:09 IST 2021 5 | Destroy time prov Tue Apr 27 16:20:51 IST 2021 6 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/rdsdb.auto.tfvars: -------------------------------------------------------------------------------- 1 | # RDS Database Variables 2 | db_name = "webappdb" 3 | db_instance_identifier = "webappdb" 4 | db_username = "dbadmin" 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/secrets.tfvars: -------------------------------------------------------------------------------- 1 | db_password = "dbpassword11" -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /13-DNS-to-DB/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | #version = "2.14.0" 5 | version = "3.0.0" 6 | 7 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 8 | zone_id = data.aws_route53_zone.mydomain.zone_id 9 | 10 | subject_alternative_names = [ 11 | "*.devopsincloud.com" 12 | ] 13 | tags = local.common_tags 14 | } 15 | 16 | # Output ACM Certificate ARN 17 | output "this_acm_certificate_arn" { 18 | description = "The ARN of the certificate" 19 | #value = module.acm.this_acm_certificate_arn 20 | value = module.acm.acm_certificate_arn 21 | } 22 | 23 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | # DNS Registration 2 | resource "aws_route53_record" "apps_dns" { 3 | zone_id = data.aws_route53_zone.mydomain.zone_id 4 | name = "asg-lc.devopsincloud.com" 5 | type = "A" 6 | alias { 7 | name = module.alb.lb_dns_name 8 | zone_id = module.alb.lb_zone_id 9 | evaluate_target_health = true 10 | } 11 | } -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c13-01-autoscaling-with-launchconfiguration-variables.tf: -------------------------------------------------------------------------------- 1 | # Autoscaling Input Variables 2 | ## Placeholder file -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c13-02-autoscaling-additional-resoures.tf: -------------------------------------------------------------------------------- 1 | # AWS IAM Service Linked Role for Autoscaling Group 2 | resource "aws_iam_service_linked_role" "autoscaling" { 3 | aws_service_name = "autoscaling.amazonaws.com" 4 | description = "A service linked role for autoscaling" 5 | custom_suffix = local.name 6 | 7 | # Sometimes good sleep is required to have some IAM resources created before they can be used 8 | provisioner "local-exec" { 9 | command = "sleep 10" 10 | } 11 | } 12 | 13 | # Output AWS IAM Service Linked Role 14 | output "service_linked_role_arn" { 15 | value = aws_iam_service_linked_role.autoscaling.arn 16 | } 17 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | 12 | asg_tags = [ 13 | { 14 | key = "Project" 15 | value = "megasecret" 16 | propagate_at_launch = true 17 | }, 18 | { 19 | key = "foo" 20 | value = "" 21 | propagate_at_launch = true 22 | }, 23 | ] 24 | 25 | } -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "public-bastion-sg" 9 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp"] 13 | ingress_cidr_blocks = ["0.0.0.0/0"] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "private-sg" 9 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp", "http-80-tcp", "http-8080-tcp"] 13 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | 19 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c7-02-ec2instance-outputs.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Outputs 2 | # Public EC2 Instances - Bastion Host 3 | 4 | ## ec2_bastion_public_instance_ids 5 | output "ec2_bastion_public_instance_ids" { 6 | description = "List of IDs of instances" 7 | value = module.ec2_public.id 8 | } 9 | 10 | ## ec2_bastion_public_ip 11 | output "ec2_bastion_public_ip" { 12 | description = "List of public IP addresses assigned to the instances" 13 | value = module.ec2_public.public_ip 14 | } 15 | 16 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | Destroy time prov Fri Apr 23 16:06:53 IST 2021 3 | Destroy time prov Tue Apr 27 11:10:39 IST 2021 4 | Destroy time prov Tue Apr 27 13:09:09 IST 2021 5 | Destroy time prov Tue Apr 27 16:20:51 IST 2021 6 | Destroy time prov Wed Apr 28 08:12:01 IST 2021 7 | Destroy time prov Wed Apr 28 10:12:10 IST 2021 8 | Destroy time prov Wed Apr 28 10:39:23 IST 2021 9 | Destroy time prov Wed Apr 28 11:24:38 IST 2021 10 | Destroy time prov Wed Apr 28 13:05:25 IST 2021 11 | Destroy time prov Thu Apr 29 11:15:01 IST 2021 12 | Destroy time prov Tue May 4 12:08:25 IST 2021 13 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /14-Autoscaling-with-Launch-Configuration/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | #version = "2.14.0" 5 | version = "3.0.0" 6 | 7 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 8 | zone_id = data.aws_route53_zone.mydomain.zone_id 9 | 10 | subject_alternative_names = [ 11 | "*.devopsincloud.com" 12 | ] 13 | tags = local.common_tags 14 | } 15 | 16 | # Output ACM Certificate ARN 17 | output "this_acm_certificate_arn" { 18 | description = "The ARN of the certificate" 19 | #value = module.acm.this_acm_certificate_arn 20 | value = module.acm.acm_certificate_arn 21 | } 22 | 23 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | # DNS Registration 2 | resource "aws_route53_record" "apps_dns" { 3 | zone_id = data.aws_route53_zone.mydomain.zone_id 4 | name = "asg-lt.devopsincloud.com" 5 | type = "A" 6 | alias { 7 | name = module.alb.lb_dns_name 8 | zone_id = module.alb.lb_zone_id 9 | evaluate_target_health = true 10 | } 11 | } -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c13-01-autoscaling-with-launchtemplate-variables.tf: -------------------------------------------------------------------------------- 1 | # Autoscaling Input Variables 2 | ## Placeholder file -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | 12 | asg_tags = [ 13 | { 14 | key = "Project" 15 | value = "megasecret" 16 | propagate_at_launch = true 17 | }, 18 | { 19 | key = "foo" 20 | value = "" 21 | propagate_at_launch = true 22 | }, 23 | ] 24 | 25 | } -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "public-bastion-sg" 9 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp"] 13 | ingress_cidr_blocks = ["0.0.0.0/0"] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "private-sg" 9 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp", "http-80-tcp", "http-8080-tcp"] 13 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | 19 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c7-02-ec2instance-outputs.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Outputs 2 | # Public EC2 Instances - Bastion Host 3 | 4 | ## ec2_bastion_public_instance_ids 5 | output "ec2_bastion_public_instance_ids" { 6 | description = "List of IDs of instances" 7 | value = module.ec2_public.id 8 | } 9 | 10 | ## ec2_bastion_public_ip 11 | output "ec2_bastion_public_ip" { 12 | description = "List of public IP addresses assigned to the instances" 13 | value = module.ec2_public.public_ip 14 | } 15 | 16 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | Destroy time prov Fri Apr 23 16:06:53 IST 2021 3 | Destroy time prov Tue Apr 27 11:10:39 IST 2021 4 | Destroy time prov Tue Apr 27 13:09:09 IST 2021 5 | Destroy time prov Tue Apr 27 16:20:51 IST 2021 6 | Destroy time prov Wed Apr 28 08:12:01 IST 2021 7 | Destroy time prov Wed Apr 28 10:12:10 IST 2021 8 | Destroy time prov Wed Apr 28 10:39:23 IST 2021 9 | Destroy time prov Wed Apr 28 11:24:38 IST 2021 10 | Destroy time prov Wed Apr 28 13:05:25 IST 2021 11 | Destroy time prov Thu Apr 29 11:15:01 IST 2021 12 | Destroy time prov Thu Apr 29 16:03:46 IST 2021 13 | Destroy time prov Sat May 8 11:14:32 IST 2021 14 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /15-Autoscaling-with-Launch-Templates/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c10-01-NLB-network-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | #version = "2.14.0" 5 | version = "3.0.0" 6 | 7 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 8 | zone_id = data.aws_route53_zone.mydomain.zone_id 9 | 10 | subject_alternative_names = [ 11 | "*.devopsincloud.com" 12 | ] 13 | tags = local.common_tags 14 | } 15 | 16 | # Output ACM Certificate ARN 17 | output "this_acm_certificate_arn" { 18 | description = "The ARN of the certificate" 19 | #value = module.acm.this_acm_certificate_arn 20 | value = module.acm.acm_certificate_arn 21 | } 22 | 23 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | # DNS Registration 2 | resource "aws_route53_record" "apps_dns" { 3 | zone_id = data.aws_route53_zone.mydomain.zone_id 4 | name = "nlb.devopsincloud.com" 5 | type = "A" 6 | alias { 7 | name = module.nlb.lb_dns_name 8 | zone_id = module.nlb.lb_zone_id 9 | evaluate_target_health = true 10 | } 11 | } -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c13-01-autoscaling-with-launchtemplate-variables.tf: -------------------------------------------------------------------------------- 1 | # Autoscaling Input Variables 2 | ## Placeholder file -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | 12 | asg_tags = [ 13 | { 14 | key = "Project" 15 | value = "megasecret" 16 | propagate_at_launch = true 17 | }, 18 | { 19 | key = "foo" 20 | value = "" 21 | propagate_at_launch = true 22 | }, 23 | ] 24 | 25 | } -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "public-bastion-sg" 9 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp"] 13 | ingress_cidr_blocks = ["0.0.0.0/0"] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c7-02-ec2instance-outputs.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Outputs 2 | # Public EC2 Instances - Bastion Host 3 | 4 | ## ec2_bastion_public_instance_ids 5 | output "ec2_bastion_public_instance_ids" { 6 | description = "List of IDs of instances" 7 | value = module.ec2_public.id 8 | } 9 | 10 | ## ec2_bastion_public_ip 11 | output "ec2_bastion_public_ip" { 12 | description = "List of public IP addresses assigned to the instances" 13 | value = module.ec2_public.public_ip 14 | } 15 | 16 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | Destroy time prov Fri Apr 23 16:06:53 IST 2021 3 | Destroy time prov Tue Apr 27 11:10:39 IST 2021 4 | Destroy time prov Tue Apr 27 13:09:09 IST 2021 5 | Destroy time prov Tue Apr 27 16:20:51 IST 2021 6 | Destroy time prov Wed Apr 28 08:12:01 IST 2021 7 | Destroy time prov Wed Apr 28 10:12:10 IST 2021 8 | Destroy time prov Wed Apr 28 10:39:23 IST 2021 9 | Destroy time prov Wed Apr 28 11:24:38 IST 2021 10 | Destroy time prov Wed Apr 28 13:05:25 IST 2021 11 | Destroy time prov Thu Apr 29 11:15:01 IST 2021 12 | Destroy time prov Thu Apr 29 16:03:46 IST 2021 13 | Destroy time prov Fri Apr 30 09:35:00 IST 2021 14 | Destroy time prov Sat May 8 14:16:59 IST 2021 15 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /16-AWS-NLB-Network-Load-Balancer/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /17-AWS-CloudWatch/cw-synthetics-manifests-v1/sswebsite2/sswebsite2v1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ann-felix/terraform-on-aws-ec2/56f6831f08778c773ddc2bdd9d516874e8088ea9/17-AWS-CloudWatch/cw-synthetics-manifests-v1/sswebsite2/sswebsite2v1.zip -------------------------------------------------------------------------------- /17-AWS-CloudWatch/cw-synthetics-manifests-v2/c9-import-role.tf: -------------------------------------------------------------------------------- 1 | /*resource "aws_iam_role" "developer" { 2 | 3 | }*/ 4 | 5 | # terraform import aws_iam_role.developer CloudWatchSyntheticsRole-sswebsite-3a7-8333e475ed87 6 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/cw-synthetics-manifests-v2/sswebsite2/sswebsite2v1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ann-felix/terraform-on-aws-ec2/56f6831f08778c773ddc2bdd9d516874e8088ea9/17-AWS-CloudWatch/cw-synthetics-manifests-v2/sswebsite2/sswebsite2v1.zip -------------------------------------------------------------------------------- /17-AWS-CloudWatch/temp-alarm/temp-alarm.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | resource "aws_cloudwatch_metric_alarm" "temp" { 6 | 7 | } 8 | 9 | /* Create my terraform import command 10 | terraform import aws_cloudwatch_metric_alarm.temp temp-alarm 11 | terraform import aws_cloudwatch_metric_alarm.temp Synthetics-Alarm-my-manual-canary2-1 12 | */ -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/app1-install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Instance Identity Metadata Reference - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html 3 | sudo yum update -y 4 | sudo yum install -y httpd 5 | sudo systemctl enable httpd 6 | sudo service httpd start 7 | sudo echo '

Welcome to StackSimplify - APP-1

' | sudo tee /var/www/html/index.html 8 | sudo mkdir /var/www/html/app1 9 | sudo echo '

Welcome to Stack Simplify - APP-1

Terraform Demo

Application Version: V1

' | sudo tee /var/www/html/app1/index.html 10 | sudo curl http://169.254.169.254/latest/dynamic/instance-identity/document -o /var/www/html/app1/metadata.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | #version = "2.14.0" 5 | version = "3.0.0" 6 | 7 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 8 | zone_id = data.aws_route53_zone.mydomain.zone_id 9 | 10 | subject_alternative_names = [ 11 | "*.devopsincloud.com" 12 | ] 13 | tags = local.common_tags 14 | } 15 | 16 | # Output ACM Certificate ARN 17 | output "this_acm_certificate_arn" { 18 | description = "The ARN of the certificate" 19 | #value = module.acm.this_acm_certificate_arn 20 | value = module.acm.acm_certificate_arn 21 | } 22 | 23 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | # DNS Registration 2 | resource "aws_route53_record" "apps_dns" { 3 | zone_id = data.aws_route53_zone.mydomain.zone_id 4 | name = "cloudwatch.devopsincloud.com" 5 | type = "A" 6 | alias { 7 | name = module.alb.lb_dns_name 8 | zone_id = module.alb.lb_zone_id 9 | evaluate_target_health = true 10 | } 11 | } -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c13-01-autoscaling-with-launchtemplate-variables.tf: -------------------------------------------------------------------------------- 1 | # Autoscaling Input Variables 2 | ## Placeholder file -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c14-01-cloudwatch-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS CloudWatch Input Variables 2 | ## Place holder file for AWS CloudWatch Input Variables -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c14-04-cloudwatch-cis-alarms.tf: -------------------------------------------------------------------------------- 1 | # Create Log Group for CIS 2 | resource "aws_cloudwatch_log_group" "cis_log_group" { 3 | name = "cis-log-group-${random_pet.this.id}" 4 | } 5 | 6 | # Define CIS Alarms 7 | module "all_cis_alarms" { 8 | source = "terraform-aws-modules/cloudwatch/aws//modules/cis-alarms" 9 | version = "2.1.0" 10 | #create = false 11 | 12 | disabled_controls = ["DisableOrDeleteCMK", "VPCChanges"] 13 | 14 | log_group_name = aws_cloudwatch_log_group.cis_log_group.name 15 | alarm_actions = [aws_sns_topic.myasg_sns_topic.arn] 16 | tags = local.common_tags 17 | } -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | 12 | asg_tags = [ 13 | { 14 | key = "Project" 15 | value = "megasecret" 16 | propagate_at_launch = true 17 | }, 18 | { 19 | key = "foo" 20 | value = "" 21 | propagate_at_launch = true 22 | }, 23 | ] 24 | 25 | } -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "public-bastion-sg" 9 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp"] 13 | ingress_cidr_blocks = ["0.0.0.0/0"] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c5-04-securitygroup-privatesg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Private EC2 Instances 3 | module "private_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "private-sg" 9 | description = "Security Group with HTTP & SSH port open for entire VPC Block (IPv4 CIDR), egress ports are all world open" 10 | vpc_id = module.vpc.vpc_id 11 | # Ingress Rules & CIDR Blocks 12 | ingress_rules = ["ssh-tcp", "http-80-tcp", "http-8080-tcp"] 13 | ingress_cidr_blocks = [module.vpc.vpc_cidr_block] 14 | # Egress Rule - all-all open 15 | egress_rules = ["all-all"] 16 | tags = local.common_tags 17 | } 18 | 19 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c7-02-ec2instance-outputs.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Outputs 2 | # Public EC2 Instances - Bastion Host 3 | 4 | ## ec2_bastion_public_instance_ids 5 | output "ec2_bastion_public_instance_ids" { 6 | description = "List of IDs of instances" 7 | value = module.ec2_public.id 8 | } 9 | 10 | ## ec2_bastion_public_ip 11 | output "ec2_bastion_public_ip" { 12 | description = "List of public IP addresses assigned to the instances" 13 | value = module.ec2_public.public_ip 14 | } 15 | 16 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | 9 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 10 | provisioner "local-exec" { 11 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 12 | working_dir = "local-exec-output-files/" 13 | when = destroy 14 | #on_failure = continue 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/sswebsite2/sswebsite2v1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ann-felix/terraform-on-aws-ec2/56f6831f08778c773ddc2bdd9d516874e8088ea9/17-AWS-CloudWatch/terraform-manifests/sswebsite2/sswebsite2v1.zip -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /17-AWS-CloudWatch/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | profile = "default" 16 | } 17 | /* 18 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 19 | $HOME/.aws/credentials 20 | */ 21 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "SAP" 19 | } 20 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/modules/aws-vpc/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | # Uses editorconfig to maintain consistent coding styles 3 | 4 | # top-most EditorConfig file 5 | root = true 6 | 7 | # Unix-style newlines with a newline ending every file 8 | [*] 9 | charset = utf-8 10 | end_of_line = lf 11 | indent_size = 2 12 | indent_style = space 13 | insert_final_newline = true 14 | max_line_length = 80 15 | trim_trailing_whitespace = true 16 | 17 | [*.{tf,tfvars}] 18 | indent_size = 2 19 | indent_style = space 20 | 21 | [*.md] 22 | max_line_length = 0 23 | trim_trailing_whitespace = false 24 | 25 | [Makefile] 26 | tab_width = 2 27 | indent_style = tab 28 | 29 | [COMMIT_EDITMSG] 30 | max_line_length = 0 31 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/modules/aws-vpc/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: changelog release 2 | 3 | changelog: 4 | git-chglog -o CHANGELOG.md --next-tag `semtag final -s minor -o` 5 | 6 | release: 7 | semtag final -s minor 8 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/modules/aws-vpc/README.md: -------------------------------------------------------------------------------- 1 | # AWS VPC Terraform module 2 | 3 | ## Authors 4 | 5 | Module is maintained by [Anton Babenko](https://github.com/antonbabenko) with help from [these awesome contributors](https://github.com/terraform-aws-modules/terraform-aws-vpc/graphs/contributors). 6 | 7 | ## License 8 | 9 | Apache 2 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/LICENSE) for full details. 10 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/modules/aws-vpc/modules/vpc-endpoints/outputs.tf: -------------------------------------------------------------------------------- 1 | output "endpoints" { 2 | description = "Array containing the full resource object and attributes for all endpoints created" 3 | value = aws_vpc_endpoint.this 4 | } 5 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/modules/aws-vpc/modules/vpc-endpoints/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.12.26" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 3.15" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/modules/aws-vpc/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.12.26" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 3.15" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "HR" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/backup-terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | profile = "default" 16 | } 17 | /* 18 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 19 | $HOME/.aws/credentials 20 | */ 21 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "SAP" 19 | } 20 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/modules/aws-vpc/README.md: -------------------------------------------------------------------------------- 1 | # AWS VPC Terraform module 2 | 3 | ## Authors 4 | Module is maintained by [Anton Babenko](https://github.com/antonbabenko) with help from [these awesome contributors](https://github.com/terraform-aws-modules/terraform-aws-vpc/graphs/contributors). 5 | 6 | ## License 7 | Apache 2 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/LICENSE) for full details. 8 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/modules/aws-vpc/modules/vpc-endpoints/outputs.tf: -------------------------------------------------------------------------------- 1 | output "endpoints" { 2 | description = "Array containing the full resource object and attributes for all endpoints created" 3 | value = aws_vpc_endpoint.this 4 | } 5 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/modules/aws-vpc/modules/vpc-endpoints/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.12.26" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 3.15" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/modules/aws-vpc/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.12.26" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 3.15" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "HR" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /18-Develop-Terraform-Modules-Locally/terraform-manifests/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v1-create-static-website-on-s3-using-aws-mgmt-console/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Welcome to Stack Simplify 4 | 5 | 6 |

Welcome to Stack Simplify - Terraform Modules Demo

7 |

Build Terraform Modules

8 |

Terraform Modules - Step by Step

9 | 10 | -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v1-create-static-website-on-s3-using-aws-mgmt-console/policy-public-read-access-for-website.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Sid": "PublicReadGetObject", 6 | "Effect": "Allow", 7 | "Principal": "*", 8 | "Action": [ 9 | "s3:GetObject" 10 | ], 11 | "Resource": [ 12 | "arn:aws:s3:::mybucket-1045/*" 13 | ] 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v2-host-static-website-on-s3-using-terraform-manifests/outputs.tf: -------------------------------------------------------------------------------- 1 | # Output variable definitions 2 | 3 | output "arn" { 4 | description = "ARN of the S3 Bucket" 5 | value = aws_s3_bucket.s3_bucket.arn 6 | } 7 | 8 | output "name" { 9 | description = "Name (id) of the bucket" 10 | value = aws_s3_bucket.s3_bucket.id 11 | } 12 | 13 | output "domain" { 14 | description = "Domain Name of the bucket" 15 | value = aws_s3_bucket.s3_bucket.website_domain 16 | } 17 | 18 | output "endpoint" { 19 | description = "Endpoint Information of the bucket" 20 | value = aws_s3_bucket.s3_bucket.website_endpoint 21 | } -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v2-host-static-website-on-s3-using-terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | bucket_name = "mybucket-1046" 2 | tags = { 3 | Terraform = "true" 4 | Environment = "dev" 5 | } -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v2-host-static-website-on-s3-using-terraform-manifests/variables.tf: -------------------------------------------------------------------------------- 1 | # Input variable definitions 2 | 3 | variable "bucket_name" { 4 | description = "Name of the S3 bucket. Must be Unique across AWS" 5 | type = string 6 | } 7 | 8 | variable "tags" { 9 | description = "Tages to set on the bucket" 10 | type = map(string) 11 | default = {} 12 | } 13 | -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v2-host-static-website-on-s3-using-terraform-manifests/versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = "us-east-1" 15 | profile = "default" 16 | } 17 | /* 18 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 19 | $HOME/.aws/credentials 20 | */ 21 | -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v3-build-a-module-to-host-static-website-on-aws-s3/c1-versions.tf: -------------------------------------------------------------------------------- 1 | # Terraform Block 2 | terraform { 3 | required_version = "~> 0.14" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "~> 3.0" 8 | } 9 | } 10 | } 11 | 12 | # Provider Block 13 | provider "aws" { 14 | region = var.aws_region 15 | profile = "default" 16 | } 17 | /* 18 | Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal 19 | $HOME/.aws/credentials 20 | */ 21 | -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v3-build-a-module-to-host-static-website-on-aws-s3/c2-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | variable "aws_region" { 3 | description = "Region in which AWS Resources to be created" 4 | type = string 5 | default = "us-east-1" 6 | } 7 | 8 | ## Create Variable for S3 Bucket Name 9 | variable "my_s3_bucket" { 10 | description = "S3 Bucket name that we pass to S3 Custom Module" 11 | type = string 12 | default = "mybucket-1047" 13 | } 14 | 15 | ## Create Variable for S3 Bucket Tags 16 | variable "my_s3_tags" { 17 | description = "Tags to set on the bucket" 18 | type = map(string) 19 | default = { 20 | Terraform = "true" 21 | Environment = "dev" 22 | newtag1 = "tag1" 23 | newtag2 = "tag2" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v3-build-a-module-to-host-static-website-on-aws-s3/c3-s3bucket.tf: -------------------------------------------------------------------------------- 1 | # Call our Custom Terraform Module which we built earlier 2 | 3 | module "website_s3_bucket" { 4 | source = "./modules/aws-s3-static-website-bucket" # Mandatory 5 | bucket_name = var.my_s3_bucket 6 | tags = var.my_s3_tags 7 | } -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v3-build-a-module-to-host-static-website-on-aws-s3/c4-outputs.tf: -------------------------------------------------------------------------------- 1 | # Output definitions 2 | 3 | ## S3 Bucket ARN 4 | output "website_bucket_arn" { 5 | description = "ARN of the bucket" 6 | value = module.website_s3_bucket.arn 7 | } 8 | 9 | ## S3 Bucket Name 10 | output "website_bucket_name" { 11 | description = "Name (id) of the bucket" 12 | value = module.website_s3_bucket.name 13 | } 14 | 15 | ## S3 Bucket Domain 16 | output "website_bucket_domain" { 17 | description = "Name (id) of the bucket" 18 | value = module.website_s3_bucket.domain 19 | } 20 | 21 | ## S3 Bucket Endpoint 22 | output "website_bucket_endpoint" { 23 | description = "Name (id) of the bucket" 24 | value = module.website_s3_bucket.endpoint 25 | } 26 | -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v3-build-a-module-to-host-static-website-on-aws-s3/modules/aws-s3-static-website-bucket/LICENSE: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 (the "License"); 2 | you may not use this file except in compliance with the License. 3 | You may obtain a copy of the License at 4 | 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v3-build-a-module-to-host-static-website-on-aws-s3/modules/aws-s3-static-website-bucket/README.md: -------------------------------------------------------------------------------- 1 | # AWS S3 static website bucket 2 | - This module provisions AWS S3 buckets configured for static website hosting. 3 | - This will be a demo S3 module 4 | 5 | -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v3-build-a-module-to-host-static-website-on-aws-s3/modules/aws-s3-static-website-bucket/outputs.tf: -------------------------------------------------------------------------------- 1 | # Output variable definitions 2 | 3 | output "arn" { 4 | description = "ARN of the S3 Bucket" 5 | value = aws_s3_bucket.s3_bucket.arn 6 | } 7 | 8 | output "name" { 9 | description = "Name (id) of the bucket" 10 | value = aws_s3_bucket.s3_bucket.id 11 | } 12 | 13 | output "domain" { 14 | description = "Domain Name of the bucket" 15 | value = aws_s3_bucket.s3_bucket.website_domain 16 | } 17 | 18 | output "endpoint" { 19 | description = "Endpoint Information of the bucket" 20 | value = aws_s3_bucket.s3_bucket.website_endpoint 21 | } -------------------------------------------------------------------------------- /19-Develop-Terraform-Module-from-scratch/v3-build-a-module-to-host-static-website-on-aws-s3/modules/aws-s3-static-website-bucket/variables.tf: -------------------------------------------------------------------------------- 1 | # Input variable definitions 2 | 3 | variable "bucket_name" { 4 | description = "Name of the S3 bucket. Must be Unique across AWS" 5 | type = string 6 | } 7 | 8 | variable "tags" { 9 | description = "Tages to set on the bucket" 10 | type = map(string) 11 | default = {} 12 | } 13 | -------------------------------------------------------------------------------- /20-Remote-State-Storage-with-AWS-S3-and-DynamoDB/project-1-aws-vpc/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "SAP" 19 | } 20 | -------------------------------------------------------------------------------- /20-Remote-State-Storage-with-AWS-S3-and-DynamoDB/project-1-aws-vpc/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /20-Remote-State-Storage-with-AWS-S3-and-DynamoDB/project-1-aws-vpc/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "HR" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /20-Remote-State-Storage-with-AWS-S3-and-DynamoDB/project-1-aws-vpc/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-1-aws-vpc/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "SAP" 19 | } 20 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-1-aws-vpc/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | } -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-1-aws-vpc/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "HR" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-1-aws-vpc/vpc.auto.tfvars: -------------------------------------------------------------------------------- 1 | # VPC Variables 2 | vpc_name = "myvpc" 3 | vpc_cidr_block = "10.0.0.0/16" 4 | vpc_availability_zones = ["us-east-1a", "us-east-1b"] 5 | vpc_public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] 6 | vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] 7 | vpc_database_subnets= ["10.0.151.0/24", "10.0.152.0/24"] 8 | vpc_create_database_subnet_group = true 9 | vpc_create_database_subnet_route_table = true 10 | vpc_enable_nat_gateway = true 11 | vpc_single_nat_gateway = true -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | #version = "2.14.0" 5 | version = "3.0.0" 6 | 7 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 8 | zone_id = data.aws_route53_zone.mydomain.zone_id 9 | 10 | subject_alternative_names = [ 11 | "*.devopsincloud.com" 12 | ] 13 | tags = local.common_tags 14 | } 15 | 16 | # Output ACM Certificate ARN 17 | output "this_acm_certificate_arn" { 18 | description = "The ARN of the certificate" 19 | #value = module.acm.this_acm_certificate_arn 20 | value = module.acm.acm_certificate_arn 21 | } 22 | 23 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | # DNS Registration 2 | resource "aws_route53_record" "apps_dns" { 3 | zone_id = data.aws_route53_zone.mydomain.zone_id 4 | name = "tf-multi-app-projects.devopsincloud.com" 5 | type = "A" 6 | alias { 7 | name = module.alb.lb_dns_name 8 | zone_id = module.alb.lb_zone_id 9 | evaluate_target_health = true 10 | } 11 | } -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c13-01-autoscaling-with-launchtemplate-variables.tf: -------------------------------------------------------------------------------- 1 | # Autoscaling Input Variables 2 | ## Placeholder file -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | 12 | asg_tags = [ 13 | { 14 | key = "Project" 15 | value = "megasecret" 16 | propagate_at_launch = true 17 | }, 18 | { 19 | key = "foo" 20 | value = "" 21 | propagate_at_launch = true 22 | }, 23 | ] 24 | 25 | } -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | name = "public-bastion-sg" 9 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 10 | #vpc_id = module.vpc.vpc_id 11 | vpc_id = data.terraform_remote_state.vpc.outputs.vpc_id 12 | # Ingress Rules & CIDR Blocks 13 | ingress_rules = ["ssh-tcp"] 14 | ingress_cidr_blocks = ["0.0.0.0/0"] 15 | # Egress Rule - all-all open 16 | egress_rules = ["all-all"] 17 | tags = local.common_tags 18 | } 19 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c7-02-ec2instance-outputs.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Outputs 2 | # Public EC2 Instances - Bastion Host 3 | 4 | ## ec2_bastion_public_instance_ids 5 | output "ec2_bastion_public_instance_ids" { 6 | description = "List of IDs of instances" 7 | value = module.ec2_public.id 8 | } 9 | 10 | ## ec2_bastion_public_ip 11 | output "ec2_bastion_public_ip" { 12 | description = "List of public IP addresses assigned to the instances" 13 | value = module.ec2_public.public_ip 14 | } 15 | 16 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | #depends_on = [ module.ec2_public, module.vpc ] 5 | depends_on = [ module.ec2_public, /*module.vpc*/ ] 6 | instance = module.ec2_public.id[0] 7 | vpc = true 8 | tags = local.common_tags 9 | 10 | ## Local Exec Provisioner: local-exec provisioner (Destroy-Time Provisioner - Triggered during deletion of Resource) 11 | provisioner "local-exec" { 12 | command = "echo Destroy time prov `date` >> destroy-time-prov.txt" 13 | working_dir = "local-exec-output-files/" 14 | when = destroy 15 | #on_failure = continue 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/ec2instance.auto.tfvars: -------------------------------------------------------------------------------- 1 | # EC2 Instance Variables 2 | instance_type = "t3.micro" 3 | instance_keypair = "terraform-key" 4 | private_instance_count = 2 5 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/local-exec-output-files/destroy-time-prov.txt: -------------------------------------------------------------------------------- 1 | Destroy time prov Tue Apr 20 14:11:11 IST 2021 2 | Destroy time prov Fri Apr 23 16:06:53 IST 2021 3 | Destroy time prov Tue Apr 27 11:10:39 IST 2021 4 | Destroy time prov Tue Apr 27 13:09:09 IST 2021 5 | Destroy time prov Tue Apr 27 16:20:51 IST 2021 6 | Destroy time prov Wed Apr 28 08:12:01 IST 2021 7 | Destroy time prov Wed Apr 28 10:12:10 IST 2021 8 | Destroy time prov Wed Apr 28 10:39:23 IST 2021 9 | Destroy time prov Wed Apr 28 11:24:38 IST 2021 10 | Destroy time prov Wed Apr 28 13:05:25 IST 2021 11 | Destroy time prov Thu Apr 29 11:15:01 IST 2021 12 | Destroy time prov Thu Apr 29 16:03:46 IST 2021 13 | Destroy time prov Mon May 10 17:56:23 IST 2021 14 | -------------------------------------------------------------------------------- /21-terraform-remote-state-datasource/project-2-app1-with-asg-and-alb/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | environment = "stag" 4 | business_divsion = "hr" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/README.md: -------------------------------------------------------------------------------- 1 | # terraform-iacdevops-with-aws-codepipeline 2 | terraform-iacdevops-with-aws-codepipeline 3 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c10-01-ALB-application-loadbalancer-variables.tf: -------------------------------------------------------------------------------- 1 | # Terraform AWS Application Load Balancer Variables 2 | # Place holder file for AWS ALB Variables 3 | 4 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c11-acm-certificatemanager.tf: -------------------------------------------------------------------------------- 1 | # ACM Module - To create and Verify SSL Certificates 2 | module "acm" { 3 | source = "terraform-aws-modules/acm/aws" 4 | #version = "2.14.0" 5 | version = "3.0.0" 6 | 7 | domain_name = trimsuffix(data.aws_route53_zone.mydomain.name, ".") 8 | zone_id = data.aws_route53_zone.mydomain.zone_id 9 | 10 | subject_alternative_names = [ 11 | #"*.devopsincloud.com" 12 | var.dns_name 13 | ] 14 | tags = local.common_tags 15 | } 16 | 17 | # Output ACM Certificate ARN 18 | output "this_acm_certificate_arn" { 19 | description = "The ARN of the certificate" 20 | #value = module.acm.this_acm_certificate_arn 21 | value = module.acm.acm_certificate_arn 22 | } 23 | 24 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c12-route53-dnsregistration.tf: -------------------------------------------------------------------------------- 1 | # DNS Name Input Variable 2 | variable "dns_name" { 3 | description = "DNS Name to support multiple environments" 4 | type = string 5 | } 6 | # DNS Registration 7 | resource "aws_route53_record" "apps_dns" { 8 | zone_id = data.aws_route53_zone.mydomain.zone_id 9 | name = var.dns_name 10 | type = "A" 11 | alias { 12 | name = module.alb.lb_dns_name 13 | zone_id = module.alb.lb_zone_id 14 | evaluate_target_health = true 15 | } 16 | } -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c13-01-autoscaling-with-launchtemplate-variables.tf: -------------------------------------------------------------------------------- 1 | # Autoscaling Input Variables 2 | ## Placeholder file -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c2-generic-variables.tf: -------------------------------------------------------------------------------- 1 | # Input Variables 2 | # AWS Region 3 | variable "aws_region" { 4 | description = "Region in which AWS Resources to be created" 5 | type = string 6 | default = "us-east-1" 7 | } 8 | # Environment Variable 9 | variable "environment" { 10 | description = "Environment Variable used as a prefix" 11 | type = string 12 | default = "dev" 13 | } 14 | # Business Division 15 | variable "business_divsion" { 16 | description = "Business Division in the large organization this Infrastructure belongs" 17 | type = string 18 | default = "sap" 19 | } 20 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c3-local-values.tf: -------------------------------------------------------------------------------- 1 | # Define Local Values in Terraform 2 | locals { 3 | owners = var.business_divsion 4 | environment = var.environment 5 | name = "${var.business_divsion}-${var.environment}" 6 | #name = "${local.owners}-${local.environment}" 7 | common_tags = { 8 | owners = local.owners 9 | environment = local.environment 10 | } 11 | 12 | asg_tags = [ 13 | { 14 | key = "Project" 15 | value = "megasecret" 16 | propagate_at_launch = true 17 | }, 18 | { 19 | key = "foo" 20 | value = "" 21 | propagate_at_launch = true 22 | }, 23 | ] 24 | 25 | } -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c5-01-securitygroup-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Variables 2 | ## Placeholder file for Variables 3 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c5-03-securitygroup-bastionsg.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Security Group Terraform Module 2 | # Security Group for Public Bastion Host 3 | module "public_bastion_sg" { 4 | source = "terraform-aws-modules/security-group/aws" 5 | #version = "3.18.0" 6 | version = "4.0.0" 7 | 8 | #name = "public-bastion-sg" 9 | name = "${local.name}-public-bastion-sg" 10 | description = "Security Group with SSH port open for everybody (IPv4 CIDR), egress ports are all world open" 11 | vpc_id = module.vpc.vpc_id 12 | # Ingress Rules & CIDR Blocks 13 | ingress_rules = ["ssh-tcp"] 14 | ingress_cidr_blocks = ["0.0.0.0/0"] 15 | # Egress Rule - all-all open 16 | egress_rules = ["all-all"] 17 | tags = local.common_tags 18 | } 19 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c6-01-datasource-ami.tf: -------------------------------------------------------------------------------- 1 | # Get latest AMI ID for Amazon Linux2 OS 2 | data "aws_ami" "amzlinux2" { 3 | most_recent = true 4 | owners = [ "amazon" ] 5 | filter { 6 | name = "name" 7 | values = [ "amzn2-ami-hvm-*-gp2" ] 8 | } 9 | filter { 10 | name = "root-device-type" 11 | values = [ "ebs" ] 12 | } 13 | filter { 14 | name = "virtualization-type" 15 | values = [ "hvm" ] 16 | } 17 | filter { 18 | name = "architecture" 19 | values = [ "x86_64" ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c6-02-datasource-route53-zone.tf: -------------------------------------------------------------------------------- 1 | # Get DNS information from AWS Route53 2 | data "aws_route53_zone" "mydomain" { 3 | name = "devopsincloud.com" 4 | } 5 | 6 | # Output MyDomain Zone ID 7 | output "mydomain_zoneid" { 8 | description = "The Hosted Zone id of the desired Hosted Zone" 9 | value = data.aws_route53_zone.mydomain.zone_id 10 | } 11 | 12 | # Output MyDomain name 13 | output "mydomain_name" { 14 | description = " The Hosted Zone name of the desired Hosted Zone." 15 | value = data.aws_route53_zone.mydomain.name 16 | } 17 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c7-01-ec2instance-variables.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Variables 2 | # EC2 Instance Variables 3 | 4 | # AWS EC2 Instance Type 5 | variable "instance_type" { 6 | description = "EC2 Instance Type" 7 | type = string 8 | default = "t3.micro" 9 | } 10 | 11 | # AWS EC2 Instance Key Pair 12 | variable "instance_keypair" { 13 | description = "AWS EC2 Key pair that need to be associated with EC2 Instance" 14 | type = string 15 | default = "terraform-key" 16 | } 17 | 18 | # AWS EC2 Private Instance Count 19 | variable "private_instance_count" { 20 | description = "AWS EC2 Private Instances Count" 21 | type = number 22 | default = 1 23 | } -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c7-02-ec2instance-outputs.tf: -------------------------------------------------------------------------------- 1 | # AWS EC2 Instance Terraform Outputs 2 | # Public EC2 Instances - Bastion Host 3 | 4 | ## ec2_bastion_public_instance_ids 5 | output "ec2_bastion_public_instance_ids" { 6 | description = "List of IDs of instances" 7 | value = module.ec2_public.id 8 | } 9 | 10 | ## ec2_bastion_public_ip 11 | output "ec2_bastion_public_ip" { 12 | description = "List of public IP addresses assigned to the instances" 13 | value = module.ec2_public.public_ip 14 | } 15 | 16 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/c8-elasticip.tf: -------------------------------------------------------------------------------- 1 | # Create Elastic IP for Bastion Host 2 | # Resource - depends_on Meta-Argument 3 | resource "aws_eip" "bastion_eip" { 4 | depends_on = [ module.ec2_public, module.vpc ] 5 | instance = module.ec2_public.id[0] 6 | vpc = true 7 | tags = local.common_tags 8 | } 9 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/dev.conf: -------------------------------------------------------------------------------- 1 | bucket = "terraform-on-aws-for-ec2" 2 | key = "iacdevops/dev/terraform.tfstate" 3 | region = "us-east-1" 4 | dynamodb_table = "iacdevops-dev-tfstate" 5 | 6 | 7 | -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/stag.conf: -------------------------------------------------------------------------------- 1 | bucket = "terraform-on-aws-for-ec2" 2 | key = "iacdevops/stag/terraform.tfstate" 3 | region = "us-east-1" 4 | dynamodb_table = "iacdevops-stag-tfstate" -------------------------------------------------------------------------------- /22-IaC-DevOps-using-AWS-CodePipeline/Git-Repo-Files/terraform-manifests/terraform.tfvars: -------------------------------------------------------------------------------- 1 | # Generic Variables 2 | aws_region = "us-east-1" 3 | business_divsion = "hr" 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /git-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Add files and do local commit" 4 | git add . 5 | git commit -am "Welcome to StackSimplify" 6 | 7 | echo "Pushing to Github Repository" 8 | git push 9 | -------------------------------------------------------------------------------- /presentation/Terraform-On-AWS-v2.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ann-felix/terraform-on-aws-ec2/56f6831f08778c773ddc2bdd9d516874e8088ea9/presentation/Terraform-On-AWS-v2.pptx --------------------------------------------------------------------------------