├── .gitignore ├── README.md └── src ├── 1_Terraform_Fundamentals ├── .terraform.lock.hcl ├── main.tf ├── outputs.tf ├── providers.tf ├── terraform.tfvars ├── variables.tf └── vpc.tf ├── 2_Terraform_Modules ├── .terraform.lock.hcl ├── locals.tf ├── main.tf ├── modules │ ├── db │ │ ├── db.tf │ │ └── variables.tf │ ├── vpc │ │ ├── outputs.tf │ │ ├── variables.tf │ │ └── vpc.tf │ └── webserver │ │ ├── locals.tf │ │ ├── outputs.tf │ │ ├── variables.tf │ │ └── webserver.tf ├── outputs.tf ├── providers.tf ├── terraform.tfvars └── variables.tf ├── 3_Terraform_State ├── locals.tf ├── main.tf ├── modules │ ├── db │ │ ├── db.tf │ │ └── variables.tf │ ├── tf-state │ │ ├── tf-state.tf │ │ └── variables.tf │ ├── vpc │ │ ├── outputs.tf │ │ ├── variables.tf │ │ └── vpc.tf │ └── webserver │ │ ├── locals.tf │ │ ├── outputs.tf │ │ ├── variables.tf │ │ └── webserver.tf ├── outputs.tf ├── providers.tf ├── terraform.tfvars └── variables.tf ├── 4_HashiCorp_Vault ├── data.tf ├── ec2.tf ├── main.tf ├── outputs.tf └── providers.tf ├── 5_Terraform_ECR_ECS ├── App │ ├── Dockerfile │ └── src │ │ ├── package-lock.json │ │ ├── package.json │ │ └── server.js ├── locals.tf ├── main.tf ├── modules │ ├── ecr │ │ ├── ecr.tf │ │ ├── outputs.tf │ │ └── variables.tf │ ├── ecs │ │ ├── data.tf │ │ ├── ecs.tf │ │ └── variables.tf │ └── tf-state │ │ ├── tf-state.tf │ │ └── variables.tf └── providers.tf ├── 6_Terraform_and_CloudFormation ├── cft │ ├── params │ │ └── params.json │ └── template.yaml └── tf │ ├── locals.tf │ ├── main.tf │ ├── modules │ ├── cft-bucket │ │ ├── cft-bucket.tf │ │ ├── outputs.tf │ │ └── variables.tf │ ├── cft-stack │ │ ├── ctf-stack.tf │ │ └── variables.tf │ ├── cft-template │ │ ├── cft-template.tf │ │ ├── outputs.tf │ │ └── variables.tf │ └── tf-state │ │ ├── tf-state.tf │ │ └── variables.tf │ ├── providers.tf │ ├── terraform.tfvars │ └── variables.tf ├── 7_Terraform_AWS_Lambda_with_Layers ├── chromedriver │ ├── chromedriver │ └── headless-chromium ├── locals.tf ├── main.tf ├── modules │ ├── chromedriver_layer │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── variables.tf │ ├── iam │ │ ├── lambda-assume-role-policy.json │ │ ├── lambda-iam-policy.json │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── variables.tf │ ├── lambda │ │ ├── main.tf │ │ └── variables.tf │ └── selenium_layer │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── variables.tf ├── providers.tf ├── selenium │ └── python │ │ └── lib │ │ └── python3.7 │ │ └── site-packages │ │ ├── selenium-3.8.0.dist-info │ │ ├── DESCRIPTION.rst │ │ ├── INSTALLER │ │ ├── METADATA │ │ ├── RECORD │ │ ├── REQUESTED │ │ ├── WHEEL │ │ ├── metadata.json │ │ └── top_level.txt │ │ └── selenium │ │ ├── __init__.py │ │ ├── common │ │ ├── __init__.py │ │ └── exceptions.py │ │ └── webdriver │ │ ├── __init__.py │ │ ├── android │ │ ├── __init__.py │ │ └── webdriver.py │ │ ├── blackberry │ │ ├── __init__.py │ │ └── webdriver.py │ │ ├── chrome │ │ ├── __init__.py │ │ ├── options.py │ │ ├── remote_connection.py │ │ ├── service.py │ │ └── webdriver.py │ │ ├── common │ │ ├── __init__.py │ │ ├── action_chains.py │ │ ├── actions │ │ │ ├── __init__.py │ │ │ ├── action_builder.py │ │ │ ├── input_device.py │ │ │ ├── interaction.py │ │ │ ├── key_actions.py │ │ │ ├── key_input.py │ │ │ ├── mouse_button.py │ │ │ ├── pointer_actions.py │ │ │ └── pointer_input.py │ │ ├── alert.py │ │ ├── by.py │ │ ├── desired_capabilities.py │ │ ├── html5 │ │ │ ├── __init__.py │ │ │ └── application_cache.py │ │ ├── keys.py │ │ ├── proxy.py │ │ ├── service.py │ │ ├── touch_actions.py │ │ └── utils.py │ │ ├── edge │ │ ├── __init__.py │ │ ├── options.py │ │ ├── service.py │ │ └── webdriver.py │ │ ├── firefox │ │ ├── __init__.py │ │ ├── amd64 │ │ │ └── x_ignore_nofocus.so │ │ ├── extension_connection.py │ │ ├── firefox_binary.py │ │ ├── firefox_profile.py │ │ ├── options.py │ │ ├── remote_connection.py │ │ ├── service.py │ │ ├── webdriver.py │ │ ├── webdriver.xpi │ │ ├── webdriver_prefs.json │ │ ├── webelement.py │ │ └── x86 │ │ │ └── x_ignore_nofocus.so │ │ ├── ie │ │ ├── __init__.py │ │ ├── options.py │ │ ├── service.py │ │ └── webdriver.py │ │ ├── opera │ │ ├── __init__.py │ │ ├── options.py │ │ └── webdriver.py │ │ ├── phantomjs │ │ ├── __init__.py │ │ ├── service.py │ │ └── webdriver.py │ │ ├── remote │ │ ├── __init__.py │ │ ├── command.py │ │ ├── errorhandler.py │ │ ├── file_detector.py │ │ ├── getAttribute.js │ │ ├── isDisplayed.js │ │ ├── mobile.py │ │ ├── remote_connection.py │ │ ├── switch_to.py │ │ ├── utils.py │ │ ├── webdriver.py │ │ └── webelement.py │ │ ├── safari │ │ ├── __init__.py │ │ ├── service.py │ │ └── webdriver.py │ │ ├── support │ │ ├── __init__.py │ │ ├── abstract_event_listener.py │ │ ├── color.py │ │ ├── event_firing_webdriver.py │ │ ├── events.py │ │ ├── expected_conditions.py │ │ ├── select.py │ │ ├── ui.py │ │ └── wait.py │ │ └── webkitgtk │ │ ├── __init__.py │ │ ├── options.py │ │ ├── service.py │ │ └── webdriver.py └── src │ ├── demo_v1.py │ ├── demo_v2.py │ └── scrape.py ├── 8_Terraform_Jenkins_Server_with_TF ├── locals.tf ├── main.tf ├── modules │ ├── iam │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── variables.tf │ ├── server │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── variables.tf │ ├── ssh_connection │ │ ├── main.tf │ │ └── vriables.tf │ ├── tf-state │ │ ├── main.tf │ │ └── variables.tf │ └── vpc │ │ ├── main.tf │ │ ├── outputs.tf │ │ └── variables.tf ├── providers.tf └── scripts │ └── script.sh └── 9_Terraform_AWS_Provision_and_mount_EFS ├── locals.tf ├── main.tf └── modules ├── efs ├── efs.tf ├── main.tf ├── outputs.tf └── variables.tf ├── tf-state ├── main.tf ├── tf-state.tf └── varaibles.tf └── webserver ├── locals.tf ├── main.tf ├── outputs.tf ├── user_data.tfpl ├── variables.tf └── webserver.tf /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | 3 | # Local .terraform directories 4 | **/.terraform/* 5 | 6 | # .tfstate files 7 | *.tfstate 8 | *.tfstate.* 9 | 10 | # Crash log files 11 | crash.log 12 | 13 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 14 | # .tfvars files are managed as part of configuration and so should be included in 15 | # version control. 16 | # 17 | # example.tfvars 18 | 19 | # Ignore override files as they are usually used to override resources locally and so 20 | # are not checked in 21 | override.tf 22 | override.tf.json 23 | *_override.tf 24 | *_override.tf.json 25 | 26 | # Include override files you do wish to add to version control using negated pattern 27 | # 28 | # !example_override.tf 29 | 30 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 31 | # example: *tfplan* 32 | 33 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IaC_on_AWS_with_Terraform 2 | Code for the Terraform Playlist [videos](https://www.youtube.com/watch?v=FOs5FF9wLmU&list=PLRBkbp6t5gM2Lfbp2l-GGUM-jV7uOePlJ) 3 | -------------------------------------------------------------------------------- /src/1_Terraform_Fundamentals/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "4.52.0" 6 | constraints = "~> 4.0" 7 | hashes = [ 8 | "h1:pTH20eNlkwO3vxYb3f/Dm9QXjhVeidpvrn5YcvydM7Y=", 9 | "zh:00c865de3a0e7643f4e2e5c8d4ba91eee94a46d41090eb134baca6b58c107172", 10 | "zh:1430682e26eba25d8ace19fa780361187f474153e455545235b4fe30637fdcc2", 11 | "zh:1b9a4e5c889bd2022bd59fb924dc78e189f1b7a4fd718fcacda0f0a4cb74d6eb", 12 | "zh:2485260141608f1d386d0f68934092bbf68a27d96f0d83c73222d0382aee02f5", 13 | "zh:2fe67ee94e2df7dabee7e474356f8e907e7c8011533f9d71df8702d59f9060b2", 14 | "zh:37babd1b7ff96ff1f42aa56d7575cacabda6f9f460ff651d70662bfd90076341", 15 | "zh:54aa8d39f22ecab6613169f49d37d2ccfaf417e59dd7a8c8fc6bf92600c3384f", 16 | "zh:5bf4a84b962a8d2da8f4ccf2a7de56fb6c7a1f566e8393b563977fc7872a8740", 17 | "zh:8cb4a51f209a3cc497e53f09188c15c6675697587fe2ea14a6c7fff10c8c8476", 18 | "zh:91f6bdcbb1e36471140982e9048b7ced437d3290b2cc21079e5429cc84fed2fd", 19 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 20 | "zh:9f8c01c3f677bc64ddefa41e59c6fc98860c11875d7f148af55969d3e3847f77", 21 | "zh:b6b4fc0bd6f3c0adcd9531da3ccf8c25787ccd6ccc568f13ebbff1336d71a9e1", 22 | "zh:d52a428bd92cc319088685ecac63b9f7d12d4cd6725604edb20d0c4f37a9936e", 23 | "zh:e20252a851a0d38548a3c01a006bfc59ee1fc84217bf9eb95b22724769601b2b", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/1_Terraform_Fundamentals/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.3" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = "~> 4.0" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/1_Terraform_Fundamentals/outputs.tf: -------------------------------------------------------------------------------- 1 | output "vpc_id" { 2 | value = aws_vpc.ccVPC.id 3 | } -------------------------------------------------------------------------------- /src/1_Terraform_Fundamentals/providers.tf: -------------------------------------------------------------------------------- 1 | # Configure the AWS Provider 2 | provider "aws" { 3 | region = "us-east-1" 4 | } -------------------------------------------------------------------------------- /src/1_Terraform_Fundamentals/terraform.tfvars: -------------------------------------------------------------------------------- 1 | vpc_cidr = "10.0.0.0/16" 2 | vpc_tags = { 3 | Name = "ccVPC", 4 | Project = "CC TF Demo" 5 | } -------------------------------------------------------------------------------- /src/1_Terraform_Fundamentals/variables.tf: -------------------------------------------------------------------------------- 1 | variable "vpc_cidr" { 2 | description = "CIDR for VPC" 3 | type = string 4 | } 5 | 6 | variable "vpc_tags" { 7 | description = "Tags for VPC" 8 | type = map(any) 9 | } -------------------------------------------------------------------------------- /src/1_Terraform_Fundamentals/vpc.tf: -------------------------------------------------------------------------------- 1 | # Create a VPC 2 | resource "aws_vpc" "ccVPC" { 3 | cidr_block = var.vpc_cidr 4 | tags = var.vpc_tags 5 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "4.52.0" 6 | constraints = "~> 4.0" 7 | hashes = [ 8 | "h1:pTH20eNlkwO3vxYb3f/Dm9QXjhVeidpvrn5YcvydM7Y=", 9 | "zh:00c865de3a0e7643f4e2e5c8d4ba91eee94a46d41090eb134baca6b58c107172", 10 | "zh:1430682e26eba25d8ace19fa780361187f474153e455545235b4fe30637fdcc2", 11 | "zh:1b9a4e5c889bd2022bd59fb924dc78e189f1b7a4fd718fcacda0f0a4cb74d6eb", 12 | "zh:2485260141608f1d386d0f68934092bbf68a27d96f0d83c73222d0382aee02f5", 13 | "zh:2fe67ee94e2df7dabee7e474356f8e907e7c8011533f9d71df8702d59f9060b2", 14 | "zh:37babd1b7ff96ff1f42aa56d7575cacabda6f9f460ff651d70662bfd90076341", 15 | "zh:54aa8d39f22ecab6613169f49d37d2ccfaf417e59dd7a8c8fc6bf92600c3384f", 16 | "zh:5bf4a84b962a8d2da8f4ccf2a7de56fb6c7a1f566e8393b563977fc7872a8740", 17 | "zh:8cb4a51f209a3cc497e53f09188c15c6675697587fe2ea14a6c7fff10c8c8476", 18 | "zh:91f6bdcbb1e36471140982e9048b7ced437d3290b2cc21079e5429cc84fed2fd", 19 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 20 | "zh:9f8c01c3f677bc64ddefa41e59c6fc98860c11875d7f148af55969d3e3847f77", 21 | "zh:b6b4fc0bd6f3c0adcd9531da3ccf8c25787ccd6ccc568f13ebbff1336d71a9e1", 22 | "zh:d52a428bd92cc319088685ecac63b9f7d12d4cd6725604edb20d0c4f37a9936e", 23 | "zh:e20252a851a0d38548a3c01a006bfc59ee1fc84217bf9eb95b22724769601b2b", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/2_Terraform_Modules/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | vpc_cidr = "10.0.0.0/16" 3 | availability_zones = ["us-east-1a", "us-east-1b"] 4 | public_subnet_cidrs = ["10.0.0.0/24", "10.0.1.0/24"] 5 | private_subnet_cidrs = ["10.0.3.0/24", "10.0.4.0/24"] 6 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.3" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = "~> 4.0" 7 | } 8 | } 9 | } 10 | 11 | module "ccVPC" { 12 | source = "./modules/vpc" 13 | 14 | vpc_cidr = local.vpc_cidr 15 | vpc_tags = var.vpc_tags 16 | availability_zones = local.availability_zones 17 | public_subnet_cidrs = local.public_subnet_cidrs 18 | private_subnet_cidrs = local.private_subnet_cidrs 19 | } 20 | 21 | module "db" { 22 | source = "./modules/db" 23 | 24 | cc_vpc_id = module.ccVPC.vpc_id 25 | cc_private_subnets = module.ccVPC.private_subnets 26 | cc_private_subnet_cidrs = local.private_subnet_cidrs 27 | 28 | db_az = local.availability_zones[0] 29 | db_name = "ccDatabaseInstance" 30 | db_user_name = var.db_user_name 31 | db_user_password = var.db_user_password 32 | } 33 | 34 | module "webserver" { 35 | source = "./modules/webserver" 36 | 37 | cc_vpc_id = module.ccVPC.vpc_id 38 | cc_public_subnets = module.ccVPC.public_subnets 39 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/modules/db/db.tf: -------------------------------------------------------------------------------- 1 | resource "aws_db_subnet_group" "ccDBSubnetGroup" { 2 | name = "cc-db-subnet-group" 3 | subnet_ids = [ 4 | var.cc_private_subnets[0].id, 5 | var.cc_private_subnets[1].id 6 | ] 7 | tags = { 8 | Name = "ccDBSubnetGroup" 9 | Project = "CC TF Demo" 10 | } 11 | } 12 | 13 | resource "aws_security_group" "ccDBSecurityGroup" { 14 | name = "cc-db-security-group" 15 | vpc_id = var.cc_vpc_id 16 | 17 | ingress { 18 | from_port = 5432 19 | to_port = 5432 20 | protocol = "tcp" 21 | cidr_blocks = [ 22 | var.cc_private_subnet_cidrs[0], 23 | var.cc_private_subnet_cidrs[1] 24 | ] 25 | } 26 | tags = { 27 | Name = "ccDBSecurityGroup" 28 | Project = "CC TF Demo" 29 | } 30 | } 31 | 32 | resource "aws_db_instance" "ccRDS" { 33 | availability_zone = var.db_az 34 | db_subnet_group_name = aws_db_subnet_group.ccDBSubnetGroup.name 35 | vpc_security_group_ids = [aws_security_group.ccDBSecurityGroup.id] 36 | allocated_storage = 20 37 | storage_type = "standard" 38 | engine = "postgres" 39 | engine_version = "12" 40 | instance_class = "db.t2.micro" 41 | name = var.db_name 42 | username = var.db_user_name 43 | password = var.db_user_password 44 | skip_final_snapshot = true 45 | tags = { 46 | Name = "ccRDS" 47 | Project = "CC TF Demo" 48 | } 49 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/modules/db/variables.tf: -------------------------------------------------------------------------------- 1 | variable "cc_private_subnets" { 2 | description = "Private Subnets ID for RDS DB" 3 | type = list(any) 4 | } 5 | 6 | variable "cc_private_subnet_cidrs" { 7 | description = "Private Subnet CIDRs for RDS DB" 8 | type = list(any) 9 | } 10 | 11 | variable "cc_vpc_id" { 12 | description = "VPC Id" 13 | type = string 14 | validation { 15 | condition = length(var.cc_vpc_id) > 4 && substr(var.cc_vpc_id, 0, 4) == "vpc-" 16 | error_message = "VPC ID must not be empty." 17 | } 18 | } 19 | 20 | variable "db_az" { 21 | description = "DB Availability Zone" 22 | type = string 23 | validation { 24 | condition = can(regex("^[a-zA-Z0-9\\-]+$", var.db_az)) 25 | error_message = "DB Availability Zone must not be empty." 26 | } 27 | } 28 | 29 | variable "db_name" { 30 | description = "Name of DB" 31 | type = string 32 | sensitive = true 33 | validation { 34 | condition = can(regex("^[a-zA-Z0-9\\-\\_]+$", var.db_name)) 35 | error_message = "DB Name must not be empty and can contain letters, numbers, underscores, and dashes." 36 | } 37 | } 38 | 39 | variable "db_user_name" { 40 | description = "RDS DB User" 41 | type = string 42 | sensitive = true 43 | validation { 44 | condition = length(var.db_user_name) > 5 45 | error_message = "DB UserName must not be empty." 46 | } 47 | } 48 | 49 | variable "db_user_password" { 50 | description = "RDS DB User Password" 51 | type = string 52 | sensitive = true 53 | validation { 54 | condition = length(var.db_user_password) > 8 55 | error_message = "DB User Password must not be empty." 56 | } 57 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/modules/vpc/outputs.tf: -------------------------------------------------------------------------------- 1 | output "vpc_id" { 2 | value = aws_vpc.ccVPC.id 3 | } 4 | 5 | output "public_subnets" { 6 | description = "Will be used by Web Server Module to set subnet_ids" 7 | value = [ 8 | aws_subnet.ccPublicSubnet1, 9 | aws_subnet.ccPublicSubnet2 10 | ] 11 | } 12 | output "private_subnets" { 13 | description = "Will be used by RDS Module to set subnet_ids" 14 | value = [ 15 | aws_subnet.ccPrivateSubnet1, 16 | aws_subnet.ccPrivateSubnet2 17 | ] 18 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/modules/vpc/variables.tf: -------------------------------------------------------------------------------- 1 | variable "vpc_cidr" { 2 | description = "CIDR for VPC" 3 | type = string 4 | } 5 | 6 | variable "vpc_tags" { 7 | description = "Tags for VPC" 8 | type = map(any) 9 | } 10 | 11 | variable "availability_zones" { 12 | description = "AZs for Subnets" 13 | type = list(string) 14 | } 15 | 16 | variable "public_subnet_cidrs" { 17 | description = "CIDRs for Public Subnets" 18 | type = list(string) 19 | } 20 | 21 | variable "private_subnet_cidrs" { 22 | description = "CIDRs for Private Subnets" 23 | type = list(string) 24 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/modules/vpc/vpc.tf: -------------------------------------------------------------------------------- 1 | # Create a VPC 2 | resource "aws_vpc" "ccVPC" { 3 | instance_tenancy = "default" 4 | cidr_block = var.vpc_cidr 5 | tags = var.vpc_tags 6 | } 7 | 8 | resource "aws_internet_gateway" "ccIGW" { 9 | vpc_id = aws_vpc.ccVPC.id 10 | tags = { 11 | Name = "ccIGW" 12 | Project = "CC TF Demo" 13 | } 14 | } 15 | 16 | resource "aws_eip" "ccNatGatewayEIP1" { 17 | tags = { 18 | Name = "ccNatGatewayEIP1" 19 | Project = "CC TF Demo" 20 | } 21 | } 22 | resource "aws_nat_gateway" "ccNatGateway1" { 23 | allocation_id = aws_eip.ccNatGatewayEIP1.id 24 | subnet_id = aws_subnet.ccPublicSubnet1.id 25 | tags = { 26 | Name = "ccNatGateway1" 27 | Project = "CC TF Demo" 28 | } 29 | } 30 | resource "aws_subnet" "ccPublicSubnet1" { 31 | vpc_id = aws_vpc.ccVPC.id 32 | cidr_block = var.public_subnet_cidrs[0] 33 | availability_zone = var.availability_zones[0] 34 | tags = { 35 | Name = "ccPublicSubnet1" 36 | Project = "CC TF Demo" 37 | } 38 | } 39 | 40 | resource "aws_eip" "ccNatGatewayEIP2" { 41 | tags = { 42 | Name = "ccNatGatewayEIP2" 43 | Project = "CC TF Demo" 44 | } 45 | } 46 | resource "aws_nat_gateway" "ccNatGateway2" { 47 | allocation_id = aws_eip.ccNatGatewayEIP2.id 48 | subnet_id = aws_subnet.ccPublicSubnet1.id 49 | tags = { 50 | Name = "ccNatGateway2" 51 | Project = "CC TF Demo" 52 | } 53 | } 54 | resource "aws_subnet" "ccPublicSubnet2" { 55 | vpc_id = aws_vpc.ccVPC.id 56 | cidr_block = var.public_subnet_cidrs[1] 57 | availability_zone = var.availability_zones[1] 58 | tags = { 59 | Name = "ccPublicSubnet2" 60 | Project = "CC TF Demo" 61 | } 62 | } 63 | 64 | resource "aws_subnet" "ccPrivateSubnet1" { 65 | vpc_id = aws_vpc.ccVPC.id 66 | cidr_block = var.private_subnet_cidrs[0] 67 | availability_zone = var.availability_zones[0] 68 | tags = { 69 | Name = "ccPrivateSubnet1" 70 | Project = "CC TF Demo" 71 | } 72 | } 73 | resource "aws_subnet" "ccPrivateSubnet2" { 74 | vpc_id = aws_vpc.ccVPC.id 75 | cidr_block = var.private_subnet_cidrs[1] 76 | availability_zone = var.availability_zones[1] 77 | tags = { 78 | Name = "ccPrivateSubnet2" 79 | Project = "CC TF Demo" 80 | } 81 | } 82 | 83 | resource "aws_route_table" "ccPublicRT" { 84 | vpc_id = aws_vpc.ccVPC.id 85 | route { 86 | cidr_block = "0.0.0.0/0" 87 | gateway_id = aws_internet_gateway.ccIGW.id 88 | } 89 | tags = { 90 | Name = "ccPublicRT" 91 | Project = "CC TF Demo" 92 | } 93 | } 94 | resource "aws_route_table" "ccPrivateRT1" { 95 | vpc_id = aws_vpc.ccVPC.id 96 | route { 97 | cidr_block = "0.0.0.0/0" 98 | nat_gateway_id = aws_nat_gateway.ccNatGateway1.id 99 | } 100 | tags = { 101 | Name = "ccPrivateRT1" 102 | Project = "CC TF Demo" 103 | } 104 | } 105 | 106 | resource "aws_route_table_association" "ccPublicRTassociation1" { 107 | subnet_id = aws_subnet.ccPublicSubnet1.id 108 | route_table_id = aws_route_table.ccPublicRT.id 109 | } 110 | resource "aws_route_table_association" "ccPublicRTassociation2" { 111 | subnet_id = aws_subnet.ccPublicSubnet2.id 112 | route_table_id = aws_route_table.ccPublicRT.id 113 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/modules/webserver/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | ami_id = "ami-026b57f3c383c2eec" 3 | instance_type = "t2.micro" 4 | key_name = "ccKP" 5 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/modules/webserver/outputs.tf: -------------------------------------------------------------------------------- 1 | output "load_balancer_dns_name" { 2 | description = "Load Balancer DNS Name" 3 | value = aws_lb.ccLoadBalancer.dns_name 4 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/modules/webserver/variables.tf: -------------------------------------------------------------------------------- 1 | variable "cc_public_subnets" { 2 | description = "Public Subnets" 3 | type = list(any) 4 | } 5 | 6 | variable "cc_vpc_id" { 7 | description = "VPC ID" 8 | type = string 9 | validation { 10 | condition = length(var.cc_vpc_id) > 4 && substr(var.cc_vpc_id, 0, 4) == "vpc-" 11 | error_message = "VPC ID must not be empty." 12 | } 13 | } 14 | 15 | variable "ingress_rules" { 16 | type = list(object({ 17 | port = number 18 | proto = string 19 | cidr_blocks = list(string) 20 | })) 21 | default = [ 22 | { 23 | port = 80 24 | proto = "tcp" 25 | cidr_blocks = ["0.0.0.0/0"] 26 | }, 27 | { 28 | port = 22 29 | proto = "tcp" 30 | cidr_blocks = ["0.0.0.0/0"] 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/outputs.tf: -------------------------------------------------------------------------------- 1 | output "vpc_id" { 2 | value = module.ccVPC.vpc_id 3 | } 4 | 5 | output "load_balancer_dns_name" { 6 | value = module.webserver.load_balancer_dns_name 7 | } 8 | -------------------------------------------------------------------------------- /src/2_Terraform_Modules/providers.tf: -------------------------------------------------------------------------------- 1 | # Configure the AWS Provider 2 | provider "aws" { 3 | region = "us-east-1" 4 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/terraform.tfvars: -------------------------------------------------------------------------------- 1 | vpc_tags = { 2 | Name = "ccVPC", 3 | Project = "CC TF Demo" 4 | } -------------------------------------------------------------------------------- /src/2_Terraform_Modules/variables.tf: -------------------------------------------------------------------------------- 1 | variable "vpc_tags" { 2 | description = "Tags for VPC" 3 | type = map(any) 4 | } 5 | 6 | variable "db_user_name" { 7 | description = "RDS DB User" 8 | type = string 9 | sensitive = true 10 | validation { 11 | condition = length(var.db_user_name) > 5 12 | error_message = "DB UserName must not be empty." 13 | } 14 | } 15 | 16 | variable "db_user_password" { 17 | description = "RDS DB User Password" 18 | type = string 19 | sensitive = true 20 | validation { 21 | condition = length(var.db_user_password) > 8 22 | error_message = "DB User Password must not be empty." 23 | } 24 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | bucket_name = "YOUR_BUCKET_NAME" 3 | table_name = "YOUR_TABLE_NAME" 4 | 5 | vpc_cidr = "10.0.0.0/16" 6 | availability_zones = ["us-east-1a", "us-east-1b"] 7 | public_subnet_cidrs = ["10.0.0.0/24", "10.0.1.0/24"] 8 | private_subnet_cidrs = ["10.0.3.0/24", "10.0.4.0/24"] 9 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.3" 3 | 4 | backend "s3" { 5 | bucket = "YOUR_BUCKET_NAME" 6 | key = "tf-infra/terraform.tfstate" 7 | region = "us-east-1" 8 | dynamodb_table = "YOUR_TABLE_NAME" 9 | encrypt = true 10 | } 11 | 12 | required_providers { 13 | aws = { 14 | source = "hashicorp/aws" 15 | version = "~> 4.0" 16 | } 17 | } 18 | } 19 | 20 | module "tf-state" { 21 | source = "./modules/tf-state" 22 | bucket_name = local.bucket_name 23 | table_name = local.table_name 24 | } 25 | 26 | module "ccVPC" { 27 | source = "./modules/vpc" 28 | 29 | vpc_cidr = local.vpc_cidr 30 | vpc_tags = var.vpc_tags 31 | availability_zones = local.availability_zones 32 | public_subnet_cidrs = local.public_subnet_cidrs 33 | private_subnet_cidrs = local.private_subnet_cidrs 34 | } 35 | 36 | module "db" { 37 | source = "./modules/db" 38 | 39 | cc_vpc_id = module.ccVPC.vpc_id 40 | cc_private_subnets = module.ccVPC.private_subnets 41 | cc_private_subnet_cidrs = local.private_subnet_cidrs 42 | 43 | db_az = local.availability_zones[0] 44 | db_name = "ccDatabaseInstance" 45 | db_user_name = var.db_user_name 46 | db_user_password = var.db_user_password 47 | } 48 | 49 | module "webserver" { 50 | source = "./modules/webserver" 51 | 52 | cc_vpc_id = module.ccVPC.vpc_id 53 | cc_public_subnets = module.ccVPC.public_subnets 54 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/db/db.tf: -------------------------------------------------------------------------------- 1 | resource "aws_db_subnet_group" "ccDBSubnetGroup" { 2 | name = "cc-db-subnet-group" 3 | subnet_ids = [ 4 | var.cc_private_subnets[0].id, 5 | var.cc_private_subnets[1].id 6 | ] 7 | tags = { 8 | Name = "ccDBSubnetGroup" 9 | Project = "CC TF Demo" 10 | } 11 | } 12 | 13 | resource "aws_security_group" "ccDBSecurityGroup" { 14 | name = "cc-db-security-group" 15 | vpc_id = var.cc_vpc_id 16 | 17 | ingress { 18 | from_port = 5432 19 | to_port = 5432 20 | protocol = "tcp" 21 | cidr_blocks = [ 22 | var.cc_private_subnet_cidrs[0], 23 | var.cc_private_subnet_cidrs[1] 24 | ] 25 | } 26 | tags = { 27 | Name = "ccDBSecurityGroup" 28 | Project = "CC TF Demo" 29 | } 30 | } 31 | 32 | resource "aws_db_instance" "ccRDS" { 33 | availability_zone = var.db_az 34 | db_subnet_group_name = aws_db_subnet_group.ccDBSubnetGroup.name 35 | vpc_security_group_ids = [aws_security_group.ccDBSecurityGroup.id] 36 | allocated_storage = 20 37 | storage_type = "standard" 38 | engine = "postgres" 39 | engine_version = "12" 40 | instance_class = "db.t2.micro" 41 | name = var.db_name 42 | username = var.db_user_name 43 | password = var.db_user_password 44 | skip_final_snapshot = true 45 | tags = { 46 | Name = "ccRDS" 47 | Project = "CC TF Demo" 48 | } 49 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/db/variables.tf: -------------------------------------------------------------------------------- 1 | variable "cc_private_subnets" { 2 | description = "Private Subnets ID for RDS DB" 3 | type = list(any) 4 | } 5 | 6 | variable "cc_private_subnet_cidrs" { 7 | description = "Private Subnet CIDRs for RDS DB" 8 | type = list(any) 9 | } 10 | 11 | variable "cc_vpc_id" { 12 | description = "VPC Id" 13 | type = string 14 | validation { 15 | condition = length(var.cc_vpc_id) > 4 && substr(var.cc_vpc_id, 0, 4) == "vpc-" 16 | error_message = "VPC ID must not be empty." 17 | } 18 | } 19 | 20 | variable "db_az" { 21 | description = "DB Availability Zone" 22 | type = string 23 | validation { 24 | condition = can(regex("^[a-zA-Z0-9\\-]+$", var.db_az)) 25 | error_message = "DB Availability Zone must not be empty." 26 | } 27 | } 28 | 29 | variable "db_name" { 30 | description = "Name of DB" 31 | type = string 32 | sensitive = true 33 | validation { 34 | condition = can(regex("^[a-zA-Z0-9\\-\\_]+$", var.db_name)) 35 | error_message = "DB Name must not be empty and can contain letters, numbers, underscores, and dashes." 36 | } 37 | } 38 | 39 | variable "db_user_name" { 40 | description = "RDS DB User" 41 | type = string 42 | sensitive = true 43 | validation { 44 | condition = length(var.db_user_name) > 5 45 | error_message = "DB UserName must not be empty." 46 | } 47 | } 48 | 49 | variable "db_user_password" { 50 | description = "RDS DB User Password" 51 | type = string 52 | sensitive = true 53 | validation { 54 | condition = length(var.db_user_password) > 8 55 | error_message = "DB User Password must not be empty." 56 | } 57 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/tf-state/tf-state.tf: -------------------------------------------------------------------------------- 1 | resource "aws_s3_bucket" "terraform_state" { 2 | bucket = var.bucket_name 3 | force_destroy = true 4 | } 5 | 6 | resource "aws_s3_bucket_versioning" "terraform_bucket_versioning" { 7 | bucket = aws_s3_bucket.terraform_state.id 8 | versioning_configuration { 9 | status = "Enabled" 10 | } 11 | } 12 | 13 | resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_crypto_conf" { 14 | bucket = aws_s3_bucket.terraform_state.bucket 15 | rule { 16 | apply_server_side_encryption_by_default { 17 | sse_algorithm = "AES256" 18 | } 19 | } 20 | } 21 | 22 | resource "aws_dynamodb_table" "terraform_locks" { 23 | name = var.table_name 24 | billing_mode = "PAY_PER_REQUEST" 25 | hash_key = "LockID" 26 | attribute { 27 | name = "LockID" 28 | type = "S" 29 | } 30 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/tf-state/variables.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "Remote S3 Bucket Name" 3 | type = string 4 | validation { 5 | condition = can(regex("^([a-z0-9]{1}[a-z0-9-]{1,61}[a-z0-9]{1})$", var.bucket_name)) 6 | error_message = "Bucket Name must not be empty and must follow S3 naming rules." 7 | } 8 | } 9 | 10 | variable "table_name" { 11 | description = "Remote DynamoDB Table Name" 12 | type = string 13 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/vpc/outputs.tf: -------------------------------------------------------------------------------- 1 | output "vpc_id" { 2 | value = aws_vpc.ccVPC.id 3 | } 4 | 5 | output "public_subnets" { 6 | description = "Will be used by Web Server Module to set subnet_ids" 7 | value = [ 8 | aws_subnet.ccPublicSubnet1, 9 | aws_subnet.ccPublicSubnet2 10 | ] 11 | } 12 | output "private_subnets" { 13 | description = "Will be used by RDS Module to set subnet_ids" 14 | value = [ 15 | aws_subnet.ccPrivateSubnet1, 16 | aws_subnet.ccPrivateSubnet2 17 | ] 18 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/vpc/variables.tf: -------------------------------------------------------------------------------- 1 | variable "vpc_cidr" { 2 | description = "CIDR for VPC" 3 | type = string 4 | } 5 | 6 | variable "vpc_tags" { 7 | description = "Tags for VPC" 8 | type = map(any) 9 | } 10 | 11 | variable "availability_zones" { 12 | description = "AZs for Subnets" 13 | type = list(string) 14 | } 15 | 16 | variable "public_subnet_cidrs" { 17 | description = "CIDRs for Public Subnets" 18 | type = list(string) 19 | } 20 | 21 | variable "private_subnet_cidrs" { 22 | description = "CIDRs for Private Subnets" 23 | type = list(string) 24 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/vpc/vpc.tf: -------------------------------------------------------------------------------- 1 | # Create a VPC 2 | resource "aws_vpc" "ccVPC" { 3 | instance_tenancy = "default" 4 | cidr_block = var.vpc_cidr 5 | tags = var.vpc_tags 6 | } 7 | 8 | resource "aws_internet_gateway" "ccIGW" { 9 | vpc_id = aws_vpc.ccVPC.id 10 | tags = { 11 | Name = "ccIGW" 12 | Project = "CC TF Demo" 13 | } 14 | } 15 | 16 | resource "aws_eip" "ccNatGatewayEIP1" { 17 | tags = { 18 | Name = "ccNatGatewayEIP1" 19 | Project = "CC TF Demo" 20 | } 21 | } 22 | resource "aws_nat_gateway" "ccNatGateway1" { 23 | allocation_id = aws_eip.ccNatGatewayEIP1.id 24 | subnet_id = aws_subnet.ccPublicSubnet1.id 25 | tags = { 26 | Name = "ccNatGateway1" 27 | Project = "CC TF Demo" 28 | } 29 | } 30 | resource "aws_subnet" "ccPublicSubnet1" { 31 | vpc_id = aws_vpc.ccVPC.id 32 | cidr_block = var.public_subnet_cidrs[0] 33 | availability_zone = var.availability_zones[0] 34 | tags = { 35 | Name = "ccPublicSubnet1" 36 | Project = "CC TF Demo" 37 | } 38 | } 39 | 40 | resource "aws_eip" "ccNatGatewayEIP2" { 41 | tags = { 42 | Name = "ccNatGatewayEIP2" 43 | Project = "CC TF Demo" 44 | } 45 | } 46 | resource "aws_nat_gateway" "ccNatGateway2" { 47 | allocation_id = aws_eip.ccNatGatewayEIP2.id 48 | subnet_id = aws_subnet.ccPublicSubnet1.id 49 | tags = { 50 | Name = "ccNatGateway2" 51 | Project = "CC TF Demo" 52 | } 53 | } 54 | resource "aws_subnet" "ccPublicSubnet2" { 55 | vpc_id = aws_vpc.ccVPC.id 56 | cidr_block = var.public_subnet_cidrs[1] 57 | availability_zone = var.availability_zones[1] 58 | tags = { 59 | Name = "ccPublicSubnet2" 60 | Project = "CC TF Demo" 61 | } 62 | } 63 | 64 | resource "aws_subnet" "ccPrivateSubnet1" { 65 | vpc_id = aws_vpc.ccVPC.id 66 | cidr_block = var.private_subnet_cidrs[0] 67 | availability_zone = var.availability_zones[0] 68 | tags = { 69 | Name = "ccPrivateSubnet1" 70 | Project = "CC TF Demo" 71 | } 72 | } 73 | resource "aws_subnet" "ccPrivateSubnet2" { 74 | vpc_id = aws_vpc.ccVPC.id 75 | cidr_block = var.private_subnet_cidrs[1] 76 | availability_zone = var.availability_zones[1] 77 | tags = { 78 | Name = "ccPrivateSubnet2" 79 | Project = "CC TF Demo" 80 | } 81 | } 82 | 83 | resource "aws_route_table" "ccPublicRT" { 84 | vpc_id = aws_vpc.ccVPC.id 85 | route { 86 | cidr_block = "0.0.0.0/0" 87 | gateway_id = aws_internet_gateway.ccIGW.id 88 | } 89 | tags = { 90 | Name = "ccPublicRT" 91 | Project = "CC TF Demo" 92 | } 93 | } 94 | resource "aws_route_table" "ccPrivateRT1" { 95 | vpc_id = aws_vpc.ccVPC.id 96 | route { 97 | cidr_block = "0.0.0.0/0" 98 | nat_gateway_id = aws_nat_gateway.ccNatGateway1.id 99 | } 100 | tags = { 101 | Name = "ccPrivateRT1" 102 | Project = "CC TF Demo" 103 | } 104 | } 105 | 106 | resource "aws_route_table_association" "ccPublicRTassociation1" { 107 | subnet_id = aws_subnet.ccPublicSubnet1.id 108 | route_table_id = aws_route_table.ccPublicRT.id 109 | } 110 | resource "aws_route_table_association" "ccPublicRTassociation2" { 111 | subnet_id = aws_subnet.ccPublicSubnet2.id 112 | route_table_id = aws_route_table.ccPublicRT.id 113 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/webserver/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | ami_id = "ami-026b57f3c383c2eec" 3 | instance_type = "t2.micro" 4 | key_name = "ccKP" 5 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/webserver/outputs.tf: -------------------------------------------------------------------------------- 1 | output "load_balancer_dns_name" { 2 | description = "Load Balancer DNS Name" 3 | value = aws_lb.ccLoadBalancer.dns_name 4 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/webserver/variables.tf: -------------------------------------------------------------------------------- 1 | variable "cc_public_subnets" { 2 | description = "Public Subnets" 3 | type = list(any) 4 | } 5 | 6 | variable "cc_vpc_id" { 7 | description = "VPC ID" 8 | type = string 9 | validation { 10 | condition = length(var.cc_vpc_id) > 4 && substr(var.cc_vpc_id, 0, 4) == "vpc-" 11 | error_message = "VPC ID must not be empty." 12 | } 13 | } 14 | 15 | variable "ingress_rules" { 16 | type = list(object({ 17 | port = number 18 | proto = string 19 | cidr_blocks = list(string) 20 | })) 21 | default = [ 22 | { 23 | port = 80 24 | proto = "tcp" 25 | cidr_blocks = ["0.0.0.0/0"] 26 | }, 27 | { 28 | port = 22 29 | proto = "tcp" 30 | cidr_blocks = ["0.0.0.0/0"] 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/modules/webserver/webserver.tf: -------------------------------------------------------------------------------- 1 | resource "aws_security_group" "ccWebserverSecurityGroup" { 2 | name = "allow_ssh_http" 3 | description = "Allow ssh http inbound traffic" 4 | vpc_id = var.cc_vpc_id 5 | 6 | dynamic "ingress" { 7 | for_each = var.ingress_rules 8 | content { 9 | from_port = ingress.value["port"] 10 | to_port = ingress.value["port"] 11 | protocol = ingress.value["proto"] 12 | cidr_blocks = ingress.value["cidr_blocks"] 13 | } 14 | } 15 | 16 | egress { 17 | from_port = 0 18 | to_port = 0 19 | protocol = "-1" 20 | cidr_blocks = ["0.0.0.0/0"] 21 | } 22 | 23 | tags = { 24 | Name = "ccWebserverSecurityGroup" 25 | Project = "CC TF Demo" 26 | } 27 | } 28 | 29 | resource "aws_lb" "ccLoadBalancer" { 30 | load_balancer_type = "application" 31 | subnets = [var.cc_public_subnets[0].id, var.cc_public_subnets[1].id] 32 | security_groups = [aws_security_group.ccWebserverSecurityGroup.id] 33 | tags = { 34 | Name = "ccLoadBalancer" 35 | Project = "CC TF Demo" 36 | } 37 | } 38 | 39 | resource "aws_lb_listener" "ccLbListener" { 40 | load_balancer_arn = aws_lb.ccLoadBalancer.arn 41 | 42 | port = 80 43 | protocol = "HTTP" 44 | 45 | default_action { 46 | target_group_arn = aws_lb_target_group.ccTargetGroup.id 47 | type = "forward" 48 | } 49 | } 50 | 51 | resource "aws_lb_target_group" "ccTargetGroup" { 52 | name = "example-target-group" 53 | port = 80 54 | protocol = "HTTP" 55 | vpc_id = var.cc_vpc_id 56 | 57 | health_check { 58 | path = "/" 59 | protocol = "HTTP" 60 | matcher = "200" 61 | interval = 15 62 | timeout = 3 63 | healthy_threshold = 2 64 | unhealthy_threshold = 2 65 | } 66 | tags = { 67 | Name = "ccTargetGroup" 68 | Project = "CC TF Demo" 69 | } 70 | } 71 | 72 | resource "aws_lb_target_group_attachment" "webserver1" { 73 | target_group_arn = aws_lb_target_group.ccTargetGroup.arn 74 | target_id = aws_instance.webserver1.id 75 | port = 80 76 | } 77 | 78 | resource "aws_lb_target_group_attachment" "webserver2" { 79 | target_group_arn = aws_lb_target_group.ccTargetGroup.arn 80 | target_id = aws_instance.webserver2.id 81 | port = 80 82 | } 83 | 84 | resource "aws_instance" "webserver1" { 85 | ami = local.ami_id 86 | instance_type = local.instance_type 87 | key_name = local.key_name 88 | subnet_id = var.cc_public_subnets[0].id 89 | security_groups = [aws_security_group.ccWebserverSecurityGroup.id] 90 | associate_public_ip_address = true 91 | 92 | user_data = <<-EOF 93 | #!/bin/bash -xe 94 | sudo su 95 | yum update -y 96 | yum install -y httpd 97 | echo "

Hello, World!

server: ccWebServer1" > /var/www/html/index.html 98 | echo "healthy" > /var/www/html/hc.html 99 | service httpd start 100 | EOF 101 | } 102 | 103 | resource "aws_instance" "webserver2" { 104 | ami = local.ami_id 105 | instance_type = local.instance_type 106 | key_name = local.key_name 107 | subnet_id = var.cc_public_subnets[0].id 108 | security_groups = [aws_security_group.ccWebserverSecurityGroup.id] 109 | associate_public_ip_address = true 110 | 111 | user_data = <<-EOF 112 | #!/bin/bash -xe 113 | sudo su 114 | yum update -y 115 | yum install -y httpd 116 | echo "

Hello, World!

server: ccWebServer2" > /var/www/html/index.html 117 | echo "healthy" > /var/www/html/hc.html 118 | service httpd start 119 | EOF 120 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/outputs.tf: -------------------------------------------------------------------------------- 1 | output "vpc_id" { 2 | value = module.ccVPC.vpc_id 3 | } 4 | 5 | output "load_balancer_dns_name" { 6 | value = module.webserver.load_balancer_dns_name 7 | } 8 | -------------------------------------------------------------------------------- /src/3_Terraform_State/providers.tf: -------------------------------------------------------------------------------- 1 | # Configure the AWS Provider 2 | provider "aws" { 3 | region = "us-east-1" 4 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/terraform.tfvars: -------------------------------------------------------------------------------- 1 | vpc_tags = { 2 | Name = "ccVPC", 3 | Project = "CC TF Demo" 4 | } -------------------------------------------------------------------------------- /src/3_Terraform_State/variables.tf: -------------------------------------------------------------------------------- 1 | variable "vpc_tags" { 2 | description = "Tags for VPC" 3 | type = map(any) 4 | } 5 | 6 | variable "db_user_name" { 7 | description = "RDS DB User" 8 | type = string 9 | sensitive = true 10 | validation { 11 | condition = length(var.db_user_name) > 5 12 | error_message = "DB UserName must not be empty." 13 | } 14 | } 15 | 16 | variable "db_user_password" { 17 | description = "RDS DB User Password" 18 | type = string 19 | sensitive = true 20 | validation { 21 | condition = length(var.db_user_password) > 8 22 | error_message = "DB User Password must not be empty." 23 | } 24 | } -------------------------------------------------------------------------------- /src/4_HashiCorp_Vault/data.tf: -------------------------------------------------------------------------------- 1 | data "vault_generic_secret" "vault_db_username" { 2 | path = "secret/db-username-secret" 3 | } 4 | 5 | data "vault_generic_secret" "vault_db_password" { 6 | path = "secret/db-password-secret" 7 | } -------------------------------------------------------------------------------- /src/4_HashiCorp_Vault/ec2.tf: -------------------------------------------------------------------------------- 1 | resource "aws_instance" "webserver" { 2 | ami = "ami-026b57f3c383c2eec" 3 | instance_type = "t2.micro" 4 | 5 | tags = { 6 | Name = "webserver" 7 | } 8 | } -------------------------------------------------------------------------------- /src/4_HashiCorp_Vault/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.3" 3 | required_providers { 4 | vault = { 5 | source = "hashicorp/vault" 6 | #version = "1.12.3" # commented-out to pick up current version of Provider 7 | } 8 | 9 | aws = { 10 | source = "hashicorp/aws" 11 | version = "~> 4.0" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/4_HashiCorp_Vault/outputs.tf: -------------------------------------------------------------------------------- 1 | 2 | output "vault_db_username_secret" { 3 | #value = data.vault_generic_secret.vault_db_username.data_json 4 | value = data.vault_generic_secret.vault_db_username.data["db_username"] 5 | sensitive = true 6 | } 7 | 8 | output "vault_db_password_secret" { 9 | #value = data.vault_generic_secret.vault_db_password.data_json 10 | value = data.vault_generic_secret.vault_db_password.data["db_password"] 11 | sensitive = true 12 | } 13 | -------------------------------------------------------------------------------- /src/4_HashiCorp_Vault/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | profile = "tf_dev" 4 | } 5 | 6 | provider "vault" { 7 | address = "http://127.0.0.1:8200" 8 | } -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/App/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:alpine 2 | 3 | WORKDIR /src 4 | 5 | COPY ./src/package.json . 6 | RUN npm install 7 | 8 | COPY ./src/ . 9 | 10 | EXPOSE 3000 11 | 12 | CMD ["node", "server.js"] -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/App/src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "node server.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "express": "^4.18.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/App/src/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | app.use(function(req, res, next) { 5 | res.header('Access-Control-Allow-Origin', '*'); 6 | res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); 7 | next(); 8 | }); 9 | 10 | // Hard-Coded for demo 11 | const CONTACTS = [ 12 | { 13 | "name": "Foo Bar", 14 | "email": "foobar@test.com", 15 | "cell": "555-123-4567" 16 | }, 17 | { 18 | "name": "Biz Baz", 19 | "email": "bizbaz@test.com", 20 | "cell": "555-123-5678" 21 | }, 22 | { 23 | "name": "Bing Bang", 24 | "email": "bingbang@test.com", 25 | "cell": "555-123-6789" 26 | } 27 | ]; 28 | 29 | app.get('/contacts', (req, res) => { 30 | res.json({contacts: CONTACTS}); 31 | }); 32 | 33 | app.listen(3000, () =>{ 34 | console.log('Server running on port 3000.'); 35 | }); 36 | -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | bucket_name = "cc-tf-demo" 3 | table_name = "ccTfDemo" 4 | 5 | ecr_repo_name = "demo-app-ecr-repo" 6 | 7 | demo_app_cluster_name = "demo-app-cluster" 8 | availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"] 9 | demo_app_task_famliy = "demo-app-task" 10 | container_port = 3000 11 | demo_app_task_name = "demo-app-task" 12 | ecs_task_execution_role_name = "demo-app-task-execution-role" 13 | 14 | application_load_balancer_name = "cc-demo-app-alb" 15 | target_group_name = "cc-demo-alb-tg" 16 | 17 | demo_app_service_name = "cc-demo-app-service" 18 | } -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.3" 3 | 4 | backend "s3" { 5 | bucket = "cc-tf-demo" 6 | key = "tf-infra/terraform.tfstate" 7 | region = "us-east-1" 8 | dynamodb_table = "ccTfDemo" 9 | encrypt = true 10 | } 11 | 12 | required_providers { 13 | aws = { 14 | source = "hashicorp/aws" 15 | version = "~> 4.0" 16 | } 17 | } 18 | } 19 | 20 | module "tf-state" { 21 | source = "./modules/tf-state" 22 | bucket_name = local.bucket_name 23 | table_name = local.table_name 24 | } 25 | 26 | module "ecrRepo" { 27 | source = "./modules/ecr" 28 | 29 | ecr_repo_name = local.ecr_repo_name 30 | } 31 | 32 | module "ecsCluster" { 33 | source = "./modules/ecs" 34 | 35 | demo_app_cluster_name = local.demo_app_cluster_name 36 | availability_zones = local.availability_zones 37 | 38 | demo_app_task_famliy = local.demo_app_task_famliy 39 | ecr_repo_url = module.ecrRepo.repository_url 40 | container_port = local.container_port 41 | demo_app_task_name = local.demo_app_task_name 42 | ecs_task_execution_role_name = local.ecs_task_execution_role_name 43 | 44 | application_load_balancer_name = local.application_load_balancer_name 45 | target_group_name = local.target_group_name 46 | demo_app_service_name = local.demo_app_service_name 47 | } -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/modules/ecr/ecr.tf: -------------------------------------------------------------------------------- 1 | resource "aws_ecr_repository" "demo_app_ecr_repo" { 2 | name = var.ecr_repo_name 3 | } 4 | -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/modules/ecr/outputs.tf: -------------------------------------------------------------------------------- 1 | output "repository_url" { 2 | value = aws_ecr_repository.demo_app_ecr_repo.repository_url 3 | } -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/modules/ecr/variables.tf: -------------------------------------------------------------------------------- 1 | variable "ecr_repo_name" { 2 | description = "ECR Repo Name" 3 | type = string 4 | } 5 | -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/modules/ecs/data.tf: -------------------------------------------------------------------------------- 1 | data "aws_iam_policy_document" "assume_role_policy" { 2 | statement { 3 | actions = ["sts:AssumeRole"] 4 | 5 | principals { 6 | type = "Service" 7 | identifiers = ["ecs-tasks.amazonaws.com"] 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/modules/ecs/variables.tf: -------------------------------------------------------------------------------- 1 | variable "demo_app_cluster_name" { 2 | description = "ECS Cluster Name" 3 | type = string 4 | } 5 | 6 | variable "availability_zones" { 7 | description = "us-east-1 AZs" 8 | type = list(string) 9 | } 10 | 11 | variable "demo_app_task_famliy" { 12 | description = "ECS Task Family" 13 | type = string 14 | } 15 | 16 | variable "ecr_repo_url" { 17 | description = "ECR Repo URL" 18 | type = string 19 | } 20 | 21 | variable "container_port" { 22 | description = "Container Port" 23 | type = number 24 | } 25 | 26 | variable "demo_app_task_name" { 27 | description = "ECS Task Name" 28 | type = string 29 | } 30 | 31 | variable "ecs_task_execution_role_name" { 32 | description = "ECS Task Execution Role Name" 33 | type = string 34 | } 35 | 36 | variable "application_load_balancer_name" { 37 | description = "ALB Name" 38 | type = string 39 | } 40 | 41 | variable "target_group_name" { 42 | description = "ALB Target Group Name" 43 | type = string 44 | } 45 | 46 | variable "demo_app_service_name" { 47 | description = "ECS Service Name" 48 | type = string 49 | } -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/modules/tf-state/tf-state.tf: -------------------------------------------------------------------------------- 1 | resource "aws_s3_bucket" "terraform_state" { 2 | bucket = var.bucket_name 3 | force_destroy = true 4 | } 5 | 6 | resource "aws_s3_bucket_versioning" "terraform_bucket_versioning" { 7 | bucket = aws_s3_bucket.terraform_state.id 8 | versioning_configuration { 9 | status = "Enabled" 10 | } 11 | } 12 | 13 | resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_crypto_conf" { 14 | bucket = aws_s3_bucket.terraform_state.bucket 15 | rule { 16 | apply_server_side_encryption_by_default { 17 | sse_algorithm = "AES256" 18 | } 19 | } 20 | } 21 | 22 | resource "aws_dynamodb_table" "terraform_locks" { 23 | name = var.table_name 24 | billing_mode = "PAY_PER_REQUEST" 25 | hash_key = "LockID" 26 | attribute { 27 | name = "LockID" 28 | type = "S" 29 | } 30 | } -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/modules/tf-state/variables.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "Remote S3 Bucket Name" 3 | type = string 4 | validation { 5 | condition = can(regex("^([a-z0-9]{1}[a-z0-9-]{1,61}[a-z0-9]{1})$", var.bucket_name)) 6 | error_message = "Bucket Name must not be empty and must follow S3 naming rules." 7 | } 8 | } 9 | 10 | variable "table_name" { 11 | description = "Remote DynamoDB Table Name" 12 | type = string 13 | } -------------------------------------------------------------------------------- /src/5_Terraform_ECR_ECS/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/cft/params/params.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "ParameterKey": "VPCName", 4 | "ParameterValue": "ccVPC" 5 | }, 6 | { 7 | "ParameterKey": "CIDR", 8 | "ParameterValue": "10.0.0.0/16" 9 | } 10 | ] -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/cft/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: "2010-09-09" 2 | 3 | Description: Template to Create a VPC 4 | 5 | Metadata: 6 | AWS::CloudFormation::Interface: 7 | ParameterGroups: 8 | - 9 | Label: 10 | default: "VPC Configuration" 11 | Parameters: 12 | - VPCName 13 | - CIDR 14 | 15 | Parameters: 16 | VPCName: 17 | Type: String 18 | Description: Name of VPC 19 | Default: "" 20 | CIDR: 21 | Type: String 22 | Description: VPC CIDR 23 | Default: "" 24 | 25 | Rules: 26 | ValidateRequiredParams: 27 | Assertions: 28 | - Assert: !Not [!Equals [!Ref VPCName, ""]] 29 | AssertDescription: 'VPCName is required' 30 | - Assert: !Not [!Equals [!Ref CIDR, ""]] 31 | AssertDescription: 'CIDR is required' 32 | 33 | Resources: 34 | ccVPC: 35 | Type: AWS::EC2::VPC 36 | Properties: 37 | CidrBlock: !Ref CIDR 38 | Tags: 39 | - Key: Name 40 | Value: !Ref VPCName 41 | 42 | Outputs: 43 | ccVPC: 44 | Export: 45 | Name: !Sub ${AWS::StackName}-ccVPC 46 | Value: !Ref ccVPC 47 | -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | bucket_name = "cc-demo-bkt" 3 | table_name = "cc-demo-tbl" 4 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.5" 3 | 4 | backend "s3" { 5 | bucket = "cc-demo-bkt" 6 | key = "tf-infra/terraform.tfstate" 7 | region = "us-east-1" 8 | dynamodb_table = "cc-demo-tbl" 9 | encrypt = true 10 | } 11 | 12 | required_providers { 13 | aws = { 14 | source = "hashicorp/aws" 15 | version = "~> 4.0" 16 | } 17 | } 18 | } 19 | 20 | module "tf-state" { 21 | source = "./modules/tf-state" 22 | bucket_name = local.bucket_name 23 | table_name = local.table_name 24 | } 25 | 26 | # Module for S3 Bucket to hold CFT Template 27 | module "cft-bucket" { 28 | source = "./modules/cft-bucket" 29 | bucket_name = var.cft_bucket_name 30 | } 31 | 32 | # Module for S3 Object (the CFT Template) 33 | module "cft-template" { 34 | source = "./modules/cft-template" 35 | bucket_name = module.cft-bucket.cft_bucket_name 36 | template_key = var.cft_template_name 37 | template_source = var.cft_template_location 38 | } 39 | 40 | # Module for the CFT Stack (creates the VPC Resource) 41 | module "cft-stack" { 42 | source = "./modules/cft-stack" 43 | stack_name = var.cft_stack_name 44 | template_url = "https://${module.cft-bucket.cft_bucket_endpoint}/${module.cft-template.cft_template_key}" 45 | vpc_name = var.vpc_name 46 | vpc_cidr = var.vpc_cidr 47 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/cft-bucket/cft-bucket.tf: -------------------------------------------------------------------------------- 1 | resource "aws_s3_bucket" "cft-bucket" { 2 | bucket = var.bucket_name 3 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/cft-bucket/outputs.tf: -------------------------------------------------------------------------------- 1 | output "cft_bucket_name" { 2 | value = aws_s3_bucket.cft-bucket.bucket 3 | } 4 | 5 | output "cft_bucket_endpoint" { 6 | value = aws_s3_bucket.cft-bucket.bucket_domain_name 7 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/cft-bucket/variables.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "Name of CFT Bucket" 3 | type = string 4 | } 5 | -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/cft-stack/ctf-stack.tf: -------------------------------------------------------------------------------- 1 | resource "aws_cloudformation_stack" "VPC" { 2 | parameters = { 3 | VPCName = var.vpc_name 4 | CIDR = var.vpc_cidr 5 | } 6 | 7 | name = var.stack_name 8 | template_url = var.template_url 9 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/cft-stack/variables.tf: -------------------------------------------------------------------------------- 1 | variable "stack_name" { 2 | description = "Name of CFT Stack" 3 | type = string 4 | } 5 | 6 | variable "template_url" { 7 | description = "Location of CFT Stack Template" 8 | type = string 9 | } 10 | 11 | variable "vpc_name" { 12 | description = "Name of VPC" 13 | type = string 14 | } 15 | 16 | variable "vpc_cidr" { 17 | description = "VPC CIDR" 18 | type = string 19 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/cft-template/cft-template.tf: -------------------------------------------------------------------------------- 1 | resource "aws_s3_object" "cft-template" { 2 | bucket = var.bucket_name 3 | key = var.template_key 4 | source = var.template_source 5 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/cft-template/outputs.tf: -------------------------------------------------------------------------------- 1 | output "cft_template_key" { 2 | value = aws_s3_object.cft-template.key 3 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/cft-template/variables.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "Name of CFT Bucket" 3 | type = string 4 | } 5 | 6 | variable "template_key" { 7 | description = "Name of CFT Template" 8 | type = string 9 | } 10 | 11 | variable "template_source" { 12 | description = "Location of CFT Template" 13 | type = string 14 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/tf-state/tf-state.tf: -------------------------------------------------------------------------------- 1 | resource "aws_s3_bucket" "terraform_state" { 2 | bucket = var.bucket_name 3 | force_destroy = true 4 | } 5 | 6 | resource "aws_s3_bucket_versioning" "terraform_bucket_versioning" { 7 | bucket = aws_s3_bucket.terraform_state.id 8 | versioning_configuration { 9 | status = "Enabled" 10 | } 11 | } 12 | 13 | resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_crypto_conf" { 14 | bucket = aws_s3_bucket.terraform_state.bucket 15 | rule { 16 | apply_server_side_encryption_by_default { 17 | sse_algorithm = "AES256" 18 | } 19 | } 20 | } 21 | 22 | resource "aws_dynamodb_table" "terraform_locks" { 23 | name = var.table_name 24 | billing_mode = "PAY_PER_REQUEST" 25 | hash_key = "LockID" 26 | attribute { 27 | name = "LockID" 28 | type = "S" 29 | } 30 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/modules/tf-state/variables.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "Remote S3 Bucket Name" 3 | type = string 4 | validation { 5 | condition = can(regex("^([a-z0-9]{1}[a-z0-9-]{1,61}[a-z0-9]{1})$", var.bucket_name)) 6 | error_message = "Bucket Name must not be empty and must follow S3 naming rules." 7 | } 8 | } 9 | 10 | variable "table_name" { 11 | description = "Remote DynamoDB Table Name" 12 | type = string 13 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/providers.tf: -------------------------------------------------------------------------------- 1 | # Configure the AWS Provider 2 | provider "aws" { 3 | region = "us-east-1" 4 | } -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/terraform.tfvars: -------------------------------------------------------------------------------- 1 | cft_bucket_name = "cc-demo-cft-bkt" 2 | cft_template_name = "template.yaml" 3 | cft_template_location = "../cft/template.yaml" 4 | cft_stack_name = "cc-demo-cft-stack" 5 | 6 | vpc_name = "ccVPC" 7 | vpc_cidr = "10.0.0.0/16" -------------------------------------------------------------------------------- /src/6_Terraform_and_CloudFormation/tf/variables.tf: -------------------------------------------------------------------------------- 1 | variable "cft_bucket_name" { 2 | description = "Name of CFT Bucket" 3 | type = string 4 | } 5 | 6 | variable "cft_template_name" { 7 | description = "Name of CFT Template" 8 | type = string 9 | } 10 | 11 | variable "cft_template_location" { 12 | description = "Location of CFT Template" 13 | type = string 14 | } 15 | 16 | variable "cft_stack_name" { 17 | description = "Name of CFT Stack" 18 | type = string 19 | } 20 | 21 | variable "vpc_name" { 22 | description = "Name of VPC" 23 | type = string 24 | } 25 | 26 | variable "vpc_cidr" { 27 | description = "VPC CIDR" 28 | type = string 29 | } 30 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/chromedriver/chromedriver: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CumulusCycles/IaC_on_AWS_with_Terraform/281dcc2359791ac5037b0328eb2fcf38a65b46f4/src/7_Terraform_AWS_Lambda_with_Layers/chromedriver/chromedriver -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/chromedriver/headless-chromium: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CumulusCycles/IaC_on_AWS_with_Terraform/281dcc2359791ac5037b0328eb2fcf38a65b46f4/src/7_Terraform_AWS_Lambda_with_Layers/chromedriver/headless-chromium -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | lambda_iam_policy_name = "lambda_iam_policy" 3 | lambda_iam_policy_path = "./modules/iam/lambda-iam-policy.json" 4 | lambda_iam_role_name = "lambda_iam_role" 5 | lambda_iam_role_path = "./modules/iam/lambda-assume-role-policy.json" 6 | 7 | path_to_selenium_layer_source = "./selenium" 8 | path_to_selenium_layer_artifact = "./artifacts/selenium.zip" 9 | path_to_selenium_layer_filename = "./artifacts/selenium.zip" 10 | selenium_layer_name = "selenium" 11 | 12 | path_to_chromedriver_layer_source = "./chromedriver" 13 | path_to_chromedriver_layer_artifact = "./artifacts/chromedriver.zip" 14 | path_to_chromedriver_layer_filename = "./artifacts/chromedriver.zip" 15 | chromedriver_layer_name = "chromedriver" 16 | 17 | compatible_layer_runtimes = ["python3.7"] 18 | compatible_architectures = ["x86_64"] 19 | 20 | path_to_source_file = "./src/scrape.py" 21 | path_to_artifact = "./artifacts/scrape.zip" 22 | function_name = "scrape" 23 | function_handler = "scrape.get_rankings" 24 | memory_size = 512 25 | timeout = 300 26 | runtime = "python3.7" 27 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.3" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = "~> 5.0" 7 | } 8 | } 9 | } 10 | 11 | module "seleniumLayer" { 12 | source = "./modules/selenium_layer" 13 | 14 | path_to_selenium_layer_source = local.path_to_selenium_layer_source 15 | path_to_selenium_layer_artifact = local.path_to_selenium_layer_artifact 16 | path_to_selenium_layer_filename = local.path_to_selenium_layer_filename 17 | selenium_layer_name = local.selenium_layer_name 18 | compatible_layer_runtimes = local.compatible_layer_runtimes 19 | compatible_architectures = local.compatible_architectures 20 | } 21 | 22 | module "chromedriverLayer" { 23 | source = "./modules/chromedriver_layer" 24 | 25 | path_to_chromedriver_layer_source = local.path_to_chromedriver_layer_source 26 | path_to_chromedriver_layer_artifact = local.path_to_chromedriver_layer_artifact 27 | path_to_chromedriver_layer_filename = local.path_to_chromedriver_layer_filename 28 | chromedriver_layer_name = local.chromedriver_layer_name 29 | compatible_layer_runtimes = local.compatible_layer_runtimes 30 | compatible_architectures = local.compatible_architectures 31 | } 32 | 33 | module "lambdaIAM" { 34 | source = "./modules/iam" 35 | 36 | lambda_iam_policy_name = local.lambda_iam_policy_name 37 | lambda_iam_policy_path = local.lambda_iam_policy_path 38 | lambda_iam_role_name = local.lambda_iam_role_name 39 | lambda_iam_role_path = local.lambda_iam_role_path 40 | } 41 | 42 | module "lambdaFunction" { 43 | source = "./modules/lambda" 44 | 45 | lambda_iam_role_arn = module.lambdaIAM.lambda_iam_role_arn 46 | path_to_source_file = local.path_to_source_file 47 | path_to_artifact = local.path_to_artifact 48 | function_name = local.function_name 49 | function_handler = local.function_handler 50 | memory_size = local.memory_size 51 | timeout = local.timeout 52 | runtime = local.runtime 53 | lambda_layer_arns = [module.seleniumLayer.selenium_layer_arn, module.chromedriverLayer.chromedriver_layer_arn] 54 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/chromedriver_layer/main.tf: -------------------------------------------------------------------------------- 1 | data "archive_file" "layer" { 2 | type = "zip" 3 | source_dir = var.path_to_chromedriver_layer_source 4 | output_path = var.path_to_chromedriver_layer_artifact 5 | } 6 | 7 | resource "aws_lambda_layer_version" "chromedriver_layer" { 8 | filename = var.path_to_chromedriver_layer_filename 9 | layer_name = var.chromedriver_layer_name 10 | 11 | compatible_runtimes = var.compatible_layer_runtimes 12 | compatible_architectures = var.compatible_architectures 13 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/chromedriver_layer/outputs.tf: -------------------------------------------------------------------------------- 1 | output "chromedriver_layer_arn" { 2 | value = aws_lambda_layer_version.chromedriver_layer.arn 3 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/chromedriver_layer/variables.tf: -------------------------------------------------------------------------------- 1 | variable "path_to_chromedriver_layer_source" { 2 | description = "path_to_chromedriver_layer_source" 3 | type = string 4 | } 5 | 6 | variable "path_to_chromedriver_layer_artifact" { 7 | description = "path_to_chromedriver_layer_artifact" 8 | type = string 9 | } 10 | 11 | variable "path_to_chromedriver_layer_filename" { 12 | description = "path_to_chromedriver_layer_filename" 13 | type = string 14 | } 15 | 16 | variable "chromedriver_layer_name" { 17 | description = "chromedriver_layer_name" 18 | type = string 19 | } 20 | 21 | variable "compatible_layer_runtimes" { 22 | description = "compatible_layer_runtimes" 23 | type = list(string) 24 | } 25 | 26 | variable "compatible_architectures" { 27 | description = "compatible_architectures" 28 | type = list(string) 29 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/iam/lambda-assume-role-policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Action": "sts:AssumeRole", 6 | "Effect": "Allow", 7 | "Principal": { 8 | "Service": "lambda.amazonaws.com" 9 | } 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/iam/lambda-iam-policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Action": [ 6 | "logs:*" 7 | ], 8 | "Effect": "Allow", 9 | "Resource": "*" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/iam/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_iam_role_policy" "lambda_iam_policy" { 2 | name = var.lambda_iam_policy_name 3 | role = aws_iam_role.lambda_iam_role.id 4 | 5 | policy = file(var.lambda_iam_policy_path) 6 | } 7 | 8 | resource "aws_iam_role" "lambda_iam_role" { 9 | name = var.lambda_iam_role_name 10 | 11 | assume_role_policy = file(var.lambda_iam_role_path) 12 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/iam/outputs.tf: -------------------------------------------------------------------------------- 1 | output "lambda_iam_role_arn" { 2 | value = aws_iam_role.lambda_iam_role.arn 3 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/iam/variables.tf: -------------------------------------------------------------------------------- 1 | variable "lambda_iam_policy_name" { 2 | description = "Name of Lambda IAM Policy" 3 | type = string 4 | } 5 | 6 | variable "lambda_iam_policy_path" { 7 | description = "Path to Lambda IAM Policy JSON File" 8 | type = string 9 | } 10 | 11 | variable "lambda_iam_role_name" { 12 | description = "Name of Lambda IAM Role" 13 | type = string 14 | } 15 | 16 | variable "lambda_iam_role_path" { 17 | description = "Path to Lambda IAM Role JSON File" 18 | type = string 19 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/lambda/main.tf: -------------------------------------------------------------------------------- 1 | data "archive_file" "scrape" { 2 | type = "zip" 3 | source_file = var.path_to_source_file 4 | output_path = var.path_to_artifact 5 | } 6 | 7 | resource "aws_lambda_function" "rankings_lambda" { 8 | filename = var.path_to_artifact 9 | function_name = var.function_name 10 | role = var.lambda_iam_role_arn 11 | handler = var.function_handler 12 | 13 | memory_size = var.memory_size 14 | timeout = var.timeout 15 | 16 | source_code_hash = filebase64sha256(var.path_to_artifact) 17 | 18 | runtime = var.runtime 19 | 20 | layers = var.lambda_layer_arns 21 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/lambda/variables.tf: -------------------------------------------------------------------------------- 1 | variable "lambda_iam_role_arn" { 2 | description = "Lambda IAM Role ARN" 3 | type = string 4 | } 5 | 6 | variable "path_to_source_file" { 7 | description = "Path to Lambda Fucntion Source Code" 8 | type = string 9 | } 10 | 11 | variable "path_to_artifact" { 12 | description = "Path to ZIP artifact" 13 | type = string 14 | } 15 | 16 | variable "function_name" { 17 | description = "Name of Lambda Function" 18 | type = string 19 | } 20 | 21 | variable "function_handler" { 22 | description = "Name of Lambda Function Handler" 23 | type = string 24 | } 25 | 26 | variable "memory_size" { 27 | description = "Lambda Memory" 28 | type = number 29 | } 30 | 31 | variable "timeout" { 32 | description = "Lambda Timeout" 33 | type = number 34 | } 35 | 36 | variable "runtime" { 37 | description = "Lambda Runtime" 38 | type = string 39 | } 40 | 41 | variable "lambda_layer_arns" { 42 | description = "lambda_layer_arns" 43 | type = list(string) 44 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/selenium_layer/main.tf: -------------------------------------------------------------------------------- 1 | data "archive_file" "layer" { 2 | type = "zip" 3 | source_dir = var.path_to_selenium_layer_source 4 | output_path = var.path_to_selenium_layer_artifact 5 | } 6 | 7 | resource "aws_lambda_layer_version" "selenium_layer" { 8 | filename = var.path_to_selenium_layer_filename 9 | layer_name = var.selenium_layer_name 10 | 11 | compatible_runtimes = var.compatible_layer_runtimes 12 | compatible_architectures = var.compatible_architectures 13 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/selenium_layer/outputs.tf: -------------------------------------------------------------------------------- 1 | output "selenium_layer_arn" { 2 | value = aws_lambda_layer_version.selenium_layer.arn 3 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/modules/selenium_layer/variables.tf: -------------------------------------------------------------------------------- 1 | variable "path_to_selenium_layer_source" { 2 | description = "path_to_selenium_layer_source" 3 | type = string 4 | } 5 | 6 | variable "path_to_selenium_layer_artifact" { 7 | description = "path_to_selenium_layer_artifact" 8 | type = string 9 | } 10 | 11 | variable "path_to_selenium_layer_filename" { 12 | description = "path_to_selenium_layer_filename" 13 | type = string 14 | } 15 | 16 | variable "selenium_layer_name" { 17 | description = "selenium_layer_name" 18 | type = string 19 | } 20 | 21 | variable "compatible_layer_runtimes" { 22 | description = "compatible_layer_runtimes" 23 | type = list(string) 24 | } 25 | 26 | variable "compatible_architectures" { 27 | description = "compatible_architectures" 28 | type = list(string) 29 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium-3.8.0.dist-info/INSTALLER: -------------------------------------------------------------------------------- 1 | pip 2 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium-3.8.0.dist-info/REQUESTED: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CumulusCycles/IaC_on_AWS_with_Terraform/281dcc2359791ac5037b0328eb2fcf38a65b46f4/src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium-3.8.0.dist-info/REQUESTED -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium-3.8.0.dist-info/WHEEL: -------------------------------------------------------------------------------- 1 | Wheel-Version: 1.0 2 | Generator: bdist_wheel (0.30.0) 3 | Root-Is-Purelib: true 4 | Tag: py2-none-any 5 | Tag: py3-none-any 6 | 7 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium-3.8.0.dist-info/metadata.json: -------------------------------------------------------------------------------- 1 | {"classifiers": ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: POSIX", "Operating System :: Microsoft :: Windows", "Operating System :: MacOS :: MacOS X", "Topic :: Software Development :: Testing", "Topic :: Software Development :: Libraries", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6"], "description_content_type": "UNKNOWN", "extensions": {"python.details": {"document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/SeleniumHQ/selenium/"}}}, "generator": "bdist_wheel (0.30.0)", "license": "Apache 2.0", "metadata_version": "2.0", "name": "selenium", "summary": "Python bindings for Selenium", "version": "3.8.0"} -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium-3.8.0.dist-info/top_level.txt: -------------------------------------------------------------------------------- 1 | selenium 2 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | 19 | __version__ = "3.8.0" 20 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/common/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from . import exceptions # noqa 19 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from .firefox.webdriver import WebDriver as Firefox # noqa 19 | from .firefox.firefox_profile import FirefoxProfile # noqa 20 | from .firefox.options import Options as FirefoxOptions # noqa 21 | from .chrome.webdriver import WebDriver as Chrome # noqa 22 | from .chrome.options import Options as ChromeOptions # noqa 23 | from .ie.webdriver import WebDriver as Ie # noqa 24 | from .edge.webdriver import WebDriver as Edge # noqa 25 | from .opera.webdriver import WebDriver as Opera # noqa 26 | from .safari.webdriver import WebDriver as Safari # noqa 27 | from .blackberry.webdriver import WebDriver as BlackBerry # noqa 28 | from .phantomjs.webdriver import WebDriver as PhantomJS # noqa 29 | from .android.webdriver import WebDriver as Android # noqa 30 | from .webkitgtk.webdriver import WebDriver as WebKitGTK # noqa 31 | from .webkitgtk.options import Options as WebKitGTKOptions # noqa 32 | from .remote.webdriver import WebDriver as Remote # noqa 33 | from .common.desired_capabilities import DesiredCapabilities # noqa 34 | from .common.action_chains import ActionChains # noqa 35 | from .common.touch_actions import TouchActions # noqa 36 | from .common.proxy import Proxy # noqa 37 | 38 | __version__ = '3.8.0' 39 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/android/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/android/webdriver.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver 19 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 20 | 21 | 22 | class WebDriver(RemoteWebDriver): 23 | """ 24 | Simple RemoteWebDriver wrapper to start connect to Selendroid's WebView app 25 | 26 | For more info on getting started with Selendroid 27 | http://selendroid.io/mobileWeb.html 28 | """ 29 | 30 | def __init__(self, host="localhost", port=4444, desired_capabilities=DesiredCapabilities.ANDROID): 31 | """ 32 | Creates a new instance of Selendroid using the WebView app 33 | 34 | :Args: 35 | - host - location of where selendroid is running 36 | - port - port that selendroid is running on 37 | - desired_capabilities: Dictionary object with capabilities 38 | """ 39 | RemoteWebDriver.__init__( 40 | self, 41 | command_executor="http://%s:%d/wd/hub" % (host, port), 42 | desired_capabilities=desired_capabilities) 43 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/blackberry/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/chrome/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/chrome/remote_connection.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.remote.remote_connection import RemoteConnection 19 | 20 | 21 | class ChromeRemoteConnection(RemoteConnection): 22 | 23 | def __init__(self, remote_server_addr, keep_alive=True): 24 | RemoteConnection.__init__(self, remote_server_addr, keep_alive) 25 | self._commands["launchApp"] = ('POST', '/session/$sessionId/chromium/launch_app') 26 | self._commands["setNetworkConditions"] = ('POST', '/session/$sessionId/chromium/network_conditions') 27 | self._commands["getNetworkConditions"] = ('GET', '/session/$sessionId/chromium/network_conditions') 28 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/chrome/service.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.common import service 19 | 20 | 21 | class Service(service.Service): 22 | """ 23 | Object that manages the starting and stopping of the ChromeDriver 24 | """ 25 | 26 | def __init__(self, executable_path, port=0, service_args=None, 27 | log_path=None, env=None): 28 | """ 29 | Creates a new instance of the Service 30 | 31 | :Args: 32 | - executable_path : Path to the ChromeDriver 33 | - port : Port the service is running on 34 | - service_args : List of args to pass to the chromedriver service 35 | - log_path : Path for the chromedriver service to log to""" 36 | 37 | self.service_args = service_args or [] 38 | if log_path: 39 | self.service_args.append('--log-path=%s' % log_path) 40 | 41 | service.Service.__init__(self, executable_path, port=port, env=env, 42 | start_error_message="Please see https://sites.google.com/a/chromium.org/chromedriver/home") 43 | 44 | def command_line_args(self): 45 | return ["--port=%d" % self.port] + self.service_args 46 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/action_builder.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.remote.command import Command 19 | from . import interaction 20 | from .key_actions import KeyActions 21 | from .key_input import KeyInput 22 | from .pointer_actions import PointerActions 23 | from .pointer_input import PointerInput 24 | 25 | 26 | class ActionBuilder(object): 27 | def __init__(self, driver, mouse=None, keyboard=None): 28 | if mouse is None: 29 | mouse = PointerInput(interaction.POINTER, "mouse") 30 | if keyboard is None: 31 | keyboard = KeyInput(interaction.KEY) 32 | self.devices = [mouse, keyboard] 33 | self._key_action = KeyActions(keyboard) 34 | self._pointer_action = PointerActions(mouse) 35 | self.driver = driver 36 | 37 | def get_device_with(self, name): 38 | try: 39 | idx = self.devices.index(name) 40 | return self.devices[idx] 41 | except: 42 | pass 43 | 44 | @property 45 | def pointer_inputs(self): 46 | return [device for device in self.devices if device.type == interaction.POINTER] 47 | 48 | @property 49 | def key_inputs(self): 50 | return [device for device in self.devices if device.type == interaction.KEY] 51 | 52 | @property 53 | def key_action(self): 54 | return self._key_action 55 | 56 | @property 57 | def pointer_action(self): 58 | return self._pointer_action 59 | 60 | def add_key_input(self, name): 61 | new_input = KeyInput(name) 62 | self._add_input(new_input) 63 | return new_input 64 | 65 | def add_pointer_input(self, type_, name): 66 | new_input = PointerInput(type_, name) 67 | self._add_input(new_input) 68 | return new_input 69 | 70 | def perform(self): 71 | enc = {"actions": []} 72 | for device in self.devices: 73 | encoded = device.encode() 74 | if encoded['actions']: 75 | enc["actions"].append(encoded) 76 | self.driver.execute(Command.W3C_ACTIONS, enc) 77 | 78 | def clear_actions(self): 79 | self.driver.execute(Command.W3C_CLEAR_ACTIONS) 80 | 81 | def _add_input(self, input): 82 | self.devices.append(input) 83 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/input_device.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | import uuid 19 | 20 | 21 | class InputDevice(object): 22 | """ 23 | Describes the input device being used for the action. 24 | """ 25 | def __init__(self, name=None): 26 | if name is None: 27 | self.name = uuid.uuid4() 28 | else: 29 | self.name = name 30 | 31 | self.actions = [] 32 | 33 | def add_action(self, action): 34 | """ 35 | 36 | """ 37 | self.actions.append(action) 38 | 39 | def clear_actions(self): 40 | self.actions = [] 41 | 42 | def create_pause(self, duraton=0): 43 | pass 44 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/interaction.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | 19 | KEY = "key" 20 | POINTER = "pointer" 21 | NONE = "none" 22 | SOURCE_TYPES = set([KEY, POINTER, NONE]) 23 | 24 | 25 | class Interaction(object): 26 | 27 | PAUSE = "pause" 28 | 29 | def __init__(self, source): 30 | self.source = source 31 | 32 | 33 | class Pause(Interaction): 34 | 35 | def __init__(self, source, duration=0): 36 | super(Interaction, self).__init__() 37 | self.source = source 38 | self.duration = duration 39 | 40 | def encode(self): 41 | output = {"type": self.PAUSE} 42 | output["duration"] = self.duration * 1000 43 | return output 44 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/key_actions.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | from .interaction import Interaction 18 | from .key_input import KeyInput 19 | from ..utils import keys_to_typing 20 | 21 | 22 | class KeyActions(Interaction): 23 | 24 | def __init__(self, source=None): 25 | if source is None: 26 | source = KeyInput() 27 | self.source = source 28 | super(KeyActions, self).__init__(source) 29 | 30 | def key_down(self, letter, element=None): 31 | return self._key_action("create_key_down", 32 | letter, element) 33 | 34 | def key_up(self, letter, element=None): 35 | return self._key_action("create_key_up", 36 | letter, element) 37 | 38 | def pause(self, duration=0): 39 | return self._key_action("create_pause", duration) 40 | 41 | def send_keys(self, text, element=None): 42 | if not isinstance(text, list): 43 | text = keys_to_typing(text) 44 | for letter in text: 45 | self.key_down(letter, element) 46 | self.key_up(letter, element) 47 | return self 48 | 49 | def _key_action(self, action, letter, element=None): 50 | meth = getattr(self.source, action) 51 | meth(letter) 52 | return self 53 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/key_input.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | from . import interaction 18 | 19 | from .input_device import InputDevice 20 | from .interaction import (Interaction, 21 | Pause) 22 | 23 | 24 | class KeyInput(InputDevice): 25 | def __init__(self, name): 26 | super(KeyInput, self).__init__() 27 | self.name = name 28 | self.type = interaction.KEY 29 | 30 | def encode(self): 31 | return {"type": self.type, "id": self.name, "actions": [acts.encode() for acts in self.actions]} 32 | 33 | def create_key_down(self, key): 34 | self.add_action(TypingInteraction(self, "keyDown", key)) 35 | 36 | def create_key_up(self, key): 37 | self.add_action(TypingInteraction(self, "keyUp", key)) 38 | 39 | def create_pause(self, pause_duration=0): 40 | self.add_action(Pause(self, pause_duration)) 41 | 42 | 43 | class TypingInteraction(Interaction): 44 | 45 | def __init__(self, source, type_, key): 46 | super(TypingInteraction, self).__init__(source) 47 | self.type = type_ 48 | self.key = key 49 | 50 | def encode(self): 51 | return {"type": self.type, "value": self.key} 52 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/mouse_button.py: -------------------------------------------------------------------------------- 1 | class MouseButton(object): 2 | 3 | LEFT = 0 4 | MIDDLE = 1 5 | RIGHT = 2 6 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/pointer_actions.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | from . import interaction 18 | 19 | from .interaction import Interaction 20 | from .mouse_button import MouseButton 21 | from .pointer_input import PointerInput 22 | 23 | from selenium.webdriver.remote.webelement import WebElement 24 | 25 | 26 | class PointerActions(Interaction): 27 | 28 | def __init__(self, source=None): 29 | if source is None: 30 | source = PointerInput(interaction.POINTER, "mouse") 31 | self.source = source 32 | super(PointerActions, self).__init__(source) 33 | 34 | def pointer_down(self, button=MouseButton.LEFT): 35 | self._button_action("create_pointer_down", button=button) 36 | 37 | def pointer_up(self, button=MouseButton.LEFT): 38 | self._button_action("create_pointer_up", button=button) 39 | 40 | def move_to(self, element, x=None, y=None): 41 | if not isinstance(element, WebElement): 42 | raise AttributeError("move_to requires a WebElement") 43 | if x is not None or y is not None: 44 | el_rect = element.rect 45 | left_offset = el_rect['width'] / 2 46 | top_offset = el_rect['height'] / 2 47 | left = -left_offset + (x or 0) 48 | top = -top_offset + (y or 0) 49 | else: 50 | left = 0 51 | top = 0 52 | self.source.create_pointer_move(origin=element, x=int(left), y=int(top)) 53 | return self 54 | 55 | def move_by(self, x, y): 56 | self.source.create_pointer_move(origin=interaction.POINTER, x=int(x), y=int(y)) 57 | return self 58 | 59 | def move_to_location(self, x, y): 60 | self.source.create_pointer_move(origin='viewport', x=int(x), y=int(y)) 61 | return self 62 | 63 | def click(self, element=None): 64 | if element: 65 | self.move_to(element) 66 | self.pointer_down(MouseButton.LEFT) 67 | self.pointer_up(MouseButton.LEFT) 68 | return self 69 | 70 | def context_click(self, element=None): 71 | if element: 72 | self.move_to(element) 73 | self.pointer_down(MouseButton.RIGHT) 74 | self.pointer_up(MouseButton.RIGHT) 75 | return self 76 | 77 | def click_and_hold(self, element=None): 78 | if element: 79 | self.move_to(element) 80 | self.pointer_down() 81 | return self 82 | 83 | def release(self): 84 | self.pointer_up() 85 | return self 86 | 87 | def double_click(self, element=None): 88 | if element: 89 | self.move_to(element) 90 | self.click() 91 | self.click() 92 | 93 | def pause(self, duration=0): 94 | self.source.create_pause(duration) 95 | return self 96 | 97 | def _button_action(self, action, button=MouseButton.LEFT): 98 | meth = getattr(self.source, action) 99 | meth(button) 100 | return self 101 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/actions/pointer_input.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | from .input_device import InputDevice 18 | 19 | from selenium.webdriver.remote.webelement import WebElement 20 | 21 | 22 | class PointerInput(InputDevice): 23 | 24 | DEFAULT_MOVE_DURATION = 250 25 | 26 | def __init__(self, type_, name): 27 | super(PointerInput, self).__init__() 28 | self.type = type_ 29 | self.name = name 30 | 31 | def create_pointer_move(self, duration=DEFAULT_MOVE_DURATION, x=None, y=None, origin=None): 32 | action = dict(type="pointerMove", duration=duration) 33 | action["x"] = x 34 | action["y"] = y 35 | if isinstance(origin, WebElement): 36 | action["origin"] = {"element-6066-11e4-a52e-4f735466cecf": origin.id} 37 | elif origin is not None: 38 | action["origin"] = origin 39 | 40 | self.add_action(action) 41 | 42 | def create_pointer_down(self, button): 43 | self.add_action({"type": "pointerDown", "duration": 0, "button": button}) 44 | 45 | def create_pointer_up(self, button): 46 | self.add_action({"type": "pointerUp", "duration": 0, "button": button}) 47 | 48 | def create_pointer_cancel(self): 49 | self.add_action({"type": "pointerCancel"}) 50 | 51 | def create_pause(self, pause_duration): 52 | self.add_action({"type": "pause", "duration": pause_duration * 1000}) 53 | 54 | def encode(self): 55 | return {"type": self.type, 56 | "parameters": {"pointerType": self.name}, 57 | "id": self.name, 58 | "actions": [acts for acts in self.actions]} 59 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/by.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | """ 19 | The By implementation. 20 | """ 21 | 22 | 23 | class By(object): 24 | """ 25 | Set of supported locator strategies. 26 | """ 27 | 28 | ID = "id" 29 | XPATH = "xpath" 30 | LINK_TEXT = "link text" 31 | PARTIAL_LINK_TEXT = "partial link text" 32 | NAME = "name" 33 | TAG_NAME = "tag name" 34 | CLASS_NAME = "class name" 35 | CSS_SELECTOR = "css selector" 36 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/html5/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/html5/application_cache.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | """ 19 | The ApplicationCache implementaion. 20 | """ 21 | 22 | from selenium.webdriver.remote.command import Command 23 | 24 | 25 | class ApplicationCache(object): 26 | 27 | UNCACHED = 0 28 | IDLE = 1 29 | CHECKING = 2 30 | DOWNLOADING = 3 31 | UPDATE_READY = 4 32 | OBSOLETE = 5 33 | 34 | def __init__(self, driver): 35 | """ 36 | Creates a new Aplication Cache. 37 | 38 | :Args: 39 | - driver: The WebDriver instance which performs user actions. 40 | """ 41 | self.driver = driver 42 | 43 | @property 44 | def status(self): 45 | """ 46 | Returns a current status of application cache. 47 | """ 48 | return self.driver.execute(Command.GET_APP_CACHE_STATUS)['value'] 49 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/common/keys.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | """ 19 | The Keys implementation. 20 | """ 21 | 22 | from __future__ import unicode_literals 23 | 24 | 25 | class Keys(object): 26 | """ 27 | Set of special keys codes. 28 | """ 29 | 30 | NULL = '\ue000' 31 | CANCEL = '\ue001' # ^break 32 | HELP = '\ue002' 33 | BACKSPACE = '\ue003' 34 | BACK_SPACE = BACKSPACE 35 | TAB = '\ue004' 36 | CLEAR = '\ue005' 37 | RETURN = '\ue006' 38 | ENTER = '\ue007' 39 | SHIFT = '\ue008' 40 | LEFT_SHIFT = SHIFT 41 | CONTROL = '\ue009' 42 | LEFT_CONTROL = CONTROL 43 | ALT = '\ue00a' 44 | LEFT_ALT = ALT 45 | PAUSE = '\ue00b' 46 | ESCAPE = '\ue00c' 47 | SPACE = '\ue00d' 48 | PAGE_UP = '\ue00e' 49 | PAGE_DOWN = '\ue00f' 50 | END = '\ue010' 51 | HOME = '\ue011' 52 | LEFT = '\ue012' 53 | ARROW_LEFT = LEFT 54 | UP = '\ue013' 55 | ARROW_UP = UP 56 | RIGHT = '\ue014' 57 | ARROW_RIGHT = RIGHT 58 | DOWN = '\ue015' 59 | ARROW_DOWN = DOWN 60 | INSERT = '\ue016' 61 | DELETE = '\ue017' 62 | SEMICOLON = '\ue018' 63 | EQUALS = '\ue019' 64 | 65 | NUMPAD0 = '\ue01a' # number pad keys 66 | NUMPAD1 = '\ue01b' 67 | NUMPAD2 = '\ue01c' 68 | NUMPAD3 = '\ue01d' 69 | NUMPAD4 = '\ue01e' 70 | NUMPAD5 = '\ue01f' 71 | NUMPAD6 = '\ue020' 72 | NUMPAD7 = '\ue021' 73 | NUMPAD8 = '\ue022' 74 | NUMPAD9 = '\ue023' 75 | MULTIPLY = '\ue024' 76 | ADD = '\ue025' 77 | SEPARATOR = '\ue026' 78 | SUBTRACT = '\ue027' 79 | DECIMAL = '\ue028' 80 | DIVIDE = '\ue029' 81 | 82 | F1 = '\ue031' # function keys 83 | F2 = '\ue032' 84 | F3 = '\ue033' 85 | F4 = '\ue034' 86 | F5 = '\ue035' 87 | F6 = '\ue036' 88 | F7 = '\ue037' 89 | F8 = '\ue038' 90 | F9 = '\ue039' 91 | F10 = '\ue03a' 92 | F11 = '\ue03b' 93 | F12 = '\ue03c' 94 | 95 | META = '\ue03d' 96 | COMMAND = '\ue03d' 97 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/edge/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/edge/options.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 19 | 20 | 21 | class Options(object): 22 | 23 | def __init__(self): 24 | self._page_load_strategy = "normal" 25 | 26 | @property 27 | def page_load_strategy(self): 28 | return self._page_load_strategy 29 | 30 | @page_load_strategy.setter 31 | def page_load_strategy(self, value): 32 | if value not in ['normal', 'eager', 'none']: 33 | raise ValueError("Page Load Strategy should be 'normal', 'eager' or 'none'.") 34 | self._page_load_strategy = value 35 | 36 | def to_capabilities(self): 37 | """ 38 | Creates a capabilities with all the options that have been set and 39 | 40 | returns a dictionary with everything 41 | """ 42 | edge = DesiredCapabilities.EDGE.copy() 43 | edge['pageLoadStrategy'] = self._page_load_strategy 44 | 45 | return edge 46 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/edge/service.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.common import service 19 | 20 | 21 | class Service(service.Service): 22 | 23 | def __init__(self, executable_path, port=0, verbose=False, log_path=None): 24 | """ 25 | Creates a new instance of the EdgeDriver service. 26 | 27 | EdgeDriver provides an interface for Microsoft WebDriver to use 28 | with Microsoft Edge. 29 | 30 | :param executable_path: Path to the Microsoft WebDriver binary. 31 | :param port: Run the remote service on a specified port. 32 | Defaults to 0, which binds to a random open port of the 33 | system's choosing. 34 | :verbose: Whether to make the webdriver more verbose (passes the 35 | --verbose option to the binary). Defaults to False. 36 | :param log_path: Optional path for the webdriver binary to log to. 37 | Defaults to None which disables logging. 38 | 39 | """ 40 | 41 | self.service_args = [] 42 | if verbose: 43 | self.service_args.append("--verbose") 44 | 45 | params = { 46 | "executable": executable_path, 47 | "port": port, 48 | "start_error_message": "Please download from http://go.microsoft.com/fwlink/?LinkId=619687" 49 | } 50 | 51 | if log_path: 52 | params["log_file"] = open(log_path, "a+") 53 | 54 | service.Service.__init__(self, **params) 55 | 56 | def command_line_args(self): 57 | return ["--port=%d" % self.port] + self.service_args 58 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/edge/webdriver.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.common import utils 19 | from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver 20 | from selenium.webdriver.remote.remote_connection import RemoteConnection 21 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 22 | from .service import Service 23 | 24 | 25 | class WebDriver(RemoteWebDriver): 26 | 27 | def __init__(self, executable_path='MicrosoftWebDriver.exe', 28 | capabilities=None, port=0, verbose=False, log_path=None): 29 | self.port = port 30 | if self.port == 0: 31 | self.port = utils.free_port() 32 | 33 | self.edge_service = Service(executable_path, port=self.port, verbose=verbose, log_path=log_path) 34 | self.edge_service.start() 35 | 36 | if capabilities is None: 37 | capabilities = DesiredCapabilities.EDGE 38 | 39 | RemoteWebDriver.__init__( 40 | self, 41 | command_executor=RemoteConnection('http://localhost:%d' % self.port, 42 | resolve_ip=False), 43 | desired_capabilities=capabilities) 44 | self._is_remote = False 45 | 46 | def quit(self): 47 | RemoteWebDriver.quit(self) 48 | self.edge_service.stop() 49 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/amd64/x_ignore_nofocus.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CumulusCycles/IaC_on_AWS_with_Terraform/281dcc2359791ac5037b0328eb2fcf38a65b46f4/src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/amd64/x_ignore_nofocus.so -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/extension_connection.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | import logging 19 | import time 20 | 21 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 22 | from selenium.webdriver.common import utils 23 | from selenium.webdriver.remote.command import Command 24 | from selenium.webdriver.remote.remote_connection import RemoteConnection 25 | from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 26 | 27 | LOGGER = logging.getLogger(__name__) 28 | PORT = 0 29 | HOST = None 30 | _URL = "" 31 | 32 | 33 | class ExtensionConnection(RemoteConnection): 34 | def __init__(self, host, firefox_profile, firefox_binary=None, timeout=30): 35 | self.profile = firefox_profile 36 | self.binary = firefox_binary 37 | HOST = host 38 | timeout = int(timeout) 39 | 40 | if self.binary is None: 41 | self.binary = FirefoxBinary() 42 | 43 | if HOST is None: 44 | HOST = "127.0.0.1" 45 | 46 | PORT = utils.free_port() 47 | self.profile.port = PORT 48 | self.profile.update_preferences() 49 | 50 | self.profile.add_extension() 51 | 52 | self.binary.launch_browser(self.profile, timeout=timeout) 53 | _URL = "http://%s:%d/hub" % (HOST, PORT) 54 | RemoteConnection.__init__( 55 | self, _URL, keep_alive=True) 56 | 57 | def quit(self, sessionId=None): 58 | self.execute(Command.QUIT, {'sessionId': sessionId}) 59 | while self.is_connectable(): 60 | LOGGER.info("waiting to quit") 61 | time.sleep(1) 62 | 63 | def connect(self): 64 | """Connects to the extension and retrieves the session id.""" 65 | return self.execute(Command.NEW_SESSION, 66 | {'desiredCapabilities': DesiredCapabilities.FIREFOX}) 67 | 68 | @classmethod 69 | def connect_and_quit(self): 70 | """Connects to an running browser and quit immediately.""" 71 | self._request('%s/extensions/firefox/quit' % _URL) 72 | 73 | @classmethod 74 | def is_connectable(self): 75 | """Trys to connect to the extension but do not retrieve context.""" 76 | utils.is_connectable(self.profile.port) 77 | 78 | 79 | class ExtensionConnectionError(Exception): 80 | """An internal error occurred int the extension. 81 | 82 | Might be caused by bad input or bugs in webdriver 83 | """ 84 | pass 85 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/remote_connection.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.remote.remote_connection import RemoteConnection 19 | 20 | 21 | class FirefoxRemoteConnection(RemoteConnection): 22 | def __init__(self, remote_server_addr, keep_alive=True): 23 | RemoteConnection.__init__(self, remote_server_addr, keep_alive) 24 | 25 | self._commands["GET_CONTEXT"] = ('GET', '/session/$sessionId/moz/context') 26 | self._commands["SET_CONTEXT"] = ("POST", "/session/$sessionId/moz/context") 27 | self._commands["ELEMENT_GET_ANONYMOUS_CHILDREN"] = \ 28 | ("POST", "/session/$sessionId/moz/xbl/$id/anonymous_children") 29 | self._commands["ELEMENT_FIND_ANONYMOUS_ELEMENTS_BY_ATTRIBUTE"] = \ 30 | ("POST", "/session/$sessionId/moz/xbl/$id/anonymous_by_attribute") 31 | self._commands["INSTALL_ADDON"] = \ 32 | ("POST", "/session/$sessionId/moz/addon/install") 33 | self._commands["UNINSTALL_ADDON"] = \ 34 | ("POST", "/session/$sessionId/moz/addon/uninstall") 35 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/service.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.common import service 19 | 20 | 21 | class Service(service.Service): 22 | """Object that manages the starting and stopping of the 23 | GeckoDriver.""" 24 | 25 | def __init__(self, executable_path, port=0, service_args=None, 26 | log_path="geckodriver.log", env=None): 27 | """Creates a new instance of the GeckoDriver remote service proxy. 28 | 29 | GeckoDriver provides a HTTP interface speaking the W3C WebDriver 30 | protocol to Marionette. 31 | 32 | :param executable_path: Path to the GeckoDriver binary. 33 | :param port: Run the remote service on a specified port. 34 | Defaults to 0, which binds to a random open port of the 35 | system's choosing. 36 | :param service_args: Optional list of arguments to pass to the 37 | GeckoDriver binary. 38 | :param log_path: Optional path for the GeckoDriver to log to. 39 | Defaults to _geckodriver.log_ in the current working directory. 40 | :param env: Optional dictionary of output variables to expose 41 | in the services' environment. 42 | 43 | """ 44 | log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None 45 | 46 | service.Service.__init__( 47 | self, executable_path, port=port, log_file=log_file, env=env) 48 | self.service_args = service_args or [] 49 | 50 | def command_line_args(self): 51 | return ["--port", "%d" % self.port] + self.service_args 52 | 53 | def send_remote_shutdown_command(self): 54 | pass 55 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.xpi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CumulusCycles/IaC_on_AWS_with_Terraform/281dcc2359791ac5037b0328eb2fcf38a65b46f4/src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.xpi -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver_prefs.json: -------------------------------------------------------------------------------- 1 | { 2 | "frozen": { 3 | "app.update.auto": false, 4 | "app.update.enabled": false, 5 | "browser.displayedE10SNotice": 4, 6 | "browser.download.manager.showWhenStarting": false, 7 | "browser.EULA.override": true, 8 | "browser.EULA.3.accepted": true, 9 | "browser.link.open_external": 2, 10 | "browser.link.open_newwindow": 2, 11 | "browser.offline": false, 12 | "browser.reader.detectedFirstArticle": true, 13 | "browser.safebrowsing.enabled": false, 14 | "browser.safebrowsing.malware.enabled": false, 15 | "browser.search.update": false, 16 | "browser.selfsupport.url" : "", 17 | "browser.sessionstore.resume_from_crash": false, 18 | "browser.shell.checkDefaultBrowser": false, 19 | "browser.tabs.warnOnClose": false, 20 | "browser.tabs.warnOnOpen": false, 21 | "datareporting.healthreport.service.enabled": false, 22 | "datareporting.healthreport.uploadEnabled": false, 23 | "datareporting.healthreport.service.firstRun": false, 24 | "datareporting.healthreport.logging.consoleEnabled": false, 25 | "datareporting.policy.dataSubmissionEnabled": false, 26 | "datareporting.policy.dataSubmissionPolicyAccepted": false, 27 | "devtools.errorconsole.enabled": true, 28 | "dom.disable_open_during_load": false, 29 | "extensions.autoDisableScopes": 10, 30 | "extensions.blocklist.enabled": false, 31 | "extensions.checkCompatibility.nightly": false, 32 | "extensions.logging.enabled": true, 33 | "extensions.update.enabled": false, 34 | "extensions.update.notifyUser": false, 35 | "javascript.enabled": true, 36 | "network.manage-offline-status": false, 37 | "network.http.phishy-userpass-length": 255, 38 | "offline-apps.allow_by_default": true, 39 | "prompts.tab_modal.enabled": false, 40 | "security.fileuri.origin_policy": 3, 41 | "security.fileuri.strict_origin_policy": false, 42 | "signon.rememberSignons": false, 43 | "toolkit.networkmanager.disable": true, 44 | "toolkit.telemetry.prompted": 2, 45 | "toolkit.telemetry.enabled": false, 46 | "toolkit.telemetry.rejected": true, 47 | "xpinstall.signatures.required": false, 48 | "xpinstall.whitelist.required": false 49 | }, 50 | "mutable": { 51 | "browser.dom.window.dump.enabled": true, 52 | "browser.laterrun.enabled": false, 53 | "browser.newtab.url": "about:blank", 54 | "browser.newtabpage.enabled": false, 55 | "browser.startup.page": 0, 56 | "browser.startup.homepage": "about:blank", 57 | "browser.startup.homepage_override.mstone": "ignore", 58 | "browser.usedOnWindows10.introURL": "about:blank", 59 | "dom.max_chrome_script_run_time": 30, 60 | "dom.max_script_run_time": 30, 61 | "dom.report_all_js_exceptions": true, 62 | "javascript.options.showInConsole": true, 63 | "network.captive-portal-service.enabled": false, 64 | "security.csp.enable": false, 65 | "startup.homepage_welcome_url": "about:blank", 66 | "startup.homepage_welcome_url.additional": "about:blank", 67 | "webdriver_accept_untrusted_certs": true, 68 | "webdriver_assume_untrusted_issuer": true 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/webelement.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.remote.webelement import WebElement as RemoteWebElement 19 | 20 | 21 | class FirefoxWebElement(RemoteWebElement): 22 | 23 | @property 24 | def anonymous_children(self): 25 | """Retrieve the anonymous children of this element in an XBL 26 | context. This is only available in chrome context. 27 | 28 | See the `anonymous content documentation 29 | `_ 30 | on MDN for more information. 31 | 32 | """ 33 | return self._execute( 34 | "ELEMENT_GET_ANONYMOUS_CHILDREN", 35 | {"value": None}) 36 | 37 | def find_anonymous_element_by_attribute(self, name, value): 38 | """Retrieve an anonymous descendant with a specified attribute 39 | value. Typically used with an (arbitrary) anonid attribute to 40 | retrieve a specific anonymous child in an XBL binding. 41 | 42 | See the `anonymous content documentation 43 | `_ 44 | on MDN for more information. 45 | 46 | """ 47 | return self._execute( 48 | "ELEMENT_FIND_ANONYMOUS_ELEMENTS_BY_ATTRIBUTE", 49 | {"name": name, "value": value})["value"] 50 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/x86/x_ignore_nofocus.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CumulusCycles/IaC_on_AWS_with_Terraform/281dcc2359791ac5037b0328eb2fcf38a65b46f4/src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/firefox/x86/x_ignore_nofocus.so -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/ie/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/ie/service.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.common import service 19 | 20 | 21 | class Service(service.Service): 22 | """ 23 | Object that manages the starting and stopping of the IEDriver 24 | """ 25 | 26 | def __init__(self, executable_path, port=0, host=None, log_level=None, log_file=None): 27 | """ 28 | Creates a new instance of the Service 29 | 30 | :Args: 31 | - executable_path : Path to the IEDriver 32 | - port : Port the service is running on 33 | - host : IP address the service port is bound 34 | - log_level : Level of logging of service, may be "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE". 35 | Default is "FATAL". 36 | - log_file : Target of logging of service, may be "stdout", "stderr" or file path. 37 | Default is "stdout".""" 38 | self.service_args = [] 39 | if host is not None: 40 | self.service_args.append("--host=%s" % host) 41 | if log_level is not None: 42 | self.service_args.append("--log-level=%s" % log_level) 43 | if log_file is not None: 44 | self.service_args.append("--log-file=%s" % log_file) 45 | 46 | service.Service.__init__(self, executable_path, port=port, 47 | start_error_message="Please download from http://selenium-release.storage.googleapis.com/index.html and read up at https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver") 48 | 49 | def command_line_args(self): 50 | return ["--port=%d" % self.port] + self.service_args 51 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/ie/webdriver.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | import warnings 18 | 19 | from selenium.webdriver.common import utils 20 | from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver 21 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 22 | from .service import Service 23 | from .options import Options 24 | 25 | DEFAULT_TIMEOUT = 30 26 | DEFAULT_PORT = 0 27 | DEFAULT_HOST = None 28 | DEFAULT_LOG_LEVEL = None 29 | DEFAULT_LOG_FILE = None 30 | 31 | 32 | class WebDriver(RemoteWebDriver): 33 | """ Controls the IEServerDriver and allows you to drive Internet Explorer """ 34 | 35 | def __init__(self, executable_path='IEDriverServer.exe', capabilities=None, 36 | port=DEFAULT_PORT, timeout=DEFAULT_TIMEOUT, host=DEFAULT_HOST, 37 | log_level=DEFAULT_LOG_LEVEL, log_file=DEFAULT_LOG_FILE, options=None, 38 | ie_options=None): 39 | """ 40 | Creates a new instance of the chrome driver. 41 | 42 | Starts the service and then creates new instance of chrome driver. 43 | 44 | :Args: 45 | - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH 46 | - capabilities: capabilities Dictionary object 47 | - port - port you would like the service to run, if left as 0, a free port will be found. 48 | - log_level - log level you would like the service to run. 49 | - log_file - log file you would like the service to log to. 50 | - options: IE Options instance, providing additional IE options 51 | """ 52 | if ie_options: 53 | warnings.warn('use options instead of ie_options', DeprecationWarning) 54 | options = ie_options 55 | self.port = port 56 | if self.port == 0: 57 | self.port = utils.free_port() 58 | self.host = host 59 | self.log_level = log_level 60 | self.log_file = log_file 61 | 62 | if options is None: 63 | # desired_capabilities stays as passed in 64 | if capabilities is None: 65 | capabilities = self.create_options().to_capabilities() 66 | else: 67 | if capabilities is None: 68 | capabilities = options.to_capabilities() 69 | else: 70 | capabilities.update(options.to_capabilities()) 71 | 72 | self.iedriver = Service( 73 | executable_path, 74 | port=self.port, 75 | host=self.host, 76 | log_level=self.log_level, 77 | log_file=self.log_file) 78 | 79 | self.iedriver.start() 80 | 81 | if capabilities is None: 82 | capabilities = DesiredCapabilities.INTERNETEXPLORER 83 | 84 | RemoteWebDriver.__init__( 85 | self, 86 | command_executor='http://localhost:%d' % self.port, 87 | desired_capabilities=capabilities) 88 | self._is_remote = False 89 | 90 | def quit(self): 91 | RemoteWebDriver.quit(self) 92 | self.iedriver.stop() 93 | 94 | def create_options(self): 95 | return Options() 96 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/opera/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/opera/options.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.chrome.options import Options as ChromeOptions 19 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 20 | 21 | 22 | class Options(ChromeOptions): 23 | KEY = "operaOptions" 24 | 25 | def __init__(self): 26 | ChromeOptions.__init__(self) 27 | self._android_package_name = '' 28 | self._android_device_socket = '' 29 | self._android_command_line_file = '' 30 | 31 | @property 32 | def android_package_name(self): 33 | """ 34 | Returns the name of the Opera package 35 | """ 36 | return self._android_package_name 37 | 38 | @android_package_name.setter 39 | def android_package_name(self, value): 40 | """ 41 | Allows you to set the package name 42 | 43 | :Args: 44 | - value: devtools socket name 45 | """ 46 | self._android_package_name = value 47 | 48 | @property 49 | def android_device_socket(self): 50 | """ 51 | Returns the name of the devtools socket 52 | """ 53 | return self._android_device_socket 54 | 55 | @android_device_socket.setter 56 | def android_device_socket(self, value): 57 | """ 58 | Allows you to set the devtools socket name 59 | 60 | :Args: 61 | - value: devtools socket name 62 | """ 63 | self._android_device_socket = value 64 | 65 | @property 66 | def android_command_line_file(self): 67 | """ 68 | Returns the path of the command line file 69 | """ 70 | return self._android_command_line_file 71 | 72 | @android_command_line_file.setter 73 | def android_command_line_file(self, value): 74 | """ 75 | Allows you to set where the command line file lives 76 | 77 | :Args: 78 | - value: command line file path 79 | """ 80 | self._android_command_line_file = value 81 | 82 | def to_capabilities(self): 83 | """ 84 | Creates a capabilities with all the options that have been set and 85 | 86 | returns a dictionary with everything 87 | """ 88 | capabilities = ChromeOptions.to_capabilities(self) 89 | capabilities.update(DesiredCapabilities.OPERA) 90 | opera_options = capabilities[self.KEY] = capabilities.pop(ChromeOptions.KEY, None) 91 | 92 | if self.android_package_name: 93 | opera_options["androidPackage"] = self.android_package_name 94 | if self.android_device_socket: 95 | opera_options["androidDeviceSocket"] = self.android_device_socket 96 | if self.android_command_line_file: 97 | opera_options["androidCommandLineFile"] = \ 98 | self.android_command_line_file 99 | return capabilities 100 | 101 | 102 | class AndroidOptions(Options): 103 | 104 | def __init__(self): 105 | Options.__init__(self) 106 | self.android_package_name = 'com.opera.browser' 107 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/opera/webdriver.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | import warnings 18 | 19 | from selenium.webdriver.chrome.webdriver import WebDriver as ChromiumDriver 20 | from .options import Options 21 | 22 | 23 | class OperaDriver(ChromiumDriver): 24 | """Controls the new OperaDriver and allows you 25 | to drive the Opera browser based on Chromium.""" 26 | 27 | def __init__(self, executable_path=None, port=0, 28 | options=None, service_args=None, 29 | desired_capabilities=None, service_log_path=None, 30 | opera_options=None): 31 | """ 32 | Creates a new instance of the operadriver. 33 | 34 | Starts the service and then creates new instance of operadriver. 35 | 36 | :Args: 37 | - executable_path - path to the executable. If the default is used 38 | it assumes the executable is in the $PATH 39 | - port - port you would like the service to run, if left as 0, 40 | a free port will be found. 41 | - desired_capabilities: Dictionary object with non-browser specific 42 | capabilities only, such as "proxy" or "loggingPref". 43 | - options: this takes an instance of ChromeOptions 44 | """ 45 | if opera_options: 46 | warnings.warn('use options instead of opera_options', DeprecationWarning) 47 | options = opera_options 48 | 49 | executable_path = (executable_path if executable_path is not None 50 | else "operadriver") 51 | ChromiumDriver.__init__(self, 52 | executable_path=executable_path, 53 | port=port, 54 | options=options, 55 | service_args=service_args, 56 | desired_capabilities=desired_capabilities, 57 | service_log_path=service_log_path) 58 | 59 | def create_options(self): 60 | return Options() 61 | 62 | 63 | class WebDriver(OperaDriver): 64 | class ServiceType: 65 | CHROMIUM = 2 66 | 67 | def __init__(self, 68 | desired_capabilities=None, 69 | executable_path=None, 70 | port=0, 71 | service_log_path=None, 72 | service_args=None, 73 | options=None): 74 | OperaDriver.__init__(self, executable_path=executable_path, 75 | port=port, options=options, 76 | service_args=service_args, 77 | desired_capabilities=desired_capabilities, 78 | service_log_path=service_log_path) 79 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/phantomjs/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/phantomjs/service.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | import os 18 | import tempfile 19 | from selenium.webdriver.common import service 20 | 21 | 22 | class Service(service.Service): 23 | """ 24 | Object that manages the starting and stopping of PhantomJS / Ghostdriver 25 | """ 26 | 27 | def __init__(self, executable_path, port=0, service_args=None, log_path=None): 28 | """ 29 | Creates a new instance of the Service 30 | 31 | :Args: 32 | - executable_path : Path to PhantomJS binary 33 | - port : Port the service is running on 34 | - service_args : A List of other command line options to pass to PhantomJS 35 | - log_path: Path for PhantomJS service to log to 36 | """ 37 | self.service_args = service_args 38 | if self.service_args is None: 39 | self.service_args = [] 40 | else: 41 | self.service_args = service_args[:] 42 | if not log_path: 43 | log_path = "ghostdriver.log" 44 | if not self._args_contain("--cookies-file="): 45 | self._cookie_temp_file_handle, self._cookie_temp_file = tempfile.mkstemp() 46 | self.service_args.append("--cookies-file=" + self._cookie_temp_file) 47 | else: 48 | self._cookie_temp_file = None 49 | 50 | service.Service.__init__(self, executable_path, port=port, log_file=open(log_path, 'w')) 51 | 52 | def _args_contain(self, arg): 53 | return len(list(filter(lambda x: x.startswith(arg), self.service_args))) > 0 54 | 55 | def command_line_args(self): 56 | return self.service_args + ["--webdriver=%d" % self.port] 57 | 58 | @property 59 | def service_url(self): 60 | """ 61 | Gets the url of the GhostDriver Service 62 | """ 63 | return "http://localhost:%d/wd/hub" % self.port 64 | 65 | def send_remote_shutdown_command(self): 66 | if self._cookie_temp_file: 67 | os.close(self._cookie_temp_file_handle) 68 | os.remove(self._cookie_temp_file) 69 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/phantomjs/webdriver.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver 19 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 20 | from .service import Service 21 | 22 | 23 | class WebDriver(RemoteWebDriver): 24 | """ 25 | Wrapper to communicate with PhantomJS through Ghostdriver. 26 | 27 | You will need to follow all the directions here: 28 | https://github.com/detro/ghostdriver 29 | """ 30 | 31 | def __init__(self, executable_path="phantomjs", 32 | port=0, desired_capabilities=DesiredCapabilities.PHANTOMJS, 33 | service_args=None, service_log_path=None): 34 | """ 35 | Creates a new instance of the PhantomJS / Ghostdriver. 36 | 37 | Starts the service and then creates new instance of the driver. 38 | 39 | :Args: 40 | - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH 41 | - port - port you would like the service to run, if left as 0, a free port will be found. 42 | - desired_capabilities: Dictionary object with non-browser specific 43 | capabilities only, such as "proxy" or "loggingPref". 44 | - service_args : A List of command line arguments to pass to PhantomJS 45 | - service_log_path: Path for phantomjs service to log to. 46 | """ 47 | self.service = Service( 48 | executable_path, 49 | port=port, 50 | service_args=service_args, 51 | log_path=service_log_path) 52 | self.service.start() 53 | 54 | try: 55 | RemoteWebDriver.__init__( 56 | self, 57 | command_executor=self.service.service_url, 58 | desired_capabilities=desired_capabilities) 59 | except Exception: 60 | self.quit() 61 | raise 62 | 63 | self._is_remote = False 64 | 65 | def quit(self): 66 | """ 67 | Closes the browser and shuts down the PhantomJS executable 68 | that is started when starting the PhantomJS 69 | """ 70 | try: 71 | RemoteWebDriver.quit(self) 72 | except Exception: 73 | # We don't care about the message because something probably has gone wrong 74 | pass 75 | finally: 76 | self.service.stop() 77 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/remote/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/remote/file_detector.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | import abc 19 | import os 20 | from selenium.webdriver.common.utils import keys_to_typing 21 | 22 | 23 | class FileDetector(object): 24 | """ 25 | Used for identifying whether a sequence of chars represents the path to a 26 | file. 27 | """ 28 | __metaclass__ = abc.ABCMeta 29 | 30 | @abc.abstractmethod 31 | def is_local_file(self, *keys): 32 | return 33 | 34 | 35 | class UselessFileDetector(FileDetector): 36 | """ 37 | A file detector that never finds anything. 38 | """ 39 | def is_local_file(self, *keys): 40 | return None 41 | 42 | 43 | class LocalFileDetector(FileDetector): 44 | """ 45 | Detects files on the local disk. 46 | """ 47 | def is_local_file(self, *keys): 48 | file_path = ''.join(keys_to_typing(keys)) 49 | 50 | if not file_path: 51 | return None 52 | 53 | try: 54 | if os.path.isfile(file_path): 55 | return file_path 56 | except Exception: 57 | pass 58 | return None 59 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/remote/mobile.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from .command import Command 19 | 20 | 21 | class Mobile(object): 22 | 23 | class ConnectionType(object): 24 | 25 | def __init__(self, mask): 26 | self.mask = mask 27 | 28 | @property 29 | def airplane_mode(self): 30 | return self.mask % 2 == 1 31 | 32 | @property 33 | def wifi(self): 34 | return (self.mask / 2) % 2 == 1 35 | 36 | @property 37 | def data(self): 38 | return (self.mask / 4) > 0 39 | 40 | ALL_NETWORK = ConnectionType(6) 41 | WIFI_NETWORK = ConnectionType(2) 42 | DATA_NETWORK = ConnectionType(4) 43 | AIRPLANE_MODE = ConnectionType(1) 44 | 45 | def __init__(self, driver): 46 | self._driver = driver 47 | 48 | @property 49 | def network_connection(self): 50 | return self.ConnectionType(self._driver.execute(Command.GET_NETWORK_CONNECTION)['value']) 51 | 52 | def set_network_connection(self, network): 53 | """ 54 | Set the network connection for the remote device. 55 | 56 | Example of setting airplane mode:: 57 | 58 | driver.mobile.set_network_connection(driver.mobile.AIRPLANE_MODE) 59 | """ 60 | mode = network.mask if isinstance(network, self.ConnectionType) else network 61 | return self.ConnectionType(self._driver.execute( 62 | Command.SET_NETWORK_CONNECTION, { 63 | 'name': 'network_connection', 64 | 'parameters': {'type': mode}})['value']) 65 | 66 | @property 67 | def context(self): 68 | """ 69 | returns the current context (Native or WebView). 70 | """ 71 | return self._driver.execute(Command.CURRENT_CONTEXT_HANDLE) 72 | 73 | @property 74 | def contexts(self): 75 | """ 76 | returns a list of available contexts 77 | """ 78 | return self._driver.execute(Command.CONTEXT_HANDLES) 79 | 80 | @context.setter 81 | def context(self, new_context): 82 | """ 83 | sets the current context 84 | """ 85 | self._driver.execute(Command.SWITCH_TO_CONTEXT, {"name": new_context}) 86 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/safari/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/safari/service.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | import os 19 | from selenium.webdriver.common import service, utils 20 | from subprocess import PIPE 21 | 22 | 23 | class Service(service.Service): 24 | """ 25 | Object that manages the starting and stopping of the SafariDriver 26 | """ 27 | 28 | def __init__(self, executable_path, port=0, quiet=False): 29 | """ 30 | Creates a new instance of the Service 31 | 32 | :Args: 33 | - executable_path : Path to the SafariDriver 34 | - port : Port the service is running on """ 35 | 36 | if not os.path.exists(executable_path): 37 | raise Exception("SafariDriver requires Safari 10 on OSX El Capitan or greater") 38 | 39 | if port == 0: 40 | port = utils.free_port() 41 | 42 | self.quiet = quiet 43 | log = PIPE 44 | if quiet: 45 | log = open(os.devnull, 'w') 46 | service.Service.__init__(self, executable_path, port, log) 47 | 48 | def command_line_args(self): 49 | return ["-p", "%s" % self.port] 50 | 51 | @property 52 | def service_url(self): 53 | """ 54 | Gets the url of the SafariDriver Service 55 | """ 56 | return "http://localhost:%d" % self.port 57 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/safari/webdriver.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | try: 19 | import http.client as http_client 20 | except ImportError: 21 | import httplib as http_client 22 | 23 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 24 | from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver 25 | from .service import Service 26 | 27 | 28 | class WebDriver(RemoteWebDriver): 29 | """ 30 | Controls the SafariDriver and allows you to drive the browser. 31 | 32 | """ 33 | 34 | def __init__(self, port=0, executable_path="/usr/bin/safaridriver", 35 | desired_capabilities=DesiredCapabilities.SAFARI, quiet=False): 36 | """ 37 | Creates a new instance of the Safari driver. 38 | 39 | Starts the service and then creates new instance of Safari Driver. 40 | 41 | :Args: 42 | - port - port you would like the service to run, if left as 0, a free port will be found. 43 | - desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches). 44 | - quiet - set to True to suppress stdout and stderr of the driver 45 | """ 46 | self.service = Service(executable_path, port=port, quiet=quiet) 47 | self.service.start() 48 | 49 | RemoteWebDriver.__init__( 50 | self, 51 | command_executor=self.service.service_url, 52 | desired_capabilities=desired_capabilities) 53 | self._is_remote = False 54 | 55 | def quit(self): 56 | """ 57 | Closes the browser and shuts down the SafariDriver executable 58 | that is started when starting the SafariDriver 59 | """ 60 | try: 61 | RemoteWebDriver.quit(self) 62 | except http_client.BadStatusLine: 63 | pass 64 | finally: 65 | self.service.stop() 66 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/support/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/support/abstract_event_listener.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | 19 | class AbstractEventListener(object): 20 | """ 21 | Event listener must subclass and implement this fully or partially 22 | """ 23 | 24 | def before_navigate_to(self, url, driver): 25 | pass 26 | 27 | def after_navigate_to(self, url, driver): 28 | pass 29 | 30 | def before_navigate_back(self, driver): 31 | pass 32 | 33 | def after_navigate_back(self, driver): 34 | pass 35 | 36 | def before_navigate_forward(self, driver): 37 | pass 38 | 39 | def after_navigate_forward(self, driver): 40 | pass 41 | 42 | def before_find(self, by, value, driver): 43 | pass 44 | 45 | def after_find(self, by, value, driver): 46 | pass 47 | 48 | def before_click(self, element, driver): 49 | pass 50 | 51 | def after_click(self, element, driver): 52 | pass 53 | 54 | def before_change_value_of(self, element, driver): 55 | pass 56 | 57 | def after_change_value_of(self, element, driver): 58 | pass 59 | 60 | def before_execute_script(self, script, driver): 61 | pass 62 | 63 | def after_execute_script(self, script, driver): 64 | pass 65 | 66 | def before_close(self, driver): 67 | pass 68 | 69 | def after_close(self, driver): 70 | pass 71 | 72 | def before_quit(self, driver): 73 | pass 74 | 75 | def after_quit(self, driver): 76 | pass 77 | 78 | def on_exception(self, exception, driver): 79 | pass 80 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/support/events.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from .abstract_event_listener import AbstractEventListener # noqa 19 | from .event_firing_webdriver import EventFiringWebDriver # noqa 20 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/support/ui.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from .select import Select # noqa 19 | from .wait import WebDriverWait # noqa 20 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/webkitgtk/__init__.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/webkitgtk/options.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 19 | 20 | 21 | class Options(object): 22 | KEY = 'webkitgtk:browserOptions' 23 | 24 | def __init__(self): 25 | self._browser_executable_path = '' 26 | self._browser_arguments = [] 27 | self._overlay_scrollbars_enabled = True 28 | 29 | @property 30 | def browser_executable_path(self): 31 | """ 32 | Returns the location of the browser binary otherwise an empty string 33 | """ 34 | return self._browser_executable_path 35 | 36 | @browser_executable_path.setter 37 | def browser_executable_path(self, value): 38 | """ 39 | Allows you to set the browser binary to launch 40 | 41 | :Args: 42 | - value : path to the browser binary 43 | """ 44 | self._browser_executable_path = value 45 | 46 | @property 47 | def browser_arguments(self): 48 | """ 49 | Returns a list of arguments needed for the browser 50 | """ 51 | return self._browser_arguments 52 | 53 | def add_browser_argument(self, argument): 54 | """ 55 | Adds an argument to the list 56 | 57 | :Args: 58 | - Sets the arguments 59 | """ 60 | if argument: 61 | self._browser_arguments.append(argument) 62 | else: 63 | raise ValueError("argument can not be null") 64 | 65 | @property 66 | def overlay_scrollbars_enabled(self): 67 | """ 68 | Returns whether overlay scrollbars should be enabled 69 | """ 70 | return self._overlay_scrollbars_enabled 71 | 72 | @overlay_scrollbars_enabled.setter 73 | def overlay_scrollbars_enabled(self, value): 74 | """ 75 | Allows you to enable or disable overlay scrollbars 76 | 77 | :Args: 78 | - value : True or False 79 | """ 80 | self._overlay_scrollbars_enabled = value 81 | 82 | def to_capabilities(self): 83 | """ 84 | Creates a capabilities with all the options that have been set and 85 | returns a dictionary with everything 86 | """ 87 | webkitgtk = DesiredCapabilities.WEBKITGTK.copy() 88 | 89 | browser_options = {} 90 | if self.browser_executable_path: 91 | browser_options["binary"] = self.browser_executable_path 92 | if self.browser_arguments: 93 | browser_options["args"] = self.browser_arguments 94 | browser_options["useOverlayScrollbars"] = self.overlay_scrollbars_enabled 95 | 96 | webkitgtk[Options.KEY] = browser_options 97 | 98 | return webkitgtk 99 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/webkitgtk/service.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from selenium.webdriver.common import service 19 | 20 | 21 | class Service(service.Service): 22 | """ 23 | Object that manages the starting and stopping of the WebKitGTKDriver 24 | """ 25 | 26 | def __init__(self, executable_path, port=0, log_path=None): 27 | """ 28 | Creates a new instance of the Service 29 | 30 | :Args: 31 | - executable_path : Path to the WebKitGTKDriver 32 | - port : Port the service is running on 33 | - log_path : Path for the WebKitGTKDriver service to log to 34 | """ 35 | log_file = open(log_path, "wb") if log_path is not None and log_path != "" else None 36 | service.Service.__init__(self, executable_path, port, log_file) 37 | 38 | def command_line_args(self): 39 | return ["-p", "%d" % self.port] 40 | 41 | def send_remote_shutdown_command(self): 42 | pass 43 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/selenium/python/lib/python3.7/site-packages/selenium/webdriver/webkitgtk/webdriver.py: -------------------------------------------------------------------------------- 1 | # Licensed to the Software Freedom Conservancy (SFC) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The SFC licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | try: 19 | import http.client as http_client 20 | except ImportError: 21 | import httplib as http_client 22 | 23 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 24 | from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver 25 | from .service import Service 26 | 27 | 28 | class WebDriver(RemoteWebDriver): 29 | """ 30 | Controls the WebKitGTKDriver and allows you to drive the browser. 31 | """ 32 | 33 | def __init__(self, executable_path="WebKitWebDriver", port=0, options=None, 34 | desired_capabilities=DesiredCapabilities.WEBKITGTK, 35 | service_log_path=None): 36 | """ 37 | Creates a new instance of the WebKitGTK driver. 38 | 39 | Starts the service and then creates new instance of WebKitGTK Driver. 40 | 41 | :Args: 42 | - executable_path : path to the executable. If the default is used it assumes the executable is in the $PATH. 43 | - port : port you would like the service to run, if left as 0, a free port will be found. 44 | - options : an instance of WebKitGTKOptions 45 | - desired_capabilities : Dictionary object with desired capabilities 46 | - service_log_path : Path to write service stdout and stderr output. 47 | """ 48 | if options is not None: 49 | capabilities = options.to_capabilities() 50 | capabilities.update(desired_capabilities) 51 | desired_capabilities = capabilities 52 | 53 | self.service = Service(executable_path, port=port, log_path=service_log_path) 54 | self.service.start() 55 | 56 | RemoteWebDriver.__init__( 57 | self, 58 | command_executor=self.service.service_url, 59 | desired_capabilities=desired_capabilities) 60 | self._is_remote = False 61 | 62 | def quit(self): 63 | """ 64 | Closes the browser and shuts down the WebKitGTKDriver executable 65 | that is started when starting the WebKitGTKDriver 66 | """ 67 | try: 68 | RemoteWebDriver.quit(self) 69 | except http_client.BadStatusLine: 70 | pass 71 | finally: 72 | self.service.stop() 73 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/src/demo_v1.py: -------------------------------------------------------------------------------- 1 | import time 2 | import pandas as pd 3 | 4 | from selenium import webdriver 5 | from selenium.webdriver.chrome.options import Options 6 | from selenium.webdriver.common.by import By 7 | from selenium.webdriver.chrome.service import Service as ChromeService 8 | from webdriver_manager.chrome import ChromeDriverManager 9 | 10 | url = 'https://www.letour.fr/en/rankings' 11 | 12 | # Headless Browser (Lambda) 13 | # options = Options() 14 | # options.add_argument("--headless=new") 15 | # options.add_argument('window-size=1920x1080') 16 | # driver = webdriver.Chrome(service=ChromeService( 17 | # ChromeDriverManager().install()), options=options) 18 | 19 | # Launch Browser (local testing) 20 | # driver = webdriver.Chrome(service=ChromeService( 21 | # ChromeDriverManager().install())) 22 | # driver.maximize_window() 23 | 24 | driver.get(url) 25 | 26 | try: 27 | time.sleep(3) 28 | print('Checking for Current Stage...') 29 | no_ranking_indicator = driver.find_element( 30 | By.CSS_SELECTOR, '.noRanking.la').is_displayed() 31 | print('No Ranking Indicator displayed.') 32 | 33 | time.sleep(3) 34 | print('Clicking Page Nav Link Back to get to current Stage...') 35 | page_nav_link_back = driver.find_element( 36 | By.XPATH, '//a[@data-xtclick="pageRank::pageNav::Prev"]') 37 | page_nav_link_back.click() 38 | except: 39 | current_stage_ele = page_nav_link_back = driver.find_element( 40 | By.CLASS_NAME, 'stage-select__option__stage').text 41 | current_stage = current_stage_ele[current_stage_ele.rindex( 42 | ' ') + 1:] 43 | print('On current Stage: ' + current_stage) 44 | 45 | time.sleep(3) 46 | print('\nGetting General Rankings...') 47 | general_ranking_tab = driver.find_element( 48 | By.XPATH, '//span[@data-xtclick="ranking::tab::overall"]') 49 | general_ranking_tab.click() 50 | print('On General Rankings.\n') 51 | 52 | time.sleep(3) 53 | ranking_tabs = driver.find_elements( 54 | By.XPATH, '//span[@class="js-tabs-ranking-nested general"]') 55 | 56 | riders_data = [] 57 | rider_data = {} 58 | 59 | try: 60 | for ranking_tab in ranking_tabs[:-2]: 61 | ranking_tab.click() 62 | ranking_tab_text = ranking_tab.text 63 | 64 | time.sleep(3) 65 | print('Getting ' + ranking_tab_text + ' rankings...') 66 | 67 | for rider in driver.find_elements(By.CLASS_NAME, 'rankingTables__row')[:10]: 68 | rider_rank = rider.find_element( 69 | By.CLASS_NAME, 'rankingTables__row__position').find_element(By.TAG_NAME, 'span').text 70 | rider_number = rider.find_element( 71 | By.CLASS_NAME, 'flag').get_attribute('data-bib') 72 | rider_country_ele = rider.find_element( 73 | By.CLASS_NAME, 'flag').get_attribute('data-class') 74 | rider_country = rider_country_ele[rider_country_ele.rindex( 75 | '-') + 1:].upper() 76 | rider_name = rider.find_element( 77 | By.CLASS_NAME, 'rankingTables__row__profile--name').text 78 | rider_team = rider.find_element( 79 | By.CSS_SELECTOR, '.break-line.team').find_element(By.TAG_NAME, 'a').text 80 | 81 | rider_data["rider_rank"] = rider_rank 82 | rider_data["rider_number"] = rider_number 83 | rider_data["rider_country"] = rider_country 84 | rider_data["rider_name"] = rider_name 85 | rider_data["rider_team"] = rider_team 86 | 87 | riders_data.append(rider_data) 88 | rider_data = {} 89 | 90 | df = pd.DataFrame({'riders_data': riders_data}) 91 | df.to_json('./data/' + ranking_tab_text.lower() + ".json") 92 | riders_data = [] 93 | except Exception as e: 94 | print('Error processing Rider data.') 95 | print(e) 96 | 97 | print('\nComplete.') 98 | time.sleep(3) 99 | driver.close() 100 | driver.quit() 101 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/src/demo_v2.py: -------------------------------------------------------------------------------- 1 | import time 2 | from selenium import webdriver 3 | from selenium.webdriver.chrome.options import Options 4 | from selenium.webdriver.common.by import By 5 | 6 | # Launch Browser (local testing) 7 | driver = webdriver.Chrome() 8 | driver.maximize_window() 9 | 10 | url = 'https://www.letour.fr/en/rankings' 11 | 12 | driver.get(url) 13 | 14 | time.sleep(3) 15 | print('Checking for Current Stage...') 16 | try: 17 | current_stage_ele = page_nav_link_back = driver.find_element( 18 | By.CLASS_NAME, 'stage-select__option__stage').text 19 | current_stage = current_stage_ele[current_stage_ele.rindex( 20 | ' ') + 1:] 21 | print('On current Stage: ' + current_stage) 22 | 23 | time.sleep(3) 24 | print('\nGetting General Rankings...') 25 | general_ranking_tab = driver.find_element( 26 | By.XPATH, '//span[@data-xtclick="ranking::tab::overall"]') 27 | general_ranking_tab.click() 28 | print('On General Rankings.\n') 29 | 30 | time.sleep(3) 31 | ranking_tabs = driver.find_elements( 32 | By.XPATH, '//span[@class="js-tabs-ranking-nested general"]') 33 | 34 | riders_data = [] 35 | rider_data = {} 36 | 37 | for ranking_tab in ranking_tabs[:-2]: 38 | ranking_tab.click() 39 | ranking_tab_text = ranking_tab.text 40 | 41 | time.sleep(3) 42 | print('Getting ' + ranking_tab_text + ' rankings...') 43 | 44 | for rider in driver.find_elements(By.CLASS_NAME, 'rankingTables__row')[:10]: 45 | rider_rank = rider.find_element( 46 | By.CLASS_NAME, 'rankingTables__row__position').find_element(By.TAG_NAME, 'span').text 47 | rider_number = rider.find_element( 48 | By.CLASS_NAME, 'flag').get_attribute('data-bib') 49 | rider_country_ele = rider.find_element( 50 | By.CLASS_NAME, 'flag').get_attribute('data-class') 51 | rider_country = rider_country_ele[rider_country_ele.rindex( 52 | '-') + 1:].upper() 53 | rider_name = rider.find_element( 54 | By.CLASS_NAME, 'rankingTables__row__profile--name').text 55 | rider_team = rider.find_element( 56 | By.CSS_SELECTOR, '.break-line.team').find_element(By.TAG_NAME, 'a').text 57 | 58 | rider_data["rider_rank"] = rider_rank 59 | rider_data["rider_number"] = rider_number 60 | rider_data["rider_country"] = rider_country 61 | rider_data["rider_name"] = rider_name 62 | rider_data["rider_team"] = rider_team 63 | 64 | riders_data.append(rider_data) 65 | rider_data = {} 66 | 67 | print(riders_data) 68 | riders_data = [] 69 | 70 | except Exception as e: 71 | print(e) 72 | 73 | driver.close() 74 | driver.quit() 75 | 76 | exit 77 | -------------------------------------------------------------------------------- /src/7_Terraform_AWS_Lambda_with_Layers/src/scrape.py: -------------------------------------------------------------------------------- 1 | import time 2 | from selenium import webdriver 3 | from selenium.webdriver.chrome.options import Options 4 | from selenium.webdriver.common.by import By 5 | 6 | 7 | def get_rankings(event, context): 8 | options = Options() 9 | options.binary_location = '/opt/headless-chromium' 10 | options.add_argument('--headless') 11 | options.add_argument('--no-sandbox') 12 | options.add_argument('--single-process') 13 | options.add_argument('--disable-dev-shm-usage') 14 | options.add_argument('window-size=1920x1080') 15 | 16 | driver = webdriver.Chrome('/opt/chromedriver', chrome_options=options) 17 | 18 | url = 'https://www.letour.fr/en/rankings' 19 | 20 | driver.get(url) 21 | 22 | time.sleep(3) 23 | print('Checking for Current Stage...') 24 | try: 25 | current_stage_ele = page_nav_link_back = driver.find_element( 26 | By.CLASS_NAME, 'stage-select__option__stage').text 27 | current_stage = current_stage_ele[current_stage_ele.rindex( 28 | ' ') + 1:] 29 | print('On current Stage: ' + current_stage) 30 | 31 | time.sleep(3) 32 | print('\nGetting General Rankings...') 33 | general_ranking_tab = driver.find_element( 34 | By.XPATH, '//span[@data-xtclick="ranking::tab::overall"]') 35 | general_ranking_tab.click() 36 | print('On General Rankings.\n') 37 | 38 | time.sleep(3) 39 | ranking_tabs = driver.find_elements( 40 | By.XPATH, '//span[@class="js-tabs-ranking-nested general"]') 41 | 42 | riders_data = [] 43 | rider_data = {} 44 | 45 | for ranking_tab in ranking_tabs[:-2]: 46 | ranking_tab.click() 47 | ranking_tab_text = ranking_tab.text 48 | 49 | time.sleep(3) 50 | print('Getting ' + ranking_tab_text + ' rankings...') 51 | 52 | for rider in driver.find_elements(By.CLASS_NAME, 'rankingTables__row')[:10]: 53 | rider_rank = rider.find_element( 54 | By.CLASS_NAME, 'rankingTables__row__position').find_element(By.TAG_NAME, 'span').text 55 | rider_number = rider.find_element( 56 | By.CLASS_NAME, 'flag').get_attribute('data-bib') 57 | rider_country_ele = rider.find_element( 58 | By.CLASS_NAME, 'flag').get_attribute('data-class') 59 | rider_country = rider_country_ele[rider_country_ele.rindex( 60 | '-') + 1:].upper() 61 | rider_name = rider.find_element( 62 | By.CLASS_NAME, 'rankingTables__row__profile--name').text 63 | rider_team = rider.find_element( 64 | By.CSS_SELECTOR, '.break-line.team').find_element(By.TAG_NAME, 'a').text 65 | 66 | rider_data["rider_rank"] = rider_rank 67 | rider_data["rider_number"] = rider_number 68 | rider_data["rider_country"] = rider_country 69 | rider_data["rider_name"] = rider_name 70 | rider_data["rider_team"] = rider_team 71 | 72 | riders_data.append(rider_data) 73 | rider_data = {} 74 | 75 | print(riders_data) 76 | riders_data = [] 77 | 78 | except Exception as e: 79 | print(e) 80 | 81 | driver.close() 82 | driver.quit() 83 | 84 | return 85 | -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | bucket_name = "YOUR_BUCKET_NAME" 3 | table_name = "YOUR_TABLE_NAME" 4 | 5 | default_vpc_name = "defaultVPC" 6 | default_subnet_name = "defaultSubnet" 7 | 8 | ec2_security_group_name = "ec2SecurityGroup" 9 | ec2_security_group_desc = "Allow access on Ports 22 and 8080" 10 | ec2_security_group_tag_val = "Jenkins Server Security Group" 11 | 12 | ec2_security_group_http_proxy_desc = "HTTP Proxy" 13 | ec2_security_group_http_proxy_port = 8080 14 | ec2_security_group_http_proxy_protocol = "tcp" 15 | ec2_security_group_http_proxy_cidr = "0.0.0.0/0" 16 | 17 | ec2_security_group_ssh_proxy_desc = "SSH Proxy" 18 | ec2_security_group_ssh_proxy_port = 22 19 | ec2_security_group_ssh_proxy_protocol = "tcp" 20 | ec2_security_group_ssh_proxy_cidr = "0.0.0.0/0" 21 | 22 | ec2_security_group_egress_port = 0 23 | ec2_security_group_egrress_protocol = -1 24 | ec2_security_group_egress_cidr = "0.0.0.0/0" 25 | 26 | ec2_keypair_name = "tf-key-pair" 27 | ec2_instanct_tag_val = "JenkinsServer" 28 | 29 | iam_policy_name = "jenkins_iam_policy" 30 | iam_role_name = "jenkins_iam_role" 31 | iam_policy_attachment_name = "policy_attachment" 32 | jenkins_instance_profile_name = "jenkins_instance_profile" 33 | 34 | ssh_connection_user = "ec2-user" 35 | ssh_connection_file_source = "./scripts/script.sh" 36 | ssh_connection_file_destination = "/tmp/script.sh" 37 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.3" 3 | 4 | backend "s3" { 5 | bucket = "YOUR_BUCKET_NAME" 6 | key = "tf-infra/terraform.tfstate" 7 | region = "us-east-1" 8 | dynamodb_table = "YOUR_TABLE_NAME" 9 | encrypt = true 10 | } 11 | 12 | required_providers { 13 | aws = { 14 | source = "hashicorp/aws" 15 | version = "~> 4.0" 16 | } 17 | } 18 | } 19 | 20 | module "tf-state" { 21 | source = "./modules/tf-state" 22 | bucket_name = local.bucket_name 23 | table_name = local.table_name 24 | } 25 | 26 | module "vpc" { 27 | source = "./modules/vpc" 28 | default_vpc_name = local.default_vpc_name 29 | default_subnet_name = local.default_subnet_name 30 | } 31 | 32 | module "iam" { 33 | source = "./modules/iam" 34 | iam_policy_name = local.iam_policy_name 35 | iam_role_name = local.iam_role_name 36 | iam_policy_attachment_name = local.iam_policy_attachment_name 37 | jenkins_instance_profile_name = local.jenkins_instance_profile_name 38 | } 39 | 40 | module "server" { 41 | source = "./modules/server" 42 | vpc_id = module.vpc.default_vpc_id 43 | ec2_security_group_name = local.ec2_security_group_name 44 | ec2_security_group_desc = local.ec2_security_group_desc 45 | ec2_security_group_tag_val = local.ec2_security_group_tag_val 46 | 47 | ec2_security_group_http_proxy_desc = local.ec2_security_group_http_proxy_desc 48 | ec2_security_group_http_proxy_port = local.ec2_security_group_http_proxy_port 49 | ec2_security_group_http_proxy_protocol = local.ec2_security_group_http_proxy_protocol 50 | ec2_security_group_http_proxy_cidr = local.ec2_security_group_http_proxy_cidr 51 | 52 | ec2_security_group_ssh_proxy_desc = local.ec2_security_group_ssh_proxy_desc 53 | ec2_security_group_ssh_proxy_port = local.ec2_security_group_ssh_proxy_port 54 | ec2_security_group_ssh_proxy_protocol = local.ec2_security_group_ssh_proxy_protocol 55 | ec2_security_group_ssh_proxy_cidr = local.ec2_security_group_ssh_proxy_cidr 56 | 57 | ec2_security_group_egress_port = local.ec2_security_group_egress_port 58 | ec2_security_group_egrress_protocol = local.ec2_security_group_egrress_protocol 59 | ec2_security_group_egress_cidr = local.ec2_security_group_egress_cidr 60 | 61 | default_az_id = module.vpc.default_az_id 62 | jenkins_instance_profile_name = module.iam.jenkins_instance_profile_name 63 | ec2_keypair_name = local.ec2_keypair_name 64 | ec2_instanct_tag_val = local.ec2_instanct_tag_val 65 | } 66 | 67 | module "ssh_connection" { 68 | source = "./modules/ssh_connection" 69 | local_file_name = module.server.local_file_name 70 | public_ip = module.server.public_ip 71 | ssh_connection_user = local.ssh_connection_user 72 | ssh_connection_file_source = local.ssh_connection_file_source 73 | ssh_connection_file_destination = local.ssh_connection_file_destination 74 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/iam/main.tf: -------------------------------------------------------------------------------- 1 | # IAM Policy for EC2 2 | resource "aws_iam_policy" "jenkins_iam_policy" { 3 | name = var.iam_policy_name 4 | 5 | policy = jsonencode({ 6 | Version = "2012-10-17" 7 | Statement = [ 8 | { 9 | Effect = "Allow" 10 | Action = "*" 11 | Resource = "*" 12 | } 13 | ] 14 | }) 15 | } 16 | 17 | # IAM Role for EC2 18 | resource "aws_iam_role" "jenkins_role" { 19 | name = var.iam_role_name 20 | 21 | assume_role_policy = jsonencode({ 22 | Version = "2012-10-17" 23 | Statement = [ 24 | { 25 | Effect = "Allow" 26 | Principal = { 27 | Service = "ec2.amazonaws.com" 28 | } 29 | Action = "sts:AssumeRole" 30 | } 31 | ] 32 | }) 33 | } 34 | 35 | # Attach IAM Policy to IAM Role 36 | resource "aws_iam_policy_attachment" "jenkins_role_policy_attachment" { 37 | name = var.iam_policy_attachment_name 38 | policy_arn = aws_iam_policy.jenkins_iam_policy.arn 39 | roles = [aws_iam_role.jenkins_role.name] 40 | } 41 | 42 | # IAM Instance Profile 43 | resource "aws_iam_instance_profile" "jenkins_instance_profile" { 44 | name = var.jenkins_instance_profile_name 45 | role = aws_iam_role.jenkins_role.name 46 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/iam/outputs.tf: -------------------------------------------------------------------------------- 1 | output "jenkins_instance_profile_name" { 2 | value = aws_iam_instance_profile.jenkins_instance_profile.name 3 | } 4 | -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/iam/variables.tf: -------------------------------------------------------------------------------- 1 | variable "iam_policy_name" { 2 | description = "iam_policy_name" 3 | type = string 4 | } 5 | 6 | variable "iam_role_name" { 7 | description = "iam_role_name" 8 | type = string 9 | } 10 | 11 | variable "iam_policy_attachment_name" { 12 | description = "iam_policy_attachment_name" 13 | type = string 14 | } 15 | 16 | variable "jenkins_instance_profile_name" { 17 | description = "jenkins_instance_profile_name" 18 | type = string 19 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/server/main.tf: -------------------------------------------------------------------------------- 1 | # Getet AMZ Linux 2 AMI 2 | data "aws_ami" "amazon_linux_2" { 3 | most_recent = true 4 | owners = ["amazon"] 5 | 6 | filter { 7 | name = "owner-alias" 8 | values = ["amazon"] 9 | } 10 | 11 | filter { 12 | name = "name" 13 | values = ["amzn2-ami-hvm*"] 14 | } 15 | } 16 | 17 | # EC2 Security Group 18 | resource "aws_security_group" "ec2_security_group" { 19 | name = var.ec2_security_group_name 20 | description = var.ec2_security_group_desc 21 | vpc_id = var.vpc_id 22 | 23 | # Open Jenkins Port (8080) 24 | ingress { 25 | description = var.ec2_security_group_http_proxy_desc 26 | from_port = var.ec2_security_group_http_proxy_port 27 | to_port = var.ec2_security_group_http_proxy_port 28 | protocol = var.ec2_security_group_http_proxy_protocol 29 | cidr_blocks = [var.ec2_security_group_http_proxy_cidr] 30 | } 31 | 32 | # Allow ssh (Port 22) 33 | ingress { 34 | description = var.ec2_security_group_ssh_proxy_desc 35 | from_port = var.ec2_security_group_ssh_proxy_port 36 | to_port = var.ec2_security_group_ssh_proxy_port 37 | protocol = var.ec2_security_group_ssh_proxy_protocol 38 | cidr_blocks = [var.ec2_security_group_ssh_proxy_cidr] 39 | } 40 | 41 | egress { 42 | from_port = var.ec2_security_group_egress_port 43 | to_port = var.ec2_security_group_egress_port 44 | protocol = var.ec2_security_group_egrress_protocol 45 | cidr_blocks = [var.ec2_security_group_egress_cidr] 46 | } 47 | 48 | tags = { 49 | Name = var.ec2_security_group_tag_val 50 | } 51 | } 52 | 53 | # Create KP and download to local machine 54 | resource "aws_key_pair" "tf-key-pair" { 55 | key_name = var.ec2_keypair_name 56 | public_key = tls_private_key.rsa.public_key_openssh 57 | 58 | provisioner "local-exec" { 59 | command = "echo '${tls_private_key.rsa.private_key_pem}' > ./tf-key-pair.pem" 60 | } 61 | } 62 | resource "tls_private_key" "rsa" { 63 | algorithm = "RSA" 64 | rsa_bits = 4096 65 | } 66 | resource "local_file" "tf-key" { 67 | content = tls_private_key.rsa.private_key_pem 68 | filename = var.ec2_keypair_name 69 | file_permission = "0400" 70 | } 71 | 72 | # Launch Instance 73 | resource "aws_instance" "ec2_instance" { 74 | ami = data.aws_ami.amazon_linux_2.id 75 | instance_type = "t2.micro" 76 | subnet_id = var.default_az_id 77 | vpc_security_group_ids = [aws_security_group.ec2_security_group.id] 78 | iam_instance_profile = var.jenkins_instance_profile_name 79 | key_name = var.ec2_keypair_name 80 | 81 | tags = { Name = var.ec2_instanct_tag_val } 82 | } 83 | -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/server/outputs.tf: -------------------------------------------------------------------------------- 1 | output "local_file_name" { 2 | value = local_file.tf-key.filename 3 | } 4 | 5 | output "public_ip" { 6 | value = aws_instance.ec2_instance.public_ip 7 | } 8 | 9 | # Print Jenkins Server URL 10 | output "website_url" { 11 | value = join("", ["http://", aws_instance.ec2_instance.public_dns, ":", "8080"]) 12 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/server/variables.tf: -------------------------------------------------------------------------------- 1 | variable "ec2_security_group_name" { 2 | description = "ec2_security_group_name" 3 | type = string 4 | } 5 | 6 | variable "vpc_id" { 7 | description = "vpc_id" 8 | type = string 9 | } 10 | 11 | variable "ec2_security_group_desc" { 12 | description = "ec2_security_group_desc" 13 | type = string 14 | } 15 | 16 | variable "ec2_security_group_tag_val" { 17 | description = "ec2_security_group_tag_val" 18 | type = string 19 | } 20 | 21 | variable "ec2_security_group_http_proxy_desc" { 22 | description = "ec2_security_group_http_proxy_desc" 23 | type = string 24 | } 25 | 26 | variable "ec2_security_group_http_proxy_port" { 27 | description = "ec2_security_group_http_proxy_port" 28 | type = number 29 | } 30 | 31 | variable "ec2_security_group_http_proxy_protocol" { 32 | description = "ec2_security_group_http_proxy_protocol" 33 | type = string 34 | } 35 | 36 | variable "ec2_security_group_http_proxy_cidr" { 37 | description = "ec2_security_group_http_proxy_cidr" 38 | type = string 39 | } 40 | 41 | variable "ec2_security_group_ssh_proxy_desc" { 42 | description = "ec2_security_group_ssh_proxy_desc" 43 | type = string 44 | } 45 | 46 | variable "ec2_security_group_ssh_proxy_port" { 47 | description = "ec2_security_group_shh_proxy_port" 48 | type = number 49 | } 50 | 51 | variable "ec2_security_group_ssh_proxy_protocol" { 52 | description = "ec2_security_group_ssh_proxy_protocol" 53 | type = string 54 | } 55 | 56 | variable "ec2_security_group_ssh_proxy_cidr" { 57 | description = "ec2_security_group_shh_proxy_cidr" 58 | type = string 59 | } 60 | 61 | variable "ec2_security_group_egress_port" { 62 | description = "ec2_security_group_egress_port" 63 | type = number 64 | } 65 | 66 | variable "ec2_security_group_egrress_protocol" { 67 | description = "ec2_security_group_egrress_protocol" 68 | type = number 69 | } 70 | 71 | variable "ec2_security_group_egress_cidr" { 72 | description = "ec2_security_group_egress_cidr" 73 | type = string 74 | } 75 | 76 | variable "default_az_id" { 77 | description = "default_az_id" 78 | type = string 79 | } 80 | 81 | variable "jenkins_instance_profile_name" { 82 | description = "jenkins_instance_profile_name" 83 | type = string 84 | } 85 | 86 | variable "ec2_keypair_name" { 87 | description = "ec2_keypair_name" 88 | type = string 89 | } 90 | 91 | variable "ec2_instanct_tag_val" { 92 | description = "ec2_instanct_tag_val" 93 | type = string 94 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/ssh_connection/main.tf: -------------------------------------------------------------------------------- 1 | resource "null_resource" "ssh_connection" { 2 | # SSH into EC2 3 | connection { 4 | type = "ssh" 5 | user = var.ssh_connection_user 6 | private_key = file(var.local_file_name) 7 | host = var.public_ip 8 | } 9 | 10 | # Copy script.sh shell script from local machine to EC2 11 | provisioner "file" { 12 | source = var.ssh_connection_file_source 13 | destination = var.ssh_connection_file_destination 14 | } 15 | 16 | # Set permissions and exec the shell script 17 | provisioner "remote-exec" { 18 | inline = [ 19 | "sudo chmod +x /script.sh", 20 | "sh /tmp/script.sh" 21 | ] 22 | } 23 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/ssh_connection/vriables.tf: -------------------------------------------------------------------------------- 1 | variable "local_file_name" { 2 | description = "local_file_name" 3 | type = string 4 | } 5 | 6 | variable "public_ip" { 7 | description = "public_ip" 8 | type = string 9 | } 10 | 11 | variable "ssh_connection_user" { 12 | description = "ssh_connection_user" 13 | type = string 14 | } 15 | 16 | variable "ssh_connection_file_source" { 17 | description = "ssh_connection_file_source" 18 | type = string 19 | } 20 | 21 | variable "ssh_connection_file_destination" { 22 | description = "ssh_connection_file_destination" 23 | type = string 24 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/tf-state/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_s3_bucket" "terraform_state" { 2 | bucket = var.bucket_name 3 | force_destroy = true 4 | } 5 | 6 | resource "aws_s3_bucket_versioning" "terraform_bucket_versioning" { 7 | bucket = aws_s3_bucket.terraform_state.id 8 | versioning_configuration { 9 | status = "Enabled" 10 | } 11 | } 12 | 13 | resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_crypto_conf" { 14 | bucket = aws_s3_bucket.terraform_state.bucket 15 | rule { 16 | apply_server_side_encryption_by_default { 17 | sse_algorithm = "AES256" 18 | } 19 | } 20 | } 21 | 22 | resource "aws_dynamodb_table" "terraform_locks" { 23 | name = var.table_name 24 | billing_mode = "PAY_PER_REQUEST" 25 | hash_key = "LockID" 26 | attribute { 27 | name = "LockID" 28 | type = "S" 29 | } 30 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/tf-state/variables.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "Remote S3 Bucket Name" 3 | type = string 4 | validation { 5 | condition = can(regex("^([a-z0-9]{1}[a-z0-9-]{1,61}[a-z0-9]{1})$", var.bucket_name)) 6 | error_message = "Bucket Name must not be empty and must follow S3 naming rules." 7 | } 8 | } 9 | 10 | variable "table_name" { 11 | description = "Remote DynamoDB Table Name" 12 | type = string 13 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/vpc/main.tf: -------------------------------------------------------------------------------- 1 | # Hold all AZs in Region 2 | data "aws_availability_zones" "available_zones" {} 3 | 4 | # Create default VPC - if one doesn't exist 5 | resource "aws_default_vpc" "default_vpc" { 6 | tags = { Name = var.default_vpc_name } 7 | } 8 | 9 | # Create default Subnet - if one doesn't exist 10 | resource "aws_default_subnet" "default_az" { 11 | availability_zone = data.aws_availability_zones.available_zones.names[0] 12 | 13 | tags = { Name = var.default_subnet_name } 14 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/vpc/outputs.tf: -------------------------------------------------------------------------------- 1 | output "default_vpc_id" { 2 | value = aws_default_vpc.default_vpc.id 3 | } 4 | 5 | output "default_az_id" { 6 | value = aws_default_subnet.default_az.id 7 | } 8 | -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/modules/vpc/variables.tf: -------------------------------------------------------------------------------- 1 | variable "default_vpc_name" { 2 | description = "default_vpc_name" 3 | type = string 4 | } 5 | 6 | variable "default_subnet_name" { 7 | description = "default_subnet_name" 8 | type = string 9 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/providers.tf: -------------------------------------------------------------------------------- 1 | # Configure the AWS Provider 2 | provider "aws" { 3 | region = "us-east-1" 4 | } -------------------------------------------------------------------------------- /src/8_Terraform_Jenkins_Server_with_TF/scripts/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo yum update -y 3 | sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo 4 | sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key 5 | sudo yum upgrade 6 | sudo amazon-linux-extras install java-openjdk11 -y 7 | sudo yum install jenkins -y 8 | sudo systemctl enable jenkins 9 | sudo systemctl start jenkins 10 | sudo systemctl status jenkins 11 | sudo cat /var/lib/jenkins/secrets/initialAdminPassword 12 | 13 | sudo yum install git -y 14 | 15 | sudo wget https://releases.hashicorp.com/terraform/1.3.7/terraform_1.3.7_linux_amd64.zip 16 | sudo unzip terraform_1.3.7_linux_amd64.zip 17 | sudo mv terraform /usr/local/bin/ 18 | -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | subnet_ids = ["subnet-...", "subnet-..."] 3 | security_group_id = ["sg-..."] 4 | file_system_path = "/var/www/html" 5 | } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "YOUR_BUCKET_NAME" 4 | key = "tf-infra/terraform.tfstate" 5 | region = "YOUR_REGION" 6 | dynamodb_table = "terraform-state-locking" 7 | encrypt = true 8 | } 9 | 10 | required_version = ">=0.13.0" 11 | required_providers { 12 | aws = { 13 | source = "hashicorp/aws" 14 | version = "~> 5.0" 15 | } 16 | } 17 | } 18 | 19 | provider "aws" { 20 | region = "YOUR_REGION" 21 | } 22 | 23 | module "tf-state" { 24 | source = "./modules/tf-state" 25 | bucket_name = "YOUR_BUCKET_NAME" 26 | } 27 | 28 | module "efs" { 29 | source = "./modules/efs" 30 | efs-name = "cc-efs" 31 | subnet_ids = local.subnet_ids 32 | } 33 | 34 | module "webserver-infra" { 35 | source = "./modules/webserver" 36 | subnet_ids = local.subnet_ids 37 | security_group_id = local.security_group_id 38 | file_system_path = local.file_system_path 39 | mount_target_dns_names = module.efs.cc-efs-mount-target-dns-names 40 | } 41 | -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/efs/efs.tf: -------------------------------------------------------------------------------- 1 | resource "aws_efs_file_system" "cc-efs" { 2 | creation_token = var.efs-name 3 | encrypted = true 4 | 5 | tags = { 6 | Name = var.efs-name 7 | } 8 | } 9 | 10 | resource "aws_efs_mount_target" "cc-efs-mount-targets" { 11 | count = 2 12 | file_system_id = aws_efs_file_system.cc-efs.id 13 | subnet_id = var.subnet_ids[count.index] 14 | } 15 | -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/efs/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">=0.13.0" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = "~> 5.0" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/efs/outputs.tf: -------------------------------------------------------------------------------- 1 | output "cc-efs-mount-target-dns-names" { 2 | description = "EFS Mount Target DNS" 3 | value = aws_efs_mount_target.cc-efs-mount-targets[*].dns_name 4 | } 5 | -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/efs/variables.tf: -------------------------------------------------------------------------------- 1 | variable "efs-name" { 2 | description = "Name of EFS" 3 | type = string 4 | } 5 | 6 | variable "subnet_ids" { 7 | description = "Mount Target Subnet Id" 8 | type = list(string) 9 | } 10 | -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/tf-state/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">=0.13.0" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = "~> 5.0" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/tf-state/tf-state.tf: -------------------------------------------------------------------------------- 1 | # S3 Bucket for TF State File 2 | resource "aws_s3_bucket" "terraform_state" { 3 | bucket = var.bucket_name 4 | force_destroy = true 5 | } 6 | 7 | resource "aws_s3_bucket_versioning" "terraform_bucket_versioning" { 8 | bucket = aws_s3_bucket.terraform_state.id 9 | versioning_configuration { 10 | status = "Enabled" 11 | } 12 | } 13 | 14 | resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_crypto_conf" { 15 | bucket = aws_s3_bucket.terraform_state.bucket 16 | rule { 17 | apply_server_side_encryption_by_default { 18 | sse_algorithm = "AES256" 19 | } 20 | } 21 | } 22 | 23 | # Dynamo DB Table for Locking TF Config 24 | resource "aws_dynamodb_table" "terraform_locks" { 25 | name = "terraform-state-locking" 26 | billing_mode = "PAY_PER_REQUEST" 27 | hash_key = "LockID" 28 | attribute { 29 | name = "LockID" 30 | type = "S" 31 | } 32 | } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/tf-state/varaibles.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "Remote S3 Bucket Name" 3 | type = string 4 | validation { 5 | condition = can(regex("^([a-z0-9]{1}[a-z0-9-]{1,61}[a-z0-9]{1})$", var.bucket_name)) 6 | error_message = "Bucket Name must not be empty and must follow S3 naming rules." 7 | } 8 | } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/webserver/locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | ami_id = "ami-..." 3 | instance_type = "t2.micro" 4 | key_name = "YOUR_KP" 5 | } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/webserver/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">=0.13.0" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = "~> 5.0" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/webserver/outputs.tf: -------------------------------------------------------------------------------- 1 | # output "public_dns" { 2 | # description = "The public DNS name assigned to the instance." 3 | # value = aws_instance.webserver[*].public_dns 4 | # } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/webserver/user_data.tfpl: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo su 3 | yum update -y 4 | 5 | yum install -y httpd 6 | service httpd start 7 | 8 | yum install amazon-efs-utils -y 9 | 10 | mkdir ${file_system_path} 11 | mount ${mount_target_dns_name}:/ ${file_system_path} 12 | 13 | echo "

Hello, World! v${server_index}.0

" > ${file_system_path}/index.html 14 | -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/webserver/variables.tf: -------------------------------------------------------------------------------- 1 | variable "subnet_ids" { 2 | description = "Subnet Id" 3 | type = list(string) 4 | } 5 | 6 | variable "security_group_id" { 7 | description = "Security Group Id" 8 | type = list(string) 9 | } 10 | 11 | variable "ingress_rules" { 12 | type = list(object({ 13 | port = number 14 | proto = string 15 | cidr_blocks = list(string) 16 | })) 17 | default = [ 18 | { 19 | port = 80 20 | proto = "tcp" 21 | cidr_blocks = ["0.0.0.0/0"] 22 | }, 23 | { 24 | port = 22 25 | proto = "tcp" 26 | cidr_blocks = ["0.0.0.0/0"] 27 | } 28 | ] 29 | } 30 | 31 | variable "file_system_path" { 32 | description = "Path to mount EFS" 33 | type = string 34 | } 35 | 36 | variable "mount_target_dns_names" { 37 | description = "Mount Target DNS Names" 38 | type = list(string) 39 | } -------------------------------------------------------------------------------- /src/9_Terraform_AWS_Provision_and_mount_EFS/modules/webserver/webserver.tf: -------------------------------------------------------------------------------- 1 | resource "aws_instance" "webserver" { 2 | count = 2 3 | ami = local.ami_id 4 | instance_type = local.instance_type 5 | key_name = local.key_name 6 | subnet_id = var.subnet_ids[count.index] 7 | security_groups = var.security_group_id 8 | associate_public_ip_address = true 9 | 10 | tags = { 11 | Name = "WebServer_${count.index + 1}" 12 | } 13 | 14 | user_data = templatefile("./modules/webserver/user_data.tfpl", { file_system_path = var.file_system_path, mount_target_dns_name = var.mount_target_dns_names[count.index], server_index = count.index + 1 }) 15 | } --------------------------------------------------------------------------------