Skip to content

Commit

Permalink
Add test CDN app & service (#779)
Browse files Browse the repository at this point in the history
* add test CDN module to deploy test CDN app

* add comment
  • Loading branch information
markdboyd authored Nov 13, 2023
1 parent 8d6fc81 commit 02ea099
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 31 deletions.
48 changes: 48 additions & 0 deletions terraform/modules/test_cdn/test_cdn.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 7 additions & 0 deletions terraform/modules/test_cdn/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "iaas_stack_name" {
}

variable "space_id" {
type = string
description = "Space GUID to deploy test CDN app"
}
31 changes: 0 additions & 31 deletions terraform/stack/asg.tf
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
20 changes: 20 additions & 0 deletions terraform/stack/data.tf
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions terraform/stack/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions terraform/stack/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
provider "cloudfoundry" {
}

provider "zipper" {
skip_ssl_validation = false
}
11 changes: 11 additions & 0 deletions terraform/stack/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "remote_state_bucket" {
}

variable "tooling_stack_name" {
}

variable "iaas_stack_name" {
}

variable "domain_name" {
}

0 comments on commit 02ea099

Please sign in to comment.