├── .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 | 3 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | 31 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/httpRequests/2018-04-26T033228.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__init__.py -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/settings.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/settings.cpython-35.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/settings.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/settings.cpython-36.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/urls.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/urls.cpython-35.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/views.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/views.cpython-35.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/views.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/views.cpython-36.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/wsgi.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/wsgi.cpython-35.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/__pycache__/wsgi.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/backend/__pycache__/wsgi.cpython-36.pyc -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for backend project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.0.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '1h48x%=9@arthj@&ab^r@5%5@q#j1oh*vm$@%01mzjby!soa2q' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = ['*'] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | ] 41 | 42 | MIDDLEWARE = [ 43 | 'django.middleware.security.SecurityMiddleware', 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.messages.middleware.MessageMiddleware', 49 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 50 | ] 51 | 52 | ROOT_URLCONF = 'backend.urls' 53 | 54 | TEMPLATES = [ 55 | { 56 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 57 | 'DIRS': [os.path.join(BASE_DIR, 'templates')] 58 | , 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'backend.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/2.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/2.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/2.0/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/urls.py: -------------------------------------------------------------------------------- 1 | """backend URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | from . import views 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('api/v1/response/', views.api_view), 23 | ] 24 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/views.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse, HttpResponse 2 | 3 | 4 | def api_view(request): 5 | 6 | msg = request.GET["msg"] 7 | 8 | return HttpResponse("Hello, you sent me: " + msg) -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/backend/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for backend project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3i_Software_provisioning_Part_2/backend/db.sqlite3 -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/backend/requirements.txt: -------------------------------------------------------------------------------- 1 | Django -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/local_exec.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | resource "aws_instance" "backend" { 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 | # force Terraform to wait until a connection can be made, so that Ansible doesn't fail when trying to provision 13 | provisioner "remote-exec" { 14 | # The connection will use the local SSH agent for authentication 15 | inline = ["echo Successfully connected"] 16 | 17 | connection { 18 | user = "ubuntu" 19 | type = "ssh" 20 | private_key = "${file(var.pvt_key)}" 21 | } 22 | } 23 | } 24 | 25 | #resource "null_resource" "ansible-pre-tasks" { 26 | # provisioner "local-exec" { 27 | # command = "ansible-playbook -e ssh-key=${var.pvt_key} -i '${aws_instance.backend.public_ip},' ./ansible/pre-task.yml -v" 28 | # } 29 | # 30 | # depends_on = ["aws_instance.backend"] 31 | #} 32 | 33 | resource "null_resource" "ansible-main" { 34 | provisioner "local-exec" { 35 | command = "ansible-playbook -e sshKey=${var.pvt_key} -i '${aws_instance.backend.public_ip},' ./ansible/setup-backend.yaml -v" 36 | } 37 | 38 | depends_on = ["aws_instance.backend"] 39 | } 40 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/php-fpm.yml: -------------------------------------------------------------------------------- 1 | 2 | --- 3 | - hosts: all 4 | remote_user: root 5 | become: yes 6 | become_method: sudo 7 | vars_prompt: 8 | - name: "sshKey" 9 | prompt: "Enter ssh key file path: (ignore if local)" 10 | default: "/home/st/.ssh/caylent-staging-master" 11 | - name: "version" 12 | prompt: "Enter please enter php version:" 13 | default: "7.0" 14 | - name: updateRepo 15 | prompt: "Would you like to update apt repo?" 16 | default: "no" 17 | tasks: 18 | - name: update repo when add 19 | apt: 20 | update_cache: yes 21 | when: updateRepo == "yes" 22 | 23 | - name: "install php base" 24 | apt: 25 | name: "php{{ version }}" 26 | state: present 27 | install_recommends: yes 28 | allow_unauthenticated: yes 29 | - name: "install php-fpm base" 30 | apt: 31 | name: "php{{ version }}-fpm" 32 | state: present 33 | install_recommends: yes 34 | allow_unauthenticated: yes 35 | - name: "install php common" 36 | apt: 37 | name: "php{{ version }}-common" 38 | state: present 39 | install_recommends: yes 40 | allow_unauthenticated: yes 41 | - name: "install php curl" 42 | apt: 43 | name: "php{{ version }}-curl" 44 | state: present 45 | install_recommends: yes 46 | allow_unauthenticated: yes 47 | - name: "install php mbstring" 48 | apt: 49 | name: "php{{ version }}-mbstring" 50 | state: present 51 | install_recommends: yes 52 | allow_unauthenticated: yes 53 | - name: "install php mysql" 54 | apt: 55 | name: "php{{ version }}-mysql" 56 | state: present 57 | install_recommends: yes 58 | allow_unauthenticated: yes 59 | - name: "install php dev" 60 | apt: 61 | name: "php{{ version }}-dev" 62 | state: present 63 | install_recommends: yes 64 | allow_unauthenticated: yes 65 | 66 | 67 | - name: "update php-fpm" 68 | copy: 69 | src: Templates/php-fpm.conf 70 | dest: /etc/php/7.0/fpm 71 | mode: 0644 72 | owner: "root" 73 | group: "root" 74 | force: yes 75 | 76 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/scripts/ansible-install-ubuntu.sh: -------------------------------------------------------------------------------- 1 | apt-get update 2 | apt-get install software-properties-common 3 | apt-add-repository ppa:ansible/ansible 4 | apt-get update 5 | apt-get install ansible 6 | -------------------------------------------------------------------------------- /3i_Software_provisioning_Part_2/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 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/ansible/hosts: -------------------------------------------------------------------------------- 1 | [backend] 2 | 3 | 4 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/ansible/pre-task.retry: -------------------------------------------------------------------------------- 1 | 34.235.169.107 2 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/ansible/setup-backend.retry: -------------------------------------------------------------------------------- 1 | 34.235.169.107 2 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/backend.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | 31 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033228.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033243.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033244.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033246-1.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033246.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033247-1.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033247-2.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033247-3.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033247.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
Cannot open document for: /api/v1/response/
6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/httpRequests/2018-04-26T033248.404.txt: -------------------------------------------------------------------------------- 1 | 2 | Not Found 3 | 4 |

Access Error: 404 -- Not Found

5 |
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 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__init__.py -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/settings.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/settings.cpython-35.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/settings.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/settings.cpython-36.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/urls.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/urls.cpython-35.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/views.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/views.cpython-35.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/views.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/views.cpython-36.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/wsgi.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/wsgi.cpython-35.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/__pycache__/wsgi.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/backend/__pycache__/wsgi.cpython-36.pyc -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for backend project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.0.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '1h48x%=9@arthj@&ab^r@5%5@q#j1oh*vm$@%01mzjby!soa2q' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = ['*'] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | ] 41 | 42 | MIDDLEWARE = [ 43 | 'django.middleware.security.SecurityMiddleware', 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.messages.middleware.MessageMiddleware', 49 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 50 | ] 51 | 52 | ROOT_URLCONF = 'backend.urls' 53 | 54 | TEMPLATES = [ 55 | { 56 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 57 | 'DIRS': [os.path.join(BASE_DIR, 'templates')] 58 | , 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'backend.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/2.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/2.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/2.0/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/urls.py: -------------------------------------------------------------------------------- 1 | """backend URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | from . import views 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('api/v1/response/', views.api_view), 23 | ] 24 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/views.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse, HttpResponse 2 | 3 | 4 | def api_view(request): 5 | 6 | msg = request.GET["msg"] 7 | 8 | return HttpResponse("Hello, you sent me: " + msg) -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/backend/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for backend project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LevelUpEducation/terraform-tutorial/9fb6a305e073292fd6cc53c54112f11544e46177/3j_Exercise/Backend/backend/db.sqlite3 -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/backend/requirements.txt: -------------------------------------------------------------------------------- 1 | Django -------------------------------------------------------------------------------- /3j_Exercise/Backend/main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "${var.region}" 3 | } 4 | 5 | data "aws_availability_zones" "this" {} 6 | 7 | resource "aws_instance" "backend" { 8 | count = "${var.number_instances}" 9 | availability_zone = "${data.aws_availability_zones.this.names[count.index]}" 10 | ami = "ami-66506c1c" 11 | instance_type = "t2.micro" 12 | key_name = "${var.key_name}" 13 | vpc_security_group_ids = ["${var.sg-id}"] 14 | 15 | # force Terraform to wait until a connection can be made, so that Ansible doesn't fail when trying to provision 16 | provisioner "remote-exec" { 17 | # The connection will use the local SSH agent for authentication 18 | inline = ["echo Successfully connected"] 19 | 20 | connection { 21 | user = "ubuntu" 22 | type = "ssh" 23 | private_key = "${file(var.pvt_key)}" 24 | } 25 | } 26 | } 27 | 28 | #resource "null_resource" "ansible-pre-tasks" { 29 | # provisioner "local-exec" { 30 | # command = "ansible-playbook -e ssh-key=${var.pvt_key} -i '${aws_instance.backend.public_ip},' ./ansible/pre-task.yml -v" 31 | # } 32 | # 33 | # depends_on = ["aws_instance.backend"] 34 | #} 35 | 36 | resource "null_resource" "ansible-main" { 37 | provisioner "local-exec" { 38 | command = "ansible-playbook -e sshKey=${var.pvt_key} -i '${aws_instance.backend.public_ip},' ./ansible/setup-backend.yaml -v" 39 | } 40 | 41 | depends_on = ["aws_instance.backend"] 42 | } 43 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/php-fpm.yml: -------------------------------------------------------------------------------- 1 | 2 | --- 3 | - hosts: all 4 | remote_user: root 5 | become: yes 6 | become_method: sudo 7 | vars_prompt: 8 | - name: "sshKey" 9 | prompt: "Enter ssh key file path: (ignore if local)" 10 | default: "/home/st/.ssh/caylent-staging-master" 11 | - name: "version" 12 | prompt: "Enter please enter php version:" 13 | default: "7.0" 14 | - name: updateRepo 15 | prompt: "Would you like to update apt repo?" 16 | default: "no" 17 | tasks: 18 | - name: update repo when add 19 | apt: 20 | update_cache: yes 21 | when: updateRepo == "yes" 22 | 23 | - name: "install php base" 24 | apt: 25 | name: "php{{ version }}" 26 | state: present 27 | install_recommends: yes 28 | allow_unauthenticated: yes 29 | - name: "install php-fpm base" 30 | apt: 31 | name: "php{{ version }}-fpm" 32 | state: present 33 | install_recommends: yes 34 | allow_unauthenticated: yes 35 | - name: "install php common" 36 | apt: 37 | name: "php{{ version }}-common" 38 | state: present 39 | install_recommends: yes 40 | allow_unauthenticated: yes 41 | - name: "install php curl" 42 | apt: 43 | name: "php{{ version }}-curl" 44 | state: present 45 | install_recommends: yes 46 | allow_unauthenticated: yes 47 | - name: "install php mbstring" 48 | apt: 49 | name: "php{{ version }}-mbstring" 50 | state: present 51 | install_recommends: yes 52 | allow_unauthenticated: yes 53 | - name: "install php mysql" 54 | apt: 55 | name: "php{{ version }}-mysql" 56 | state: present 57 | install_recommends: yes 58 | allow_unauthenticated: yes 59 | - name: "install php dev" 60 | apt: 61 | name: "php{{ version }}-dev" 62 | state: present 63 | install_recommends: yes 64 | allow_unauthenticated: yes 65 | 66 | 67 | - name: "update php-fpm" 68 | copy: 69 | src: Templates/php-fpm.conf 70 | dest: /etc/php/7.0/fpm 71 | mode: 0644 72 | owner: "root" 73 | group: "root" 74 | force: yes 75 | 76 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/scripts/ansible-install-ubuntu.sh: -------------------------------------------------------------------------------- 1 | apt-get update 2 | apt-get install software-properties-common 3 | apt-add-repository ppa:ansible/ansible 4 | apt-get update 5 | apt-get install ansible 6 | -------------------------------------------------------------------------------- /3j_Exercise/Backend/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 | 17 | variable "number_instances" { 18 | default = "1" 19 | } 20 | 21 | variable "region" { 22 | default = "us-east-1" 23 | } 24 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | } -------------------------------------------------------------------------------- /3j_Exercise/Frontend/frontend/require/Requests/Cookie/Jar.php: -------------------------------------------------------------------------------- 1 | cookies = $cookies; 30 | } 31 | 32 | /** 33 | * Normalise cookie data into a Requests_Cookie 34 | * 35 | * @param string|Requests_Cookie $cookie 36 | * @return Requests_Cookie 37 | */ 38 | public function normalize_cookie($cookie, $key = null) { 39 | if ($cookie instanceof Requests_Cookie) { 40 | return $cookie; 41 | } 42 | 43 | return Requests_Cookie::parse($cookie, $key); 44 | } 45 | 46 | /** 47 | * Normalise cookie data into a Requests_Cookie 48 | * 49 | * @codeCoverageIgnore 50 | * @deprecated Use {@see Requests_Cookie_Jar::normalize_cookie} 51 | * @return Requests_Cookie 52 | */ 53 | public function normalizeCookie($cookie, $key = null) { 54 | return $this->normalize_cookie($cookie, $key); 55 | } 56 | 57 | /** 58 | * Check if the given item exists 59 | * 60 | * @param string $key Item key 61 | * @return boolean Does the item exist? 62 | */ 63 | public function offsetExists($key) { 64 | return isset($this->cookies[$key]); 65 | } 66 | 67 | /** 68 | * Get the value for the item 69 | * 70 | * @param string $key Item key 71 | * @return string Item value 72 | */ 73 | public function offsetGet($key) { 74 | if (!isset($this->cookies[$key])) { 75 | return null; 76 | } 77 | 78 | return $this->cookies[$key]; 79 | } 80 | 81 | /** 82 | * Set the given item 83 | * 84 | * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`) 85 | * 86 | * @param string $key Item name 87 | * @param string $value Item value 88 | */ 89 | public function offsetSet($key, $value) { 90 | if ($key === null) { 91 | throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); 92 | } 93 | 94 | $this->cookies[$key] = $value; 95 | } 96 | 97 | /** 98 | * Unset the given header 99 | * 100 | * @param string $key 101 | */ 102 | public function offsetUnset($key) { 103 | unset($this->cookies[$key]); 104 | } 105 | 106 | /** 107 | * Get an iterator for the data 108 | * 109 | * @return ArrayIterator 110 | */ 111 | public function getIterator() { 112 | return new ArrayIterator($this->cookies); 113 | } 114 | 115 | /** 116 | * Register the cookie handler with the request's hooking system 117 | * 118 | * @param Requests_Hooker $hooks Hooking system 119 | */ 120 | public function register(Requests_Hooker $hooks) { 121 | $hooks->register('requests.before_request', array($this, 'before_request')); 122 | $hooks->register('requests.before_redirect_check', array($this, 'before_redirect_check')); 123 | } 124 | 125 | /** 126 | * Add Cookie header to a request if we have any 127 | * 128 | * As per RFC 6265, cookies are separated by '; ' 129 | * 130 | * @param string $url 131 | * @param array $headers 132 | * @param array $data 133 | * @param string $type 134 | * @param array $options 135 | */ 136 | public function before_request($url, &$headers, &$data, &$type, &$options) { 137 | if (!$url instanceof Requests_IRI) { 138 | $url = new Requests_IRI($url); 139 | } 140 | 141 | if (!empty($this->cookies)) { 142 | $cookies = array(); 143 | foreach ($this->cookies as $key => $cookie) { 144 | $cookie = $this->normalize_cookie($cookie, $key); 145 | 146 | // Skip expired cookies 147 | if ($cookie->is_expired()) { 148 | continue; 149 | } 150 | 151 | if ($cookie->domain_matches($url->host)) { 152 | $cookies[] = $cookie->format_for_header(); 153 | } 154 | } 155 | 156 | $headers['Cookie'] = implode('; ', $cookies); 157 | } 158 | } 159 | 160 | /** 161 | * Parse all cookies from a response and attach them to the response 162 | * 163 | * @var Requests_Response $response 164 | */ 165 | public function before_redirect_check(Requests_Response &$return) { 166 | $url = $return->url; 167 | if (!$url instanceof Requests_IRI) { 168 | $url = new Requests_IRI($url); 169 | } 170 | 171 | $cookies = Requests_Cookie::parse_from_headers($return->headers, $url); 172 | $this->cookies = array_merge($this->cookies, $cookies); 173 | $return->cookies = $this; 174 | } 175 | } -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | } -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | } -------------------------------------------------------------------------------- /3j_Exercise/Frontend/frontend/require/Requests/Exception/HTTP/304.php: -------------------------------------------------------------------------------- 1 | code = $data->status_code; 40 | } 41 | 42 | parent::__construct($reason, $data); 43 | } 44 | } -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | } -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | } -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | } -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "${var.region}" 3 | } 4 | 5 | data "aws_availability_zones" "this" {} 6 | 7 | resource "aws_instance" "frontend" { 8 | count = "${var.number_instances}" 9 | availability_zone = "${data.aws_availability_zones.this.names[count.index]}" 10 | ami = "ami-66506c1c" 11 | instance_type = "t2.micro" 12 | key_name = "${var.key_name}" 13 | vpc_security_group_ids = ["${var.sg-id}"] 14 | 15 | lifecycle { 16 | create_before_destroy = true 17 | } 18 | 19 | connection { 20 | user = "ubuntu" 21 | type = "ssh" 22 | private_key = "${file(var.pvt_key)}" 23 | } 24 | 25 | provisioner "file" { 26 | source = "./frontend" 27 | destination = "~/" 28 | } 29 | 30 | provisioner "remote-exec" { 31 | inline = [ 32 | "chmod +x ~/frontend/run_frontend.sh", 33 | "cd ~/frontend", 34 | "sudo ~/frontend/run_frontend.sh", 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /3j_Exercise/Frontend/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 | 17 | variable "number_instances" { 18 | default = "1" 19 | } 20 | 21 | variable "region" { 22 | default = "us-east-1" 23 | } 24 | -------------------------------------------------------------------------------- /3j_Exercise/example.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 | locals { 10 | regions = { 11 | staging = "us-west-1" 12 | production = "us-east-1" 13 | } 14 | 15 | instance_count = { 16 | staging = "1" 17 | production = "2" 18 | } 19 | } 20 | 21 | module "backend" { 22 | source = "./Backend" 23 | region = "${local.regions[terraform.workspace]}" 24 | number_instances = "${local.instance_count[terraform.workspace]}" 25 | } 26 | 27 | module "frontend" { 28 | source = "./Frontend" 29 | region = "${local.regions[terraform.workspace]}" 30 | number_instances = "${local.instance_count[terraform.workspace]}" 31 | } 32 | -------------------------------------------------------------------------------- /4b_Vpcs/vpc.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "eu-west-1" 3 | } 4 | 5 | module "vpc" { 6 | source = "terraform-aws-modules/vpc/aws" 7 | 8 | name = "complete-example" 9 | 10 | cidr = "10.10.0.0/16" 11 | 12 | azs = ["eu-west-1b", "eu-west-1c"] 13 | public_subnets = ["10.10.1.0/24", "10.10.2.0/24"] 14 | private_subnets = ["10.10.3.0/24", "10.10.4.0/24"] 15 | 16 | enable_nat_gateway = true 17 | 18 | tags = { 19 | Owner = "user" 20 | Environment = "terraform.workspace" 21 | Name = "teffaform vpc" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /4c_EBS/ebs.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | resource "aws_volume_attachment" "ebs_att" { 6 | device_name = "/dev/sdh" 7 | volume_id = "${aws_ebs_volume.example.id}" 8 | instance_id = "${aws_instance.web.id}" 9 | } 10 | 11 | resource "aws_instance" "web" { 12 | ami = "ami-21f78e11" 13 | availability_zone = "us-west-2a" 14 | instance_type = "t1.micro" 15 | 16 | tags { 17 | Name = "HelloWorld" 18 | } 19 | } 20 | 21 | resource "aws_ebs_volume" "example" { 22 | availability_zone = "us-west-2a" 23 | size = 100 24 | } 25 | -------------------------------------------------------------------------------- /4d_IAM/main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | resource "aws_iam_user" "user" { 6 | name = "stefan-tf-demo" 7 | path = "${var.path}" 8 | force_destroy = "${var.force_destroy}" 9 | } 10 | 11 | resource "aws_iam_group_membership" "team" { 12 | name = "tf-testing-group-membership" 13 | 14 | users = [ 15 | "${aws_iam_user.user.name}", 16 | ] 17 | 18 | group = "${aws_iam_group.group.name}" 19 | } 20 | 21 | resource "aws_iam_group" "group" { 22 | name = "test-group" 23 | } 24 | 25 | resource "aws_iam_group_policy" "policy" { 26 | name = "policy" 27 | group = "${aws_iam_group.group.id}" 28 | 29 | policy = <