Skip to content

Commit

Permalink
Fix app zipfile for test CDN app (#782)
Browse files Browse the repository at this point in the history
* update CDN app to build zip file using terraform null_resource and archive_file

* add variables for source code and zipfile information

* remove unnecessary providers
  • Loading branch information
markdboyd authored Nov 15, 2023
1 parent 7f2d6f1 commit 23d8524
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
25 changes: 20 additions & 5 deletions terraform/modules/test_cdn/test_cdn.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
locals {
domain_name = var.iaas_stack_name == "staging" ? "fr-stage.cloud.gov" : "fr.cloud.gov"
clone_dir = "${path.module}/${var.git_clone_dir}"
zip_output_filepath = "${path.module}/${var.zip_output_filename}"
}

data "cloudfoundry_domain" "fr_domain" {
Expand All @@ -15,9 +17,22 @@ data "cloudfoundry_space" "hello_worlds" {
org = var.organization_id
}

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 "null_resource" "git_clone" {
triggers = {
on_every_apply = timestamp()
}

provisioner "local-exec" {
command = "git clone ${var.source_code_repo} ${local.clone_dir}"
}
}

data "archive_file" "test_cdn_app_src" {
depends_on = [null_resource.git_clone]

output_path = local.zip_output_filepath
source_dir = "${local.clone_dir}/${var.source_code_path}"
type = "zip"
}

resource "cloudfoundry_route" "test_cdn_route" {
Expand All @@ -40,8 +55,8 @@ resource "cloudfoundry_app" "test-cdn" {
name = "test-cdn"
buildpack = "staticfile_buildpack"
space = data.cloudfoundry_space.hello_worlds.id
path = zipper_file.test_cdn_src.output_path
source_code_hash = zipper_file.test_cdn_src.output_sha
path = local.zip_output_filepath
source_code_hash = data.archive_file.test_cdn_app_src.output_sha256

routes {
route = cloudfoundry_route.test_cdn_route.id
Expand Down
24 changes: 24 additions & 0 deletions terraform/modules/test_cdn/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,27 @@ variable "space_name" {
description = "Space name to use for test CDN app"
default = "hello-worlds"
}

variable "source_code_repo" {
type = string
description = "HTTPS link to git repo containing source code for test CDN app"
default = "https://github.com/cloud-gov/cf-hello-worlds.git"
}

variable "source_code_path" {
type = string
description = "Path in source_code_repo containing app code"
default = "static"
}

variable "git_clone_dir" {
type = string
description = "Subdirectory of module path to clone git repo"
default = "cf-hello-worlds"
}

variable "zip_output_filename" {
type = string
description = "Name of zip file containing source code for test CDN app"
default = "hello-world-static.zip"
}
5 changes: 0 additions & 5 deletions terraform/modules/test_cdn/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@ terraform {
source = "cloudfoundry-community/cloudfoundry"
version = "< 1.0.0"
}

zipper = {
source = "ArthurHlt/zipper"
version = "0.14.0"
}
}
}
1 change: 0 additions & 1 deletion terraform/stack/main.tf → terraform/stack/apps.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ module "test_cdn" {

providers = {
cloudfoundry = cloudfoundry
zipper = zipper
}
}
4 changes: 0 additions & 4 deletions terraform/stack/providers.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
provider "cloudfoundry" {
}

provider "zipper" {
skip_ssl_validation = false
}
5 changes: 0 additions & 5 deletions terraform/stack/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@ terraform {
source = "cloudfoundry-community/cloudfoundry"
version = "< 1.0.0"
}

zipper = {
source = "ArthurHlt/zipper"
version = "0.14.0"
}
}
}

0 comments on commit 23d8524

Please sign in to comment.