From 83690ccf1a22266e2e03dee414fd1710ba0562fa Mon Sep 17 00:00:00 2001 From: Rob Gil Date: Wed, 18 Dec 2019 15:14:22 -0500 Subject: [PATCH 1/5] 169163334 - Adds redis module Adds basic redis module. --- terraform/modules/redis/main.tf | 24 +++++++++++ terraform/modules/redis/outputs.tf | 0 terraform/modules/redis/variables.tf | 60 ++++++++++++++++++++++++++++ terraform/providers/dev/redis.tf | 7 ++++ 4 files changed, 91 insertions(+) create mode 100644 terraform/modules/redis/main.tf create mode 100644 terraform/modules/redis/outputs.tf create mode 100644 terraform/modules/redis/variables.tf create mode 100644 terraform/providers/dev/redis.tf diff --git a/terraform/modules/redis/main.tf b/terraform/modules/redis/main.tf new file mode 100644 index 00000000..1e47f767 --- /dev/null +++ b/terraform/modules/redis/main.tf @@ -0,0 +1,24 @@ +resource "azurerm_resource_group" "redis" { + name = "${var.name}-${var.environment}-redis" + location = var.region +} + +# NOTE: the Name used for Redis needs to be globally unique +resource "azurerm_redis_cache" "redis" { + name = "${var.name}-${var.environment}-redis" + location = azurerm_resource_group.redis.location + resource_group_name = azurerm_resource_group.redis.name + capacity = var.capacity + family = var.family + sku_name = var.sku_name + enable_non_ssl_port = var.enable_non_ssl_port + minimum_tls_version = var.minimum_tls_version + + redis_configuration { + enable_authentication = var.enable_authentication + } + tags = { + environment = var.environment + owner = var.owner + } +} diff --git a/terraform/modules/redis/outputs.tf b/terraform/modules/redis/outputs.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/modules/redis/variables.tf b/terraform/modules/redis/variables.tf new file mode 100644 index 00000000..ecdb7636 --- /dev/null +++ b/terraform/modules/redis/variables.tf @@ -0,0 +1,60 @@ +variable "region" { + type = string + description = "Region this module and resources will be created in" +} + +variable "name" { + type = string + description = "Unique name for the services in this module" +} + +variable "environment" { + type = string + description = "Environment these resources reside (prod, dev, staging, etc)" +} + +variable "owner" { + type = string + description = "Owner of the environment and resources created in this module" +} + +variable "capacity" { + type = string + default = 2 + description = "The capacity of the redis cache" + +} + +variable "family" { + type = string + default = "C" + description = "The subscription family for redis" + +} + +variable "sku_name" { + type = string + default = "Standard" + description = "The sku to use" + +} + +variable "enable_non_ssl_port" { + type = bool + default = false + description = "Enable non TLS port (default: false)" + +} + +variable "minimum_tls_version" { + type = string + default = "1.2" + description = "Minimum TLS version to use" + +} + +variable "enable_authentication" { + type = bool + default = true + description = "Enable or disable authentication (default: true)" +} diff --git a/terraform/providers/dev/redis.tf b/terraform/providers/dev/redis.tf new file mode 100644 index 00000000..fca3a4e3 --- /dev/null +++ b/terraform/providers/dev/redis.tf @@ -0,0 +1,7 @@ +module "redis" { + source = "../../modules/redis" + owner = var.owner + environment = var.environment + region = var.region + name = var.name +} From d247620c514eb2c15cc93c98241555dd02a3f4b3 Mon Sep 17 00:00:00 2001 From: graham-dds Date: Wed, 18 Dec 2019 12:04:38 -0500 Subject: [PATCH 2/5] Slience output from curl for integration tests We use curl in our integration test script to make sure the application container is available before moving on. We expect many connection errors and don't care about the output of curl, so this will just swallow all of the output. --- script/integration_tests | 7 +++++-- uitests/README.md | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/script/integration_tests b/script/integration_tests index e84b103a..cb0d813a 100755 --- a/script/integration_tests +++ b/script/integration_tests @@ -72,15 +72,18 @@ $CONTAINER_IMAGE \ # Use curl to wait for application container to become available docker pull curlimages/curl:latest +echo "Waiting for application container to become available" docker run --network atat \ curlimages/curl:latest \ - curl --connect-timeout 3 \ + curl \ + --silent \ + --connect-timeout 3 \ --max-time 5 \ --retry $CONTAINER_TIMEOUT \ --retry-connrefused \ --retry-delay 1 \ --retry-max-time $CONTAINER_TIMEOUT \ - test-atat:8000 + test-atat:8000 >/dev/null # Run Ghost Inspector tests docker pull ghostinspector/test-runner-standalone:latest diff --git a/uitests/README.md b/uitests/README.md index aa1dfd93..c05b92b2 100644 --- a/uitests/README.md +++ b/uitests/README.md @@ -58,6 +58,5 @@ NGROK_TOKEN= GI_API_KEY= GI_SUITE= CONTAINER_IMAGE=atat:b - If you get errors regarding ports being in use, make sure you don't have instances of the Flask app, Postgres, or Redis running locally using those ports. - If the curl command used to wait for the application container times out and fails, you can increase the timeout by setting a CONTAINER_TIMEOUT environment variable. It defaults to 200 in the script. -- The curl command will print errors until it successfully connects to the application container. These are normal and expected. When it finally connects, it will print the ATAT home page HTML to STDOUT. - You may see errors like "No such container". The script attempts to clean up any previous incarnations of the containers before it starts, and it may print errors when it doesn't find them. This is fine. - The script is, for the most part, a series of docker commands, so try running the commands individually and debugging that way. From 6d64665474b0aaa440ed2b8672a56d25dd086f70 Mon Sep 17 00:00:00 2001 From: Rob Gil Date: Wed, 18 Dec 2019 18:45:25 -0500 Subject: [PATCH 3/5] 169163334 - Adds CDN module Basic CDN module with configurable origin. --- terraform/modules/cdn/main.tf | 31 ++++++++++++++++++++++++++++++ terraform/modules/cdn/outputs.tf | 0 terraform/modules/cdn/variables.tf | 31 ++++++++++++++++++++++++++++++ terraform/providers/dev/cdn.tf | 8 ++++++++ 4 files changed, 70 insertions(+) create mode 100644 terraform/modules/cdn/main.tf create mode 100644 terraform/modules/cdn/outputs.tf create mode 100644 terraform/modules/cdn/variables.tf create mode 100644 terraform/providers/dev/cdn.tf diff --git a/terraform/modules/cdn/main.tf b/terraform/modules/cdn/main.tf new file mode 100644 index 00000000..5debd443 --- /dev/null +++ b/terraform/modules/cdn/main.tf @@ -0,0 +1,31 @@ +resource "random_id" "server" { + keepers = { + azi_id = 1 + } + + byte_length = 8 +} + +resource "azurerm_resource_group" "cdn" { + name = "${var.name}-${var.environment}-cdn" + location = var.region +} + +resource "azurerm_cdn_profile" "cdn" { + name = "${var.name}-${var.environment}-profile" + location = azurerm_resource_group.cdn.location + resource_group_name = azurerm_resource_group.cdn.name + sku = var.sku +} + +resource "azurerm_cdn_endpoint" "cdn" { + name = "${var.name}-${var.environment}-${random_id.server.hex}" + profile_name = azurerm_cdn_profile.cdn.name + location = azurerm_resource_group.cdn.location + resource_group_name = azurerm_resource_group.cdn.name + + origin { + name = "${var.name}-${var.environment}-origin" + host_name = var.origin_host_name + } +} diff --git a/terraform/modules/cdn/outputs.tf b/terraform/modules/cdn/outputs.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/modules/cdn/variables.tf b/terraform/modules/cdn/variables.tf new file mode 100644 index 00000000..a026ffed --- /dev/null +++ b/terraform/modules/cdn/variables.tf @@ -0,0 +1,31 @@ +variable "region" { + type = string + description = "Region this module and resources will be created in" +} + +variable "name" { + type = string + description = "Unique name for the services in this module" +} + +variable "environment" { + type = string + description = "Environment these resources reside (prod, dev, staging, etc)" +} + +variable "owner" { + type = string + description = "Owner of the environment and resources created in this module" +} + +variable "sku" { + type = string + description = "SKU of which CDN to use" + default = "Standard_Verizon" +} + +variable "origin_host_name" { + type = string + description = "Subdomain to use for the origin in requests to the CDN" +} + diff --git a/terraform/providers/dev/cdn.tf b/terraform/providers/dev/cdn.tf new file mode 100644 index 00000000..3b379b90 --- /dev/null +++ b/terraform/providers/dev/cdn.tf @@ -0,0 +1,8 @@ +module "cdn" { + source = "../../modules/cdn" + origin_host_name = "staging.atat.code.mil" + owner = var.owner + environment = var.environment + name = var.name + region = var.region +} From 0925c73c6878eec2e596d3dad92b9fde1c1b264d Mon Sep 17 00:00:00 2001 From: Rob Gil Date: Wed, 18 Dec 2019 18:47:02 -0500 Subject: [PATCH 4/5] Terraform fmt across new modules --- terraform/modules/cdn/variables.tf | 10 +++--- terraform/modules/redis/main.tf | 6 ++-- terraform/modules/redis/variables.tf | 46 ++++++++++++++-------------- terraform/providers/dev/cdn.tf | 10 +++--- terraform/providers/dev/redis.tf | 8 ++--- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/terraform/modules/cdn/variables.tf b/terraform/modules/cdn/variables.tf index a026ffed..3abe4851 100644 --- a/terraform/modules/cdn/variables.tf +++ b/terraform/modules/cdn/variables.tf @@ -19,13 +19,13 @@ variable "owner" { } variable "sku" { - type = string - description = "SKU of which CDN to use" - default = "Standard_Verizon" + type = string + description = "SKU of which CDN to use" + default = "Standard_Verizon" } variable "origin_host_name" { - type = string - description = "Subdomain to use for the origin in requests to the CDN" + type = string + description = "Subdomain to use for the origin in requests to the CDN" } diff --git a/terraform/modules/redis/main.tf b/terraform/modules/redis/main.tf index 1e47f767..90a88a2b 100644 --- a/terraform/modules/redis/main.tf +++ b/terraform/modules/redis/main.tf @@ -15,10 +15,10 @@ resource "azurerm_redis_cache" "redis" { minimum_tls_version = var.minimum_tls_version redis_configuration { - enable_authentication = var.enable_authentication + enable_authentication = var.enable_authentication } tags = { - environment = var.environment - owner = var.owner + environment = var.environment + owner = var.owner } } diff --git a/terraform/modules/redis/variables.tf b/terraform/modules/redis/variables.tf index ecdb7636..dac8819b 100644 --- a/terraform/modules/redis/variables.tf +++ b/terraform/modules/redis/variables.tf @@ -19,42 +19,42 @@ variable "owner" { } variable "capacity" { - type = string - default = 2 - description = "The capacity of the redis cache" - + type = string + default = 2 + description = "The capacity of the redis cache" + } variable "family" { - type = string - default = "C" - description = "The subscription family for redis" - + type = string + default = "C" + description = "The subscription family for redis" + } variable "sku_name" { - type = string - default = "Standard" - description = "The sku to use" - + type = string + default = "Standard" + description = "The sku to use" + } variable "enable_non_ssl_port" { - type = bool - default = false - description = "Enable non TLS port (default: false)" - + type = bool + default = false + description = "Enable non TLS port (default: false)" + } variable "minimum_tls_version" { - type = string - default = "1.2" - description = "Minimum TLS version to use" - + type = string + default = "1.2" + description = "Minimum TLS version to use" + } variable "enable_authentication" { - type = bool - default = true - description = "Enable or disable authentication (default: true)" + type = bool + default = true + description = "Enable or disable authentication (default: true)" } diff --git a/terraform/providers/dev/cdn.tf b/terraform/providers/dev/cdn.tf index 3b379b90..02c17e3d 100644 --- a/terraform/providers/dev/cdn.tf +++ b/terraform/providers/dev/cdn.tf @@ -1,8 +1,8 @@ module "cdn" { - source = "../../modules/cdn" + source = "../../modules/cdn" origin_host_name = "staging.atat.code.mil" - owner = var.owner - environment = var.environment - name = var.name - region = var.region + owner = var.owner + environment = var.environment + name = var.name + region = var.region } diff --git a/terraform/providers/dev/redis.tf b/terraform/providers/dev/redis.tf index fca3a4e3..bfe47a84 100644 --- a/terraform/providers/dev/redis.tf +++ b/terraform/providers/dev/redis.tf @@ -1,7 +1,7 @@ module "redis" { - source = "../../modules/redis" - owner = var.owner + source = "../../modules/redis" + owner = var.owner environment = var.environment - region = var.region - name = var.name + region = var.region + name = var.name } From 7aeda9377e9a810cc542d5866bbb238f4eaaeb8c Mon Sep 17 00:00:00 2001 From: Rob Gil Date: Wed, 18 Dec 2019 20:55:58 -0500 Subject: [PATCH 5/5] 169163334 - Adds LB module --- terraform/modules/lb/main.tf | 22 ++++++++++++++++++++++ terraform/modules/lb/outputs.tf | 0 terraform/modules/lb/variables.tf | 19 +++++++++++++++++++ terraform/providers/dev/k8s.tf | 7 +++++++ 4 files changed, 48 insertions(+) create mode 100644 terraform/modules/lb/main.tf create mode 100644 terraform/modules/lb/outputs.tf create mode 100644 terraform/modules/lb/variables.tf diff --git a/terraform/modules/lb/main.tf b/terraform/modules/lb/main.tf new file mode 100644 index 00000000..1c9acace --- /dev/null +++ b/terraform/modules/lb/main.tf @@ -0,0 +1,22 @@ +resource "azurerm_resource_group" "lb" { + name = "${var.name}-${var.environment}-lb" + location = var.region +} + +resource "azurerm_public_ip" "lb" { + name = "${var.name}-${var.environment}-ip" + location = var.region + resource_group_name = azurerm_resource_group.lb.name + allocation_method = "Static" +} + +resource "azurerm_lb" "lb" { + name = "${var.name}-${var.environment}-lb" + location = var.region + resource_group_name = azurerm_resource_group.lb.name + + frontend_ip_configuration { + name = "${var.name}-${var.environment}-ip" + public_ip_address_id = azurerm_public_ip.lb.id + } +} diff --git a/terraform/modules/lb/outputs.tf b/terraform/modules/lb/outputs.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/modules/lb/variables.tf b/terraform/modules/lb/variables.tf new file mode 100644 index 00000000..10fa56e9 --- /dev/null +++ b/terraform/modules/lb/variables.tf @@ -0,0 +1,19 @@ +variable "region" { + type = string + description = "Region this module and resources will be created in" +} + +variable "name" { + type = string + description = "Unique name for the services in this module" +} + +variable "environment" { + type = string + description = "Environment these resources reside (prod, dev, staging, etc)" +} + +variable "owner" { + type = string + description = "Owner of the environment and resources created in this module" +} \ No newline at end of file diff --git a/terraform/providers/dev/k8s.tf b/terraform/providers/dev/k8s.tf index b41df8a4..22120c93 100644 --- a/terraform/providers/dev/k8s.tf +++ b/terraform/providers/dev/k8s.tf @@ -9,3 +9,10 @@ module "k8s" { vnet_subnet_id = module.vpc.subnets #FIXME - output from module.vpc.subnets should be map } +module "lb" { + source = "../../modules/lb" + region = var.region + name = var.name + environment = var.environment + owner = var.owner +}