├── .gitignore
├── 1d_Linux_install
└── terrafrom.sh
├── 1f_First_terraform_deployment
└── first_deployment.tf
├── 2c_Basic_commands_and_execution
└── first_deployment.tf
├── 2d_Resources
└── resources.tf
├── 2e_Providers
└── providers.tf
├── 2f_Variables
├── var-file-example.tfvars
└── variables.tf
├── 2g_Outputs
└── outputs.tf
├── 2h_Exercise
└── answers.tf
├── 3b_Interpolations_expressions
└── expressions.tf
├── 3c_Locals
└── locals.tf
├── 3d_Data_sources
└── data_sources.tf
├── 3e_modules
├── aws_instances
│ ├── main.tf
│ ├── outputs.tf
│ ├── providers.tf
│ └── variables.tf
├── modules.tf
└── variables.tf
├── 3f_Backends_and_remote_states
├── .aws
│ ├── config
│ └── credentials
└── backend.tf
├── 3g_Workspaces
└── workspaces.tf
├── 3h_Software_provisioning_Part_1
├── frontend
│ ├── frontend.conf
│ ├── index.php
│ ├── require
│ │ ├── Requests.php
│ │ └── Requests
│ │ │ ├── Auth.php
│ │ │ ├── Auth
│ │ │ └── Basic.php
│ │ │ ├── Cookie.php
│ │ │ ├── Cookie
│ │ │ └── Jar.php
│ │ │ ├── Exception.php
│ │ │ ├── Exception
│ │ │ ├── HTTP.php
│ │ │ ├── HTTP
│ │ │ │ ├── 304.php
│ │ │ │ ├── 305.php
│ │ │ │ ├── 306.php
│ │ │ │ ├── 400.php
│ │ │ │ ├── 401.php
│ │ │ │ ├── 402.php
│ │ │ │ ├── 403.php
│ │ │ │ ├── 404.php
│ │ │ │ ├── 405.php
│ │ │ │ ├── 406.php
│ │ │ │ ├── 407.php
│ │ │ │ ├── 408.php
│ │ │ │ ├── 409.php
│ │ │ │ ├── 410.php
│ │ │ │ ├── 411.php
│ │ │ │ ├── 412.php
│ │ │ │ ├── 413.php
│ │ │ │ ├── 414.php
│ │ │ │ ├── 415.php
│ │ │ │ ├── 416.php
│ │ │ │ ├── 417.php
│ │ │ │ ├── 418.php
│ │ │ │ ├── 428.php
│ │ │ │ ├── 429.php
│ │ │ │ ├── 431.php
│ │ │ │ ├── 500.php
│ │ │ │ ├── 501.php
│ │ │ │ ├── 502.php
│ │ │ │ ├── 503.php
│ │ │ │ ├── 504.php
│ │ │ │ ├── 505.php
│ │ │ │ ├── 511.php
│ │ │ │ └── Unknown.php
│ │ │ ├── Transport.php
│ │ │ └── Transport
│ │ │ │ └── cURL.php
│ │ │ ├── Hooker.php
│ │ │ ├── Hooks.php
│ │ │ ├── IDNAEncoder.php
│ │ │ ├── IPv6.php
│ │ │ ├── IRI.php
│ │ │ ├── Proxy.php
│ │ │ ├── Proxy
│ │ │ └── HTTP.php
│ │ │ ├── Response.php
│ │ │ ├── Response
│ │ │ └── Headers.php
│ │ │ ├── SSL.php
│ │ │ ├── Session.php
│ │ │ ├── Transport.php
│ │ │ ├── Transport
│ │ │ ├── cURL.php
│ │ │ ├── cacert.pem
│ │ │ └── fsockopen.php
│ │ │ └── Utility
│ │ │ ├── CaseInsensitiveDictionary.php
│ │ │ └── FilteredIterator.php
│ └── run_frontend.sh
├── remote_exec.tf
└── variables.tf
├── 3i_Software_provisioning_Part_2
├── ansible
│ ├── group_vars
│ │ └── all.yml
│ ├── pre-task.yml
│ └── setup-backend.yaml
├── backend
│ ├── .idea
│ │ ├── backend.iml
│ │ ├── codeStyles
│ │ │ ├── Project.xml
│ │ │ └── codeStyleConfig.xml
│ │ ├── httpRequests
│ │ │ ├── 2018-04-26T033228.404.txt
│ │ │ ├── 2018-04-26T033243.404.txt
│ │ │ ├── 2018-04-26T033244.404.txt
│ │ │ ├── 2018-04-26T033246-1.404.txt
│ │ │ ├── 2018-04-26T033246.404.txt
│ │ │ ├── 2018-04-26T033247-1.404.txt
│ │ │ ├── 2018-04-26T033247-2.404.txt
│ │ │ ├── 2018-04-26T033247-3.404.txt
│ │ │ ├── 2018-04-26T033247.404.txt
│ │ │ ├── 2018-04-26T033248.404.txt
│ │ │ ├── 2018-04-26T033256.200.json
│ │ │ ├── 2018-04-26T033934.200.json
│ │ │ └── http-requests-log.http
│ │ ├── inspectionProfiles
│ │ │ └── Project_Default.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── backend
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-35.pyc
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ ├── settings.cpython-35.pyc
│ │ │ ├── settings.cpython-36.pyc
│ │ │ ├── urls.cpython-35.pyc
│ │ │ ├── urls.cpython-36.pyc
│ │ │ ├── views.cpython-35.pyc
│ │ │ ├── views.cpython-36.pyc
│ │ │ ├── wsgi.cpython-35.pyc
│ │ │ └── wsgi.cpython-36.pyc
│ │ ├── settings.py
│ │ ├── urls.py
│ │ ├── views.py
│ │ └── wsgi.py
│ ├── db.sqlite3
│ ├── manage.py
│ └── requirements.txt
├── local_exec.tf
├── php-fpm.conf
├── php-fpm.yml
├── scripts
│ └── ansible-install-ubuntu.sh
└── variables.tf
├── 3j_Exercise
├── Backend
│ ├── ansible
│ │ ├── group_vars
│ │ │ └── all.yml
│ │ ├── hosts
│ │ ├── pre-task.retry
│ │ ├── pre-task.yml
│ │ ├── setup-backend.retry
│ │ └── setup-backend.yaml
│ ├── backend
│ │ ├── .idea
│ │ │ ├── backend.iml
│ │ │ ├── codeStyles
│ │ │ │ ├── Project.xml
│ │ │ │ └── codeStyleConfig.xml
│ │ │ ├── httpRequests
│ │ │ │ ├── 2018-04-26T033228.404.txt
│ │ │ │ ├── 2018-04-26T033243.404.txt
│ │ │ │ ├── 2018-04-26T033244.404.txt
│ │ │ │ ├── 2018-04-26T033246-1.404.txt
│ │ │ │ ├── 2018-04-26T033246.404.txt
│ │ │ │ ├── 2018-04-26T033247-1.404.txt
│ │ │ │ ├── 2018-04-26T033247-2.404.txt
│ │ │ │ ├── 2018-04-26T033247-3.404.txt
│ │ │ │ ├── 2018-04-26T033247.404.txt
│ │ │ │ ├── 2018-04-26T033248.404.txt
│ │ │ │ ├── 2018-04-26T033256.200.json
│ │ │ │ ├── 2018-04-26T033934.200.json
│ │ │ │ └── http-requests-log.http
│ │ │ ├── inspectionProfiles
│ │ │ │ └── Project_Default.xml
│ │ │ ├── misc.xml
│ │ │ ├── modules.xml
│ │ │ └── workspace.xml
│ │ ├── backend
│ │ │ ├── __init__.py
│ │ │ ├── __pycache__
│ │ │ │ ├── __init__.cpython-35.pyc
│ │ │ │ ├── __init__.cpython-36.pyc
│ │ │ │ ├── settings.cpython-35.pyc
│ │ │ │ ├── settings.cpython-36.pyc
│ │ │ │ ├── urls.cpython-35.pyc
│ │ │ │ ├── urls.cpython-36.pyc
│ │ │ │ ├── views.cpython-35.pyc
│ │ │ │ ├── views.cpython-36.pyc
│ │ │ │ ├── wsgi.cpython-35.pyc
│ │ │ │ └── wsgi.cpython-36.pyc
│ │ │ ├── settings.py
│ │ │ ├── urls.py
│ │ │ ├── views.py
│ │ │ └── wsgi.py
│ │ ├── db.sqlite3
│ │ ├── manage.py
│ │ └── requirements.txt
│ ├── main.tf
│ ├── php-fpm.conf
│ ├── php-fpm.yml
│ ├── scripts
│ │ └── ansible-install-ubuntu.sh
│ └── variables.tf
├── Frontend
│ ├── frontend
│ │ ├── frontend.conf
│ │ ├── index.php
│ │ ├── require
│ │ │ ├── Requests.php
│ │ │ └── Requests
│ │ │ │ ├── Auth.php
│ │ │ │ ├── Auth
│ │ │ │ └── Basic.php
│ │ │ │ ├── Cookie.php
│ │ │ │ ├── Cookie
│ │ │ │ └── Jar.php
│ │ │ │ ├── Exception.php
│ │ │ │ ├── Exception
│ │ │ │ ├── HTTP.php
│ │ │ │ ├── HTTP
│ │ │ │ │ ├── 304.php
│ │ │ │ │ ├── 305.php
│ │ │ │ │ ├── 306.php
│ │ │ │ │ ├── 400.php
│ │ │ │ │ ├── 401.php
│ │ │ │ │ ├── 402.php
│ │ │ │ │ ├── 403.php
│ │ │ │ │ ├── 404.php
│ │ │ │ │ ├── 405.php
│ │ │ │ │ ├── 406.php
│ │ │ │ │ ├── 407.php
│ │ │ │ │ ├── 408.php
│ │ │ │ │ ├── 409.php
│ │ │ │ │ ├── 410.php
│ │ │ │ │ ├── 411.php
│ │ │ │ │ ├── 412.php
│ │ │ │ │ ├── 413.php
│ │ │ │ │ ├── 414.php
│ │ │ │ │ ├── 415.php
│ │ │ │ │ ├── 416.php
│ │ │ │ │ ├── 417.php
│ │ │ │ │ ├── 418.php
│ │ │ │ │ ├── 428.php
│ │ │ │ │ ├── 429.php
│ │ │ │ │ ├── 431.php
│ │ │ │ │ ├── 500.php
│ │ │ │ │ ├── 501.php
│ │ │ │ │ ├── 502.php
│ │ │ │ │ ├── 503.php
│ │ │ │ │ ├── 504.php
│ │ │ │ │ ├── 505.php
│ │ │ │ │ ├── 511.php
│ │ │ │ │ └── Unknown.php
│ │ │ │ ├── Transport.php
│ │ │ │ └── Transport
│ │ │ │ │ └── cURL.php
│ │ │ │ ├── Hooker.php
│ │ │ │ ├── Hooks.php
│ │ │ │ ├── IDNAEncoder.php
│ │ │ │ ├── IPv6.php
│ │ │ │ ├── IRI.php
│ │ │ │ ├── Proxy.php
│ │ │ │ ├── Proxy
│ │ │ │ └── HTTP.php
│ │ │ │ ├── Response.php
│ │ │ │ ├── Response
│ │ │ │ └── Headers.php
│ │ │ │ ├── SSL.php
│ │ │ │ ├── Session.php
│ │ │ │ ├── Transport.php
│ │ │ │ ├── Transport
│ │ │ │ ├── cURL.php
│ │ │ │ ├── cacert.pem
│ │ │ │ └── fsockopen.php
│ │ │ │ └── Utility
│ │ │ │ ├── CaseInsensitiveDictionary.php
│ │ │ │ └── FilteredIterator.php
│ │ └── run_frontend.sh
│ ├── main.tf
│ └── variables.tf
└── example.tf
├── 4b_Vpcs
└── vpc.tf
├── 4c_EBS
└── ebs.tf
├── 4d_IAM
├── main.tf
└── variables.tf
├── 4e_Route53
└── dns.tf
├── 4f_AutoScaling
└── Autoscaling.tf
├── 4g_RDS
└── RDS.tf
├── 4h_LB
└── ELB.tf
├── 4i_Lambda
├── hello_lambda.py
├── hello_lambda.zip
├── main.tf
└── outputs.tf
├── 4j_Real_life_example
├── Autoscaling.tf
├── Dns.tf
├── Elb.tf
├── Rds.tf
└── vpc.tf
├── 5c_Deploy_cluster
├── kube.tf
└── kubernetes
│ ├── main.tf
│ ├── providers.tf
│ └── variables.tf
├── 5e_First_Kube_app
└── deployment.tf
├── 5h_MongoDB
└── mongo.tf
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .terraform
2 | *.tfstate*
3 | tmp/
4 |
--------------------------------------------------------------------------------
/1d_Linux_install/terrafrom.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | function terraform-install() {
4 | [[ -f ${HOME}/bin/terraform ]] && echo "`${HOME}/bin/terraform version` already installed at ${HOME}/bin/terraform" && return 0
5 | LATEST_URL=$(curl -sL https://releases.hashicorp.com/terraform/index.json | jq -r '.versions[].builds[].url' | sort --version-sort | egrep -v 'rc|beta|alpha' | egrep 'linux.*amd64' |tail -1)
6 | curl ${LATEST_URL} > /tmp/terraform.zip
7 | mkdir -p ${HOME}/bin
8 | (cd ${HOME}/bin && unzip /tmp/terraform.zip)
9 | if [[ -z $(grep 'export PATH=${HOME}/bin:${PATH}' ~/.bashrc) ]]; then
10 | echo 'export PATH=${HOME}/bin:${PATH}' >> ~/.bashrc
11 | fi
12 |
13 | echo "Installed: `${HOME}/bin/terraform version`"
14 |
15 | cat - << EOF
16 |
17 | Run the following to reload your PATH with terraform:
18 | source ~/.bashrc
19 | EOF
20 | }
21 |
22 | terraform-install
23 |
--------------------------------------------------------------------------------
/1f_First_terraform_deployment/first_deployment.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "Access Key"
3 | secret_key = "Secrey Key"
4 | region = "us-east-1"
5 | }
6 | resource "aws_instance" "example" {
7 | ami = "ami-2757f631"
8 | instance_type = "t2.micro"
9 | }
10 |
--------------------------------------------------------------------------------
/2c_Basic_commands_and_execution/first_deployment.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "ACCESS_KEY"
3 | secret_key = "SECRET_KEY"
4 | region = "us-east-1"
5 | }
6 | resource "aws_instance" "example" {
7 | ami = "ami-2757f631"
8 | instance_type = "t2.micro"
9 | }
10 |
--------------------------------------------------------------------------------
/2d_Resources/resources.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "ACCESS_KEY"
3 | secret_key = "SECRET_KEY"
4 | region = "us-east-1"
5 | }
6 |
7 | resource "aws_instance" "frontend" {
8 | depends_on = ["aws_instance.backend"]
9 | ami = "ami-66506c1c"
10 | instance_type = "t2.micro"
11 | lifecycle {
12 | create_before_destroy = true
13 | }
14 | }
15 |
16 | resource "aws_instance" "backend" {
17 | count = 2
18 | ami = "ami-66506c1c"
19 | instance_type = "t2.micro"
20 | timeouts {
21 | create = "60m"
22 | delete = "2h"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/2e_Providers/providers.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "ACCESS_KEY"
3 | secret_key = "SECRET_KEY"
4 | region = "us-east-1"
5 | }
6 |
7 | provider "aws" {
8 | access_key = "ACCESS_KEY"
9 | secret_key = "SECRET_KEY"
10 | alias = "us-west-1"
11 | region = "us-west-1"
12 | }
13 |
14 | resource "aws_instance" "us_west_example" {
15 | provider = "aws.us-west-1"
16 | ami = "ami-07585467"
17 | instance_type = "t2.micro"
18 | }
19 |
20 | resource "aws_instance" "us_east_example" {
21 | ami = "ami-66506c1c"
22 | instance_type = "t2.micro"
23 | }
24 |
--------------------------------------------------------------------------------
/2f_Variables/var-file-example.tfvars:
--------------------------------------------------------------------------------
1 | zones = ["us-east-1c", "us-east-1d"]
2 |
--------------------------------------------------------------------------------
/2f_Variables/variables.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "ACCESS_KEY"
3 | secret_key = "SECRET_KEY"
4 | region = "us-east-1"
5 | }
6 |
7 | variable "zones" {
8 | default = ["us-east-1a", "us-east-1b"]
9 | }
10 |
11 | resource "aws_instance" "example" {
12 | count = 2
13 | availability_zone = "${var.zones[count.index]}"
14 | ami = "ami-07585467"
15 | instance_type = "t2.micro"
16 | }
17 |
--------------------------------------------------------------------------------
/2g_Outputs/outputs.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "ACCESS_KEY"
3 | secret_key = "SECRET_KEY"
4 | region = "us-east-1"
5 | }
6 |
7 | resource "aws_instance" "frontend" {
8 | ami = "ami-66506c1c"
9 | instance_type = "t2.micro"
10 | }
11 |
12 | resource "aws_instance" "backend" {
13 | count = 2
14 | ami = "ami-66506c1c"
15 | instance_type = "t2.micro"
16 | }
17 |
18 | output "frontend_ip" {
19 | value = "${aws_instance.frontend.public_ip}"
20 | }
21 |
22 | output "backend_ips" {
23 | value = "${aws_instance.backend.*.public_ip}"
24 | }
25 |
--------------------------------------------------------------------------------
/2h_Exercise/answers.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "ACCESS_KEY"
3 | secret_key = "SECRET_KEY"
4 | region = "us-east-1"
5 | }
6 |
7 | provider "aws" {
8 | alias = "us-west-1"
9 | access_key = "ACCESS_KEY"
10 | secret_key = "SECRET_KEY"
11 | region = "us-west-1"
12 | }
13 |
14 | variable "us-east-zones" {
15 | default = ["us-east-1a", "us-east-1b"]
16 | }
17 |
18 | variable "us-west-zones" {
19 | default = ["us-west-1a", "us-west-1b"]
20 | }
21 |
22 | resource "aws_instance" "west_frontend" {
23 | count = 2
24 | depends_on = ["aws_instance.west_backend"]
25 | provider = "aws.us-west-1"
26 | ami = "ami-07585467"
27 | availability_zone = "${var.us-west-zones[count.index]}"
28 | instance_type = "t2.micro"
29 |
30 | lifecycle {
31 | create_before_destroy = true
32 | }
33 | }
34 |
35 | resource "aws_instance" "frontend" {
36 | count = 2
37 | depends_on = ["aws_instance.backend"]
38 | availability_zone = "${var.us-east-zones[count.index]}"
39 | ami = "ami-66506c1c"
40 | instance_type = "t2.micro"
41 |
42 | lifecycle {
43 | create_before_destroy = true
44 | }
45 | }
46 |
47 | resource "aws_instance" "backend" {
48 | count = 2
49 | availability_zone = "${var.us-east-zones[count.index]}"
50 | ami = "ami-66506c1c"
51 | instance_type = "t2.micro"
52 |
53 | lifecycle {
54 | prevent_destroy = true
55 | }
56 | }
57 |
58 | resource "aws_instance" "west_backend" {
59 | provider = "aws.us-west-1"
60 | ami = "ami-07585467"
61 | count = 2
62 | availability_zone = "${var.us-west-zones[count.index]}"
63 | instance_type = "t2.micro"
64 |
65 | lifecycle {
66 | prevent_destroy = true
67 | }
68 | }
69 |
70 | output "frontend_ip" {
71 | value = "${aws_instance.frontend.public_ip}"
72 | }
73 |
74 | output "backend_ips" {
75 | value = "${aws_instance.backend.*.public_ip}"
76 | }
77 |
--------------------------------------------------------------------------------
/3b_Interpolations_expressions/expressions.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "ACCESS_KEY"
3 | secret_key = "SECRET_KEY"
4 | region = "us-east-1"
5 | }
6 |
7 | provider "aws" {
8 | alias = "us-west-1"
9 | access_key = "ACCESS_KEY"
10 | secret_key = "SECRET_KEY"
11 | region = "us-west-1"
12 | }
13 |
14 | variable "us-east-zones" {
15 | default = ["us-east-1a", "us-east-1b"]
16 | }
17 |
18 | variable "us-west-zones" {
19 | default = ["us-west-1c", "us-west-1b"]
20 | }
21 |
22 | variable "multi-region-deployment" {
23 | default = true
24 | }
25 |
26 | variable "environment-name" {
27 | default = "Terraform-demo"
28 | }
29 |
30 | resource "aws_instance" "frontend" {
31 | tags = {
32 | Name = "${join("-",list(var.environment-name, "frontend"))}"
33 | }
34 |
35 | depends_on = ["aws_instance.backend"]
36 | availability_zone = "${var.us-east-zones[count.index]}"
37 | ami = "ami-66506c1c"
38 | instance_type = "t2.micro"
39 | }
40 |
41 | resource "aws_instance" "west_frontend" {
42 | tags = {
43 | Name = "${join("-",list(var.environment-name, "frontend"))}"
44 | }
45 |
46 | count = "${var.multi-region-deployment ? 1 : 0}"
47 | depends_on = ["aws_instance.west_backend"]
48 | provider = "aws.us-west-1"
49 | ami = "ami-07585467"
50 | availability_zone = "${var.us-west-zones[count.index]}"
51 | instance_type = "t2.micro"
52 | }
53 |
54 | resource "aws_instance" "backend" {
55 | tags = {
56 | Name = "${join("-", list(var.environment-name, "backend"))}"
57 | }
58 |
59 | count = 2
60 | availability_zone = "${var.us-east-zones[count.index]}"
61 | ami = "ami-66506c1c"
62 | instance_type = "t2.micro"
63 | }
64 |
65 | resource "aws_instance" "west_backend" {
66 | tags = {
67 | Name = "${join("-", list(var.environment-name, "backend"))}"
68 | }
69 |
70 | provider = "aws.us-west-1"
71 | ami = "ami-07585467"
72 | count = "${var.multi-region-deployment ? 2 : 0}"
73 | availability_zone = "${var.us-west-zones[count.index]}"
74 | instance_type = "t2.micro"
75 | }
76 |
77 | output "frontend_ip" {
78 | value = "${aws_instance.frontend.public_ip}"
79 | }
80 |
81 | output "backend_ips" {
82 | value = "${aws_instance.backend.*.public_ip}"
83 | }
84 |
85 | output "west_frontend_ip" {
86 | value = "${aws_instance.west_frontend.*.public_ip}"
87 | }
88 |
89 | output "west_backend_ips" {
90 | value = "${aws_instance.west_backend.*.public_ip}"
91 | }
92 |
--------------------------------------------------------------------------------
/3c_Locals/locals.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "ACCESS_KEY"
3 | secret_key = "SECRET_KEY"
4 | region = "us-east-1"
5 | }
6 |
7 | provider "aws" {
8 | alias = "us-west-1"
9 | access_key = "ACCESS_KEY"
10 | secret_key = "SECRET_KEY"
11 | region = "us-west-1"
12 | }
13 |
14 | variable "us-east-zones" {
15 | default = ["us-east-1a", "us-east-1b"]
16 | }
17 |
18 | variable "us-west-zones" {
19 | default = ["us-west-1c", "us-west-1b"]
20 | }
21 |
22 | variable "multi-region-deployment" {
23 | default = true
24 | }
25 |
26 | variable "environment-name" {
27 | default = "Terraform-demo"
28 | }
29 |
30 | locals {
31 | default_frontend_name = "${join("-",list(var.environment-name, "frontend"))}"
32 | default_backend_name = "${join("-",list(var.environment-name, "backend"))}"
33 | }
34 |
35 | resource "aws_instance" "frontend" {
36 | tags = {
37 | Name = "${local.default_frontend_name}"
38 | }
39 |
40 | depends_on = ["aws_instance.backend"]
41 | availability_zone = "${var.us-east-zones[count.index]}"
42 | ami = "ami-66506c1c"
43 | instance_type = "t2.micro"
44 | }
45 |
46 | resource "aws_instance" "west_frontend" {
47 | tags = {
48 | Name = "${local.default_frontend_name}"
49 | }
50 |
51 | count = "${var.multi-region-deployment ? 1 : 0}"
52 | depends_on = ["aws_instance.west_backend"]
53 | provider = "aws.us-west-1"
54 | ami = "ami-07585467"
55 | availability_zone = "${var.us-west-zones[count.index]}"
56 | instance_type = "t2.micro"
57 | }
58 |
59 | resource "aws_instance" "backend" {
60 | tags = {
61 | Name = "${local.default_backend_name}"
62 | }
63 |
64 | count = 2
65 | availability_zone = "${var.us-east-zones[count.index]}"
66 | ami = "ami-66506c1c"
67 | instance_type = "t2.micro"
68 | }
69 |
70 | resource "aws_instance" "west_backend" {
71 | tags = {
72 | Name = "${local.default_backend_name}"
73 | }
74 |
75 | provider = "aws.us-west-1"
76 | ami = "ami-07585467"
77 | count = "${var.multi-region-deployment ? 2 : 0}"
78 | availability_zone = "${var.us-west-zones[count.index]}"
79 | instance_type = "t2.micro"
80 | }
81 |
82 | output "frontend_ip" {
83 | value = "${aws_instance.frontend.public_ip}"
84 | }
85 |
86 | output "backend_ips" {
87 | value = "${aws_instance.backend.*.public_ip}"
88 | }
89 |
90 | output "west_frontend_ip" {
91 | value = "${aws_instance.west_frontend.*.public_ip}"
92 | }
93 |
94 | output "west_backend_ips" {
95 | value = "${aws_instance.west_backend.*.public_ip}"
96 | }
97 |
--------------------------------------------------------------------------------
/3d_Data_sources/data_sources.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | region = "us-east-1"
3 | }
4 |
5 | provider "aws" {
6 | alias = "us-west-1"
7 | region = "us-west-1"
8 | }
9 |
10 | data "aws_availability_zones" "us-east-1" {}
11 |
12 | data "aws_availability_zones" "us-west-1" {
13 | provider = "aws.us-west-1"
14 | }
15 |
16 | variable "multi-region-deployment" {
17 | default = true
18 | }
19 |
20 | variable "environment-name" {
21 | default = "Terraform-demo"
22 | }
23 |
24 | locals {
25 | default_frontend_name = "${join("-",list(var.environment-name, "frontend"))}"
26 | default_backend_name = "${join("-",list(var.environment-name, "backend"))}"
27 | }
28 |
29 | resource "aws_instance" "frontend" {
30 | tags = {
31 | Name = "${local.default_frontend_name}"
32 | }
33 |
34 | depends_on = ["aws_instance.backend"]
35 | availability_zone = "${data.aws_availability_zones.us-east-1.names[count.index]}"
36 | ami = "ami-66506c1c"
37 | instance_type = "t2.micro"
38 | }
39 |
40 | resource "aws_instance" "west_frontend" {
41 | tags = {
42 | Name = "${local.default_frontend_name}"
43 | }
44 |
45 | count = "${var.multi-region-deployment ? 1 : 0}"
46 | depends_on = ["aws_instance.west_backend"]
47 | provider = "aws.us-west-1"
48 | ami = "ami-07585467"
49 | availability_zone = "${data.aws_availability_zones.us-west-1.names[count.index]}"
50 | instance_type = "t2.micro"
51 | }
52 |
53 | resource "aws_instance" "backend" {
54 | tags = {
55 | Name = "${local.default_backend_name}"
56 | }
57 |
58 | count = 2
59 | availability_zone = "${data.aws_availability_zones.us-east-1.names[count.index]}"
60 | ami = "ami-66506c1c"
61 | instance_type = "t2.micro"
62 | }
63 |
64 | resource "aws_instance" "west_backend" {
65 | tags = {
66 | Name = "${local.default_backend_name}"
67 | }
68 |
69 | provider = "aws.us-west-1"
70 | ami = "ami-07585467"
71 | count = "${var.multi-region-deployment ? 2 : 0}"
72 | availability_zone = "${data.aws_availability_zones.us-west-1.names[count.index]}"
73 | instance_type = "t2.micro"
74 | }
75 |
76 | output "frontend_ip" {
77 | value = "${aws_instance.frontend.public_ip}"
78 | }
79 |
80 | output "backend_ips" {
81 | value = "${aws_instance.backend.*.public_ip}"
82 | }
83 |
84 | output "west_frontend_ip" {
85 | value = "${aws_instance.west_frontend.*.public_ip}"
86 | }
87 |
88 | output "west_backend_ips" {
89 | value = "${aws_instance.west_backend.*.public_ip}"
90 | }
91 |
92 | output "data-aws-azs-us-east" {
93 | value = "${data.aws_availability_zones.us-east-1.*.names}"
94 | }
95 |
--------------------------------------------------------------------------------
/3e_modules/aws_instances/main.tf:
--------------------------------------------------------------------------------
1 | data "aws_availability_zones" "available" {}
2 |
3 | resource "aws_instance" "instance" {
4 | count = "${var.total_instances}"
5 | ami = "${var.amis[var.region]}"
6 | instance_type = "t2.micro"
7 | availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/3e_modules/aws_instances/outputs.tf:
--------------------------------------------------------------------------------
1 | output "ips" {
2 | value = "${aws_instance.instance.*.public_ip}"
3 | }
4 |
--------------------------------------------------------------------------------
/3e_modules/aws_instances/providers.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | access_key = "${var.aws_access_key}"
3 | secret_key = "${var.aws_secret_key}"
4 | region = "${var.region}"
5 | }
6 |
--------------------------------------------------------------------------------
/3e_modules/aws_instances/variables.tf:
--------------------------------------------------------------------------------
1 | variable "amis" {
2 | type = "map"
3 | default = {
4 | us-east-1 = "ami-66506c1c"
5 | us-west-1 = "ami-07585467"
6 | }
7 | }
8 |
9 | variable "region" {
10 | default="us-east-1"
11 | }
12 |
13 | variable "total_instances" {
14 | default=1
15 | }
16 |
17 | variable "aws_access_key" {}
18 | variable "aws_secret_key" {}
19 |
--------------------------------------------------------------------------------
/3e_modules/modules.tf:
--------------------------------------------------------------------------------
1 | module "frontend" {
2 | source = "./aws_instances"
3 | aws_access_key = "${var.aws_access_key}"
4 | aws_secret_key = "${var.aws_secret_key}"
5 | }
6 |
7 | module "backend" {
8 | source = "./aws_instances"
9 | total_instances = 2
10 | aws_access_key = "${var.aws_access_key}"
11 | aws_secret_key = "${var.aws_secret_key}"
12 | }
13 |
14 | output "frontnend_ips" {
15 | value = "${module.frontend.ips}"
16 | }
17 |
18 | output "backend_ips" {
19 | value = "${module.backend.ips}"
20 | }
21 |
--------------------------------------------------------------------------------
/3e_modules/variables.tf:
--------------------------------------------------------------------------------
1 | variable "aws_access_key" {}
2 |
3 | variable "aws_secret_key" {}
4 |
--------------------------------------------------------------------------------
/3f_Backends_and_remote_states/.aws/config:
--------------------------------------------------------------------------------
1 | [default]
2 | region = us-east-1
3 |
4 | [profile caylentProd]
5 | region = us-east-1
6 |
--------------------------------------------------------------------------------
/3f_Backends_and_remote_states/.aws/credentials:
--------------------------------------------------------------------------------
1 | [caylentProd]
2 | aws_access_key_id = my_access_key
3 | aws_secret_access_key = my_secret_key
4 |
5 | [default]
6 | aws_access_key_id = my_access_key
7 | aws_secret_access_key = my_secret_key
8 |
--------------------------------------------------------------------------------
/3f_Backends_and_remote_states/backend.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | backend "s3" {
3 | bucket = "stefan-terraform-demo"
4 | key = "network/terraform.tfstate"
5 | region = "us-east-1"
6 | }
7 | }
8 |
9 | provider "aws" {
10 | region = "us-east-1"
11 | }
12 |
13 | resource "aws_instance" "example" {
14 | ami = "ami-2757f631"
15 | instance_type = "t2.micro"
16 | }
17 |
--------------------------------------------------------------------------------
/3g_Workspaces/workspaces.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | region = "us-east-1"
3 | }
4 |
5 | locals {
6 | default_name = "${join("-", list(terraform.workspace, "example"))}"
7 | }
8 |
9 | resource "aws_instance" "example" {
10 | tags = {
11 | Name = "${local.default_name}"
12 | }
13 |
14 | ami = "ami-2757f631"
15 | instance_type = "t2.micro"
16 | }
17 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/frontend.conf:
--------------------------------------------------------------------------------
1 | server {
2 | listen 80 default_server;
3 | listen [::]:80 default_server;
4 | server_name localhost;
5 | root /var/www/frontend;
6 | index index.php;
7 |
8 | location ~* \.php$ {
9 | fastcgi_pass unix:/run/php/php7.0-fpm.sock;
10 | include fastcgi_params;
11 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
12 | fastcgi_param SCRIPT_NAME $fastcgi_script_name;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/index.php:
--------------------------------------------------------------------------------
1 | 'application/json');
15 | $options = array('auth' => array('user', 'pass'));
16 |
17 |
18 | foreach ($url_list as $url) {
19 |
20 | $request = Requests::get($url . $msg, $headers, $options);
21 |
22 | print($request->body);
23 | print(PHP_EOL);
24 |
25 | // var_dump($request->body);
26 | };
27 |
28 |
29 | ?>
30 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Auth.php:
--------------------------------------------------------------------------------
1 | user, $this->pass) = $args;
46 | }
47 | }
48 |
49 | /**
50 | * Register the necessary callbacks
51 | *
52 | * @see curl_before_send
53 | * @see fsockopen_header
54 | * @param Requests_Hooks $hooks Hook system
55 | */
56 | public function register(Requests_Hooks &$hooks) {
57 | $hooks->register('curl.before_send', array(&$this, 'curl_before_send'));
58 | $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header'));
59 | }
60 |
61 | /**
62 | * Set cURL parameters before the data is sent
63 | *
64 | * @param resource $handle cURL resource
65 | */
66 | public function curl_before_send(&$handle) {
67 | curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
68 | curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString());
69 | }
70 |
71 | /**
72 | * Add extra headers to the request before sending
73 | *
74 | * @param string $out HTTP header string
75 | */
76 | public function fsockopen_header(&$out) {
77 | $out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString()));
78 | }
79 |
80 | /**
81 | * Get the authentication string (user:pass)
82 | *
83 | * @return string
84 | */
85 | public function getAuthString() {
86 | return $this->user . ':' . $this->pass;
87 | }
88 | }
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Exception.php:
--------------------------------------------------------------------------------
1 | type = $type;
40 | $this->data = $data;
41 | }
42 |
43 | /**
44 | * Like {@see getCode()}, but a string code.
45 | *
46 | * @codeCoverageIgnore
47 | * @return string
48 | */
49 | public function getType() {
50 | return $this->type;
51 | }
52 |
53 | /**
54 | * Gives any relevant data
55 | *
56 | * @codeCoverageIgnore
57 | * @return mixed
58 | */
59 | public function getData() {
60 | return $this->data;
61 | }
62 | }
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Exception/HTTP.php:
--------------------------------------------------------------------------------
1 | reason = $reason;
40 | }
41 |
42 | $message = sprintf('%d %s', $this->code, $this->reason);
43 | parent::__construct($message, 'httpresponse', $data, $this->code);
44 | }
45 |
46 | /**
47 | * Get the status message
48 | */
49 | public function getReason() {
50 | return $this->reason;
51 | }
52 |
53 | /**
54 | * Get the correct exception class for a given error code
55 | *
56 | * @param int|bool $code HTTP status code, or false if unavailable
57 | * @return string Exception class name to use
58 | */
59 | public static function get_class($code) {
60 | if (!$code) {
61 | return 'Requests_Exception_HTTP_Unknown';
62 | }
63 |
64 | $class = sprintf('Requests_Exception_HTTP_%d', $code);
65 | if (class_exists($class)) {
66 | return $class;
67 | }
68 |
69 | return 'Requests_Exception_HTTP_Unknown';
70 | }
71 | }
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Exception/HTTP/304.php:
--------------------------------------------------------------------------------
1 | code = $data->status_code;
40 | }
41 |
42 | parent::__construct($reason, $data);
43 | }
44 | }
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Exception/Transport.php:
--------------------------------------------------------------------------------
1 | type = $type;
35 | }
36 |
37 | if ($code !== null) {
38 | $this->code = $code;
39 | }
40 |
41 | if ($message !== null) {
42 | $this->reason = $message;
43 | }
44 |
45 | $message = sprintf('%d %s', $this->code, $this->reason);
46 | parent::__construct($message, $this->type, $data, $this->code);
47 | }
48 |
49 | /**
50 | * Get the error message
51 | */
52 | public function getReason() {
53 | return $this->reason;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Hooker.php:
--------------------------------------------------------------------------------
1 | 0 is executed later
22 | */
23 | public function register($hook, $callback, $priority = 0);
24 |
25 | /**
26 | * Dispatch a message
27 | *
28 | * @param string $hook Hook name
29 | * @param array $parameters Parameters to pass to callbacks
30 | * @return boolean Successfulness
31 | */
32 | public function dispatch($hook, $parameters = array());
33 | }
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Hooks.php:
--------------------------------------------------------------------------------
1 | 0 is executed later
36 | */
37 | public function register($hook, $callback, $priority = 0) {
38 | if (!isset($this->hooks[$hook])) {
39 | $this->hooks[$hook] = array();
40 | }
41 | if (!isset($this->hooks[$hook][$priority])) {
42 | $this->hooks[$hook][$priority] = array();
43 | }
44 |
45 | $this->hooks[$hook][$priority][] = $callback;
46 | }
47 |
48 | /**
49 | * Dispatch a message
50 | *
51 | * @param string $hook Hook name
52 | * @param array $parameters Parameters to pass to callbacks
53 | * @return boolean Successfulness
54 | */
55 | public function dispatch($hook, $parameters = array()) {
56 | if (empty($this->hooks[$hook])) {
57 | return false;
58 | }
59 |
60 | foreach ($this->hooks[$hook] as $priority => $hooked) {
61 | foreach ($hooked as $callback) {
62 | call_user_func_array($callback, $parameters);
63 | }
64 | }
65 |
66 | return true;
67 | }
68 | }
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Proxy.php:
--------------------------------------------------------------------------------
1 | proxy = $args;
60 | }
61 | elseif (is_array($args)) {
62 | if (count($args) == 1) {
63 | list($this->proxy) = $args;
64 | }
65 | elseif (count($args) == 3) {
66 | list($this->proxy, $this->user, $this->pass) = $args;
67 | $this->use_authentication = true;
68 | }
69 | else {
70 | throw new Requests_Exception('Invalid number of arguments', 'proxyhttpbadargs');
71 | }
72 | }
73 | }
74 |
75 | /**
76 | * Register the necessary callbacks
77 | *
78 | * @since 1.6
79 | * @see curl_before_send
80 | * @see fsockopen_remote_socket
81 | * @see fsockopen_remote_host_path
82 | * @see fsockopen_header
83 | * @param Requests_Hooks $hooks Hook system
84 | */
85 | public function register(Requests_Hooks &$hooks) {
86 | $hooks->register('curl.before_send', array(&$this, 'curl_before_send'));
87 |
88 | $hooks->register('fsockopen.remote_socket', array(&$this, 'fsockopen_remote_socket'));
89 | $hooks->register('fsockopen.remote_host_path', array(&$this, 'fsockopen_remote_host_path'));
90 | if ($this->use_authentication) {
91 | $hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header'));
92 | }
93 | }
94 |
95 | /**
96 | * Set cURL parameters before the data is sent
97 | *
98 | * @since 1.6
99 | * @param resource $handle cURL resource
100 | */
101 | public function curl_before_send(&$handle) {
102 | curl_setopt($handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
103 | curl_setopt($handle, CURLOPT_PROXY, $this->proxy);
104 |
105 | if ($this->use_authentication) {
106 | curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
107 | curl_setopt($handle, CURLOPT_PROXYUSERPWD, $this->get_auth_string());
108 | }
109 | }
110 |
111 | /**
112 | * Alter remote socket information before opening socket connection
113 | *
114 | * @since 1.6
115 | * @param string $remote_socket Socket connection string
116 | */
117 | public function fsockopen_remote_socket(&$remote_socket) {
118 | $remote_socket = $this->proxy;
119 | }
120 |
121 | /**
122 | * Alter remote path before getting stream data
123 | *
124 | * @since 1.6
125 | * @param string $path Path to send in HTTP request string ("GET ...")
126 | * @param string $url Full URL we're requesting
127 | */
128 | public function fsockopen_remote_host_path(&$path, $url) {
129 | $path = $url;
130 | }
131 |
132 | /**
133 | * Add extra headers to the request before sending
134 | *
135 | * @since 1.6
136 | * @param string $out HTTP header string
137 | */
138 | public function fsockopen_header(&$out) {
139 | $out .= sprintf("Proxy-Authorization: Basic %s\r\n", base64_encode($this->get_auth_string()));
140 | }
141 |
142 | /**
143 | * Get the authentication string (user:pass)
144 | *
145 | * @since 1.6
146 | * @return string
147 | */
148 | public function get_auth_string() {
149 | return $this->user . ':' . $this->pass;
150 | }
151 | }
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Response.php:
--------------------------------------------------------------------------------
1 | headers = new Requests_Response_Headers();
21 | $this->cookies = new Requests_Cookie_Jar();
22 | }
23 |
24 | /**
25 | * Response body
26 | *
27 | * @var string
28 | */
29 | public $body = '';
30 |
31 | /**
32 | * Raw HTTP data from the transport
33 | *
34 | * @var string
35 | */
36 | public $raw = '';
37 |
38 | /**
39 | * Headers, as an associative array
40 | *
41 | * @var Requests_Response_Headers Array-like object representing headers
42 | */
43 | public $headers = array();
44 |
45 | /**
46 | * Status code, false if non-blocking
47 | *
48 | * @var integer|boolean
49 | */
50 | public $status_code = false;
51 |
52 | /**
53 | * Protocol version, false if non-blocking
54 | * @var float|boolean
55 | */
56 | public $protocol_version = false;
57 |
58 | /**
59 | * Whether the request succeeded or not
60 | *
61 | * @var boolean
62 | */
63 | public $success = false;
64 |
65 | /**
66 | * Number of redirects the request used
67 | *
68 | * @var integer
69 | */
70 | public $redirects = 0;
71 |
72 | /**
73 | * URL requested
74 | *
75 | * @var string
76 | */
77 | public $url = '';
78 |
79 | /**
80 | * Previous requests (from redirects)
81 | *
82 | * @var array Array of Requests_Response objects
83 | */
84 | public $history = array();
85 |
86 | /**
87 | * Cookies from the request
88 | *
89 | * @var Requests_Cookie_Jar Array-like object representing a cookie jar
90 | */
91 | public $cookies = array();
92 |
93 | /**
94 | * Is the response a redirect?
95 | *
96 | * @return boolean True if redirect (3xx status), false if not.
97 | */
98 | public function is_redirect() {
99 | $code = $this->status_code;
100 | return in_array($code, array(300, 301, 302, 303, 307)) || $code > 307 && $code < 400;
101 | }
102 |
103 | /**
104 | * Throws an exception if the request was not successful
105 | *
106 | * @throws Requests_Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`)
107 | * @throws Requests_Exception_HTTP On non-successful status code. Exception class corresponds to code (e.g. {@see Requests_Exception_HTTP_404})
108 | * @param boolean $allow_redirects Set to false to throw on a 3xx as well
109 | */
110 | public function throw_for_status($allow_redirects = true) {
111 | if ($this->is_redirect()) {
112 | if (!$allow_redirects) {
113 | throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this);
114 | }
115 | }
116 | elseif (!$this->success) {
117 | $exception = Requests_Exception_HTTP::get_class($this->status_code);
118 | throw new $exception(null, $this);
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Response/Headers.php:
--------------------------------------------------------------------------------
1 | data[$key])) {
29 | return null;
30 | }
31 |
32 | return $this->flatten($this->data[$key]);
33 | }
34 |
35 | /**
36 | * Set the given item
37 | *
38 | * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
39 | *
40 | * @param string $key Item name
41 | * @param string $value Item value
42 | */
43 | public function offsetSet($key, $value) {
44 | if ($key === null) {
45 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
46 | }
47 |
48 | $key = strtolower($key);
49 |
50 | if (!isset($this->data[$key])) {
51 | $this->data[$key] = array();
52 | }
53 |
54 | $this->data[$key][] = $value;
55 | }
56 |
57 | /**
58 | * Get all values for a given header
59 | *
60 | * @param string $key
61 | * @return array Header values
62 | */
63 | public function getValues($key) {
64 | $key = strtolower($key);
65 | if (!isset($this->data[$key])) {
66 | return null;
67 | }
68 |
69 | return $this->data[$key];
70 | }
71 |
72 | /**
73 | * Flattens a value into a string
74 | *
75 | * Converts an array into a string by imploding values with a comma, as per
76 | * RFC2616's rules for folding headers.
77 | *
78 | * @param string|array $value Value to flatten
79 | * @return string Flattened value
80 | */
81 | public function flatten($value) {
82 | if (is_array($value)) {
83 | $value = implode(',', $value);
84 | }
85 |
86 | return $value;
87 | }
88 |
89 | /**
90 | * Get an iterator for the data
91 | *
92 | * Converts the internal
93 | * @return ArrayIterator
94 | */
95 | public function getIterator() {
96 | return new Requests_Utility_FilteredIterator($this->data, array($this, 'flatten'));
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Transport.php:
--------------------------------------------------------------------------------
1 | $value) {
30 | $this->offsetSet($key, $value);
31 | }
32 | }
33 |
34 | /**
35 | * Check if the given item exists
36 | *
37 | * @param string $key Item key
38 | * @return boolean Does the item exist?
39 | */
40 | public function offsetExists($key) {
41 | $key = strtolower($key);
42 | return isset($this->data[$key]);
43 | }
44 |
45 | /**
46 | * Get the value for the item
47 | *
48 | * @param string $key Item key
49 | * @return string Item value
50 | */
51 | public function offsetGet($key) {
52 | $key = strtolower($key);
53 | if (!isset($this->data[$key])) {
54 | return null;
55 | }
56 |
57 | return $this->data[$key];
58 | }
59 |
60 | /**
61 | * Set the given item
62 | *
63 | * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
64 | *
65 | * @param string $key Item name
66 | * @param string $value Item value
67 | */
68 | public function offsetSet($key, $value) {
69 | if ($key === null) {
70 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
71 | }
72 |
73 | $key = strtolower($key);
74 | $this->data[$key] = $value;
75 | }
76 |
77 | /**
78 | * Unset the given header
79 | *
80 | * @param string $key
81 | */
82 | public function offsetUnset($key) {
83 | unset($this->data[strtolower($key)]);
84 | }
85 |
86 | /**
87 | * Get an iterator for the data
88 | *
89 | * @return ArrayIterator
90 | */
91 | public function getIterator() {
92 | return new ArrayIterator($this->data);
93 | }
94 |
95 | /**
96 | * Get the headers as an array
97 | *
98 | * @return array Header data
99 | */
100 | public function getAll() {
101 | return $this->data;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/require/Requests/Utility/FilteredIterator.php:
--------------------------------------------------------------------------------
1 | callback = $callback;
33 | }
34 |
35 | /**
36 | * Get the current item's value after filtering
37 | *
38 | * @return string
39 | */
40 | public function current() {
41 | $value = parent::current();
42 | $value = call_user_func($this->callback, $value);
43 | return $value;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/frontend/run_frontend.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | apt update
4 | apt install -y php php-fpm nginx
5 | systemctl restart php7.0-fpm.service
6 | systemctl restart nginx.service
7 | mkdir /var/www/frontend/
8 | cp frontend.conf /etc/nginx/conf.d/frontend.conf
9 | rm /etc/nginx/sites-available/default
10 | rm /etc/nginx/sites-enabled/default
11 | rm /etc/nginx/conf.d/default
12 | cp -a ./ /var/www/frontend/
13 | nginx -s reload
14 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/remote_exec.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | region = "us-east-1"
3 | }
4 |
5 | resource "aws_instance" "frontend" {
6 | availability_zone = "${var.us-east-zones[count.index]}"
7 | ami = "ami-66506c1c"
8 | instance_type = "t2.micro"
9 | key_name = "${var.key_name}"
10 | vpc_security_group_ids = ["${var.sg-id}"]
11 |
12 | lifecycle {
13 | create_before_destroy = true
14 | }
15 |
16 | connection {
17 | user = "ubuntu"
18 | type = "ssh"
19 | private_key = "${file(var.pvt_key)}"
20 | }
21 |
22 | provisioner "file" {
23 | source = "./frontend"
24 | destination = "~/"
25 | }
26 |
27 | provisioner "remote-exec" {
28 | inline = [
29 | "chmod +x ~/frontend/run_frontend.sh",
30 | "cd ~/frontend",
31 | "sudo ~/frontend/run_frontend.sh",
32 | ]
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/3h_Software_provisioning_Part_1/variables.tf:
--------------------------------------------------------------------------------
1 | variable "key_name" {
2 | default = "stefan-personal-aws"
3 | }
4 |
5 | variable "pvt_key" {
6 | default = "/home/stefan/.ssh/stefan-personal-aws.pem"
7 | }
8 |
9 | variable "us-east-zones" {
10 | default = ["us-east-1a", "us-east-1b"]
11 | }
12 |
13 | variable "sg-id" {
14 | default = "sg-4e1b7b39"
15 | }
16 |
--------------------------------------------------------------------------------
/3i_Software_provisioning_Part_2/ansible/group_vars/all.yml:
--------------------------------------------------------------------------------
1 | # tag_Name_server1.yml
2 | # --------------------
3 | #
4 | # Variables for EC2 instances
5 | # ---
6 | ansible_ssh_user: ubuntu
7 | ansible_ssh_private_key_file: "{{ sshKey }}"
8 | ansible_host_key_checking: false
9 |
--------------------------------------------------------------------------------
/3i_Software_provisioning_Part_2/ansible/pre-task.yml:
--------------------------------------------------------------------------------
1 | ---
2 | ###############################################################################
3 | # Ubuntu 16.04 require this
4 | ##############################################################################
5 | - hosts: all
6 | remote_user: root
7 | become: yes
8 | become_method: sudo
9 | gather_facts: no
10 | vars_prompt:
11 | - name: "sshKey"
12 | prompt: "Enter ssh key file path: (ignore if local)"
13 | default: "/home/st/.ssh/github-personal"
14 |
--------------------------------------------------------------------------------
/3i_Software_provisioning_Part_2/ansible/setup-backend.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | - hosts: all
3 | gather_facts: no
4 | become: yes
5 | become_method: sudo
6 | pre_tasks:
7 | - name: 'install python2'
8 | raw: sudo apt-get -y install python-simplejson
9 | tasks:
10 | - name: Running apt update
11 | apt: update_cache=yes
12 | - name: Installing required packages
13 | apt: name={{item}} state=present
14 | with_items:
15 | - git
16 | - python3-pip
17 | - python-psycopg2
18 |
19 | - name: pull branch master
20 | git:
21 | repo=https://github.com/cyantarek/django-ansible-test.git
22 | dest=/deploy/backend/
23 | accept_hostkey=yes
24 | - name: install python requirements
25 | pip: executable=pip3 requirements=/deploy/backend/requirements.txt
26 | - name: run server
27 | shell: python3 /deploy/backend/manage.py runserver 0.0.0.0:80 >/dev/null 2>&1 &
28 | async: 45
29 | poll: 0
30 |
31 |
--------------------------------------------------------------------------------
/3i_Software_provisioning_Part_2/backend/.idea/backend.iml:
--------------------------------------------------------------------------------
1 |
2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033243.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033244.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033246-1.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033246.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033247-1.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033247-2.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033247-3.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033247.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033248.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033256.200.json: -------------------------------------------------------------------------------- 1 | {"msg": "ok"} -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033934.200.json: -------------------------------------------------------------------------------- 1 | {"msg": "ok"} -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/http-requests-log.http: -------------------------------------------------------------------------------- 1 | GET http://localhost:8000/api/v1/response 2 | Accept:*/* 3 | Cache-Control:no-cache 4 | 5 | <> 2018-04-26T033934.200.json 6 | 7 | ### 8 | 9 | GET http://localhost:8000/api/v1/response 10 | Accept:*/* 11 | Cache-Control:no-cache 12 | 13 | <> 2018-04-26T033256.200.json 14 | 15 | ### 16 | 17 | GET http://localhost:8080/api/v1/response 18 | Accept:*/* 19 | Cache-Control:no-cache 20 | 21 | <> 2018-04-26T033248.404.txt 22 | 23 | ### 24 | 25 | GET http://localhost:8080/api/v1/response 26 | Accept:*/* 27 | Cache-Control:no-cache 28 | 29 | <> 2018-04-26T033247-3.404.txt 30 | 31 | ### 32 | 33 | GET http://localhost:8080/api/v1/response 34 | Accept:*/* 35 | Cache-Control:no-cache 36 | 37 | <> 2018-04-26T033247-2.404.txt 38 | 39 | ### 40 | 41 | GET http://localhost:8080/api/v1/response 42 | Accept:*/* 43 | Cache-Control:no-cache 44 | 45 | <> 2018-04-26T033247-1.404.txt 46 | 47 | ### 48 | 49 | GET http://localhost:8080/api/v1/response 50 | Accept:*/* 51 | Cache-Control:no-cache 52 | 53 | <> 2018-04-26T033247.404.txt 54 | 55 | ### 56 | 57 | GET http://localhost:8080/api/v1/response 58 | Accept:*/* 59 | Cache-Control:no-cache 60 | 61 | <> 2018-04-26T033246-1.404.txt 62 | 63 | ### 64 | 65 | GET http://localhost:8080/api/v1/response 66 | Accept:*/* 67 | Cache-Control:no-cache 68 | 69 | <> 2018-04-26T033246.404.txt 70 | 71 | ### 72 | 73 | GET http://localhost:8080/api/v1/response 74 | Accept:*/* 75 | Cache-Control:no-cache 76 | 77 | <> 2018-04-26T033244.404.txt 78 | 79 | ### 80 | 81 | GET http://localhost:8080/api/v1/response 82 | Accept:*/* 83 | Cache-Control:no-cache 84 | 85 | <> 2018-04-26T033243.404.txt 86 | 87 | ### 88 | 89 | GET http://localhost:8080/api/v1/response 90 | Accept:*/* 91 | Cache-Control:no-cache 92 | 93 | <> 2018-04-26T033228.404.txt 94 | 95 | ### 96 | 97 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033243.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033244.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033246-1.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033246.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033247-1.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033247-2.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033247-3.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033247.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033248.404.txt: -------------------------------------------------------------------------------- 1 | 2 |
Cannot open document for: /api/v1/response/6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033256.200.json: -------------------------------------------------------------------------------- 1 | {"msg": "ok"} -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033934.200.json: -------------------------------------------------------------------------------- 1 | {"msg": "ok"} -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/http-requests-log.http: -------------------------------------------------------------------------------- 1 | GET http://localhost:8000/api/v1/response 2 | Accept:*/* 3 | Cache-Control:no-cache 4 | 5 | <> 2018-04-26T033934.200.json 6 | 7 | ### 8 | 9 | GET http://localhost:8000/api/v1/response 10 | Accept:*/* 11 | Cache-Control:no-cache 12 | 13 | <> 2018-04-26T033256.200.json 14 | 15 | ### 16 | 17 | GET http://localhost:8080/api/v1/response 18 | Accept:*/* 19 | Cache-Control:no-cache 20 | 21 | <> 2018-04-26T033248.404.txt 22 | 23 | ### 24 | 25 | GET http://localhost:8080/api/v1/response 26 | Accept:*/* 27 | Cache-Control:no-cache 28 | 29 | <> 2018-04-26T033247-3.404.txt 30 | 31 | ### 32 | 33 | GET http://localhost:8080/api/v1/response 34 | Accept:*/* 35 | Cache-Control:no-cache 36 | 37 | <> 2018-04-26T033247-2.404.txt 38 | 39 | ### 40 | 41 | GET http://localhost:8080/api/v1/response 42 | Accept:*/* 43 | Cache-Control:no-cache 44 | 45 | <> 2018-04-26T033247-1.404.txt 46 | 47 | ### 48 | 49 | GET http://localhost:8080/api/v1/response 50 | Accept:*/* 51 | Cache-Control:no-cache 52 | 53 | <> 2018-04-26T033247.404.txt 54 | 55 | ### 56 | 57 | GET http://localhost:8080/api/v1/response 58 | Accept:*/* 59 | Cache-Control:no-cache 60 | 61 | <> 2018-04-26T033246-1.404.txt 62 | 63 | ### 64 | 65 | GET http://localhost:8080/api/v1/response 66 | Accept:*/* 67 | Cache-Control:no-cache 68 | 69 | <> 2018-04-26T033246.404.txt 70 | 71 | ### 72 | 73 | GET http://localhost:8080/api/v1/response 74 | Accept:*/* 75 | Cache-Control:no-cache 76 | 77 | <> 2018-04-26T033244.404.txt 78 | 79 | ### 80 | 81 | GET http://localhost:8080/api/v1/response 82 | Accept:*/* 83 | Cache-Control:no-cache 84 | 85 | <> 2018-04-26T033243.404.txt 86 | 87 | ### 88 | 89 | GET http://localhost:8080/api/v1/response 90 | Accept:*/* 91 | Cache-Control:no-cache 92 | 93 | <> 2018-04-26T033228.404.txt 94 | 95 | ### 96 | 97 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 |