From 02ea0998cc131fe663d9259ec9525bbe1761bb8e Mon Sep 17 00:00:00 2001 From: Mark Boyd Date: Mon, 13 Nov 2023 14:46:18 -0500 Subject: [PATCH] Add test CDN app & service (#779) * add test CDN module to deploy test CDN app * add comment --- terraform/modules/test_cdn/test_cdn.tf | 48 +++++++++++++++++++++++++ terraform/modules/test_cdn/variables.tf | 7 ++++ terraform/stack/asg.tf | 31 ---------------- terraform/stack/data.tf | 20 +++++++++++ terraform/stack/main.tf | 6 ++++ terraform/stack/providers.tf | 6 ++++ terraform/stack/variables.tf | 11 ++++++ 7 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 terraform/modules/test_cdn/test_cdn.tf create mode 100644 terraform/modules/test_cdn/variables.tf create mode 100644 terraform/stack/data.tf create mode 100644 terraform/stack/main.tf create mode 100644 terraform/stack/providers.tf create mode 100644 terraform/stack/variables.tf diff --git a/terraform/modules/test_cdn/test_cdn.tf b/terraform/modules/test_cdn/test_cdn.tf new file mode 100644 index 00000000..565b4621 --- /dev/null +++ b/terraform/modules/test_cdn/test_cdn.tf @@ -0,0 +1,48 @@ +locals { + domain_name = var.iaas_stack_name == "staging" ? "fr-stage.cloud.gov" : "fr.cloud.gov" +} + +data "cloudfoundry_domain" "fr_domain" { + name = local.domain_name +} + +data "cloudfoundry_service" "external_domain" { + name = "external-domain" +} + +resource "zipper_file" "test_cdn_src" { + source = "https://github.com/cloud-gov/cf-hello-worlds/tree/main/static" + output_path = "test-static-app.zip" +} + +resource "cloudfoundry_route" "test_cdn_route" { + domain = data.cloudfoundry_domain.fr_domain.id + space = var.space_id + hostname = "test-cdn" +} + +# DNS records: +# https://github.com/cloud-gov/cg-provision/blob/417000c786a101988c3edd965f7c78f66ad334fe/terraform/stacks/dns/staging.tf#L25-L30 +# https://github.com/cloud-gov/cg-provision/blob/417000c786a101988c3edd965f7c78f66ad334fe/terraform/stacks/dns/production.tf#L12-L17 +resource "cloudfoundry_service_instance" "test_cdn_instance" { + name = "test-cdn-service" + space = var.space_id + service_plan = data.cloudfoundry_service.external_domain.service_plans["domain-with-cdn"] + json_params = "{\"domains\": \"test-cdn.${local.domain_name}\"}" +} + +resource "cloudfoundry_app" "test-cdn" { + name = "test-cdn" + buildpack = "staticfile_buildpack" + space = var.space_id + path = zipper_file.test_cdn_src.output_path + source_code_hash = zipper_file.test_cdn_src.output_sha + + routes { + route = cloudfoundry_route.test_cdn_route.id + } + + service_binding { + service_instance = cloudfoundry_service_instance.test_cdn_instance.id + } +} diff --git a/terraform/modules/test_cdn/variables.tf b/terraform/modules/test_cdn/variables.tf new file mode 100644 index 00000000..697900ff --- /dev/null +++ b/terraform/modules/test_cdn/variables.tf @@ -0,0 +1,7 @@ +variable "iaas_stack_name" { +} + +variable "space_id" { + type = string + description = "Space GUID to deploy test CDN app" +} diff --git a/terraform/stack/asg.tf b/terraform/stack/asg.tf index 4fb0accb..88b13a29 100644 --- a/terraform/stack/asg.tf +++ b/terraform/stack/asg.tf @@ -1,39 +1,8 @@ -variable "remote_state_bucket" { -} - -variable "tooling_stack_name" { -} - -variable "iaas_stack_name" { -} - -variable "domain_name" { -} - terraform { backend "s3" { } } -provider "cloudfoundry" { -} - -data "terraform_remote_state" "iaas" { - backend = "s3" - config = { - bucket = var.remote_state_bucket - key = "${var.iaas_stack_name}/terraform.tfstate" - } -} - -data "terraform_remote_state" "tooling" { - backend = "s3" - config = { - bucket = var.remote_state_bucket - key = "${var.tooling_stack_name}/terraform.tfstate" - } -} - resource "cloudfoundry_asg" "public_networks" { name = "public_networks" diff --git a/terraform/stack/data.tf b/terraform/stack/data.tf new file mode 100644 index 00000000..7031a53d --- /dev/null +++ b/terraform/stack/data.tf @@ -0,0 +1,20 @@ +data "terraform_remote_state" "iaas" { + backend = "s3" + config = { + bucket = var.remote_state_bucket + key = "${var.iaas_stack_name}/terraform.tfstate" + } +} + +data "terraform_remote_state" "tooling" { + backend = "s3" + config = { + bucket = var.remote_state_bucket + key = "${var.tooling_stack_name}/terraform.tfstate" + } +} + +data "cloudfoundry_space" "hello_worlds" { + name = "hello-worlds" + org = cloudfoundry_org.cloud-gov.id +} diff --git a/terraform/stack/main.tf b/terraform/stack/main.tf new file mode 100644 index 00000000..8809a9c5 --- /dev/null +++ b/terraform/stack/main.tf @@ -0,0 +1,6 @@ +module "test_cdn" { + count = var.iaas_stack_name == "development" ? 0 : 1 + source = "../modules/test_cdn" + iaas_stack_name = var.iaas_stack_name + space_id = data.cloudfoundry_space.hello_worlds.id +} diff --git a/terraform/stack/providers.tf b/terraform/stack/providers.tf new file mode 100644 index 00000000..5dd3d779 --- /dev/null +++ b/terraform/stack/providers.tf @@ -0,0 +1,6 @@ +provider "cloudfoundry" { +} + +provider "zipper" { + skip_ssl_validation = false +} diff --git a/terraform/stack/variables.tf b/terraform/stack/variables.tf new file mode 100644 index 00000000..036d09a2 --- /dev/null +++ b/terraform/stack/variables.tf @@ -0,0 +1,11 @@ +variable "remote_state_bucket" { +} + +variable "tooling_stack_name" { +} + +variable "iaas_stack_name" { +} + +variable "domain_name" { +}