Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from gruntwork-io/terraform12
Browse files Browse the repository at this point in the history
TF12
  • Loading branch information
autero1 authored Jun 11, 2019
2 parents d3b8ed5 + f91a3a3 commit ac51064
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 227 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ defaults: &defaults
machine: true
environment:
GRUNTWORK_INSTALLER_VERSION: v0.0.21
TERRATEST_LOG_PARSER_VERSION: v0.13.24
MODULE_CI_VERSION: v0.13.3
TERRAFORM_VERSION: 0.11.8
TERRATEST_LOG_PARSER_VERSION: v0.16.1
MODULE_CI_VERSION: v0.13.15
TERRAFORM_VERSION: 0.12.1
TERRAGRUNT_VERSION: NONE
PACKER_VERSION: NONE
GOLANG_VERSION: 1.11.2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Maintained by Gruntwork.io](https://img.shields.io/badge/maintained%20by-gruntwork.io-%235849a6.svg)](https://gruntwork.io/?ref=repo_google_static_assets)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gruntwork-io/terraform-google-static-assets.svg?label=latest)](https://github.com/gruntwork-io/terraform-google-static-assets/releases/latest)

![Terraform Version](https://img.shields.io/badge/tf-%3E%3D0.12.0-blue.svg)
<!-- NOTE: Because the module is published to Terraform Module Registry, we have to use absolute links in all READMEs. -->

# Static Assets Modules
Expand Down
71 changes: 39 additions & 32 deletions examples/http-load-balancer-website/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
# This is an example of how to use the cloud-load-balancer-website module to deploy a static website with a custom domain.
# ---------------------------------------------------------------------------------------------------------------------

terraform {
# The modules used in this example have been updated with 0.12 syntax, which means the example is no longer
# compatible with any versions below 0.12.
required_version = ">= 0.12"
}

# ------------------------------------------------------------------------------
# CONFIGURE OUR GCP CONNECTION
# ------------------------------------------------------------------------------

provider "google-beta" {
project = "${var.project}"
project = var.project
}

# ------------------------------------------------------------------------------
Expand All @@ -22,59 +28,59 @@ module "static_site" {
# source = "github.com/gruntwork-io/terraform-google-static-assets.git//modules/http-load-balancer-website?ref=v0.1.1"
source = "../../modules/http-load-balancer-website"

project = "${var.project}"
project = var.project

website_domain_name = "${var.website_domain_name}"
website_location = "${var.website_location}"
website_domain_name = var.website_domain_name
website_location = var.website_location

force_destroy_access_logs_bucket = "${var.force_destroy_access_logs_bucket}"
force_destroy_website = "${var.force_destroy_website}"
force_destroy_access_logs_bucket = var.force_destroy_access_logs_bucket
force_destroy_website = var.force_destroy_website

create_dns_entry = "${var.create_dns_entry}"
dns_record_ttl = "${var.dns_record_ttl}"
dns_managed_zone_name = "${var.dns_managed_zone_name}"
create_dns_entry = var.create_dns_entry
dns_record_ttl = var.dns_record_ttl
dns_managed_zone_name = var.dns_managed_zone_name

enable_versioning = "${var.enable_versioning}"
enable_versioning = var.enable_versioning

index_page = "${var.index_page}"
not_found_page = "${var.not_found_page}"
index_page = var.index_page
not_found_page = var.not_found_page

enable_cdn = false
enable_ssl = "${var.enable_ssl}"
enable_http = "${var.enable_http}"
enable_ssl = var.enable_ssl
enable_http = var.enable_http

ssl_certificate = "${join("", google_compute_ssl_certificate.certificate.*.self_link)}"
ssl_certificate = join("", google_compute_ssl_certificate.certificate.*.self_link)
}

# ------------------------------------------------------------------------------
# CREATE DEFAULT PAGES
# ------------------------------------------------------------------------------

resource "google_storage_bucket_object" "index" {
name = "${var.index_page}"
name = var.index_page
content = "Hello, World!"
bucket = "${module.static_site.website_bucket_name}"
bucket = module.static_site.website_bucket_name
}

resource "google_storage_bucket_object" "not_found" {
name = "${var.not_found_page}"
name = var.not_found_page
content = "Uh oh"
bucket = "${module.static_site.website_bucket_name}"
bucket = module.static_site.website_bucket_name
}

# ------------------------------------------------------------------------------
# SET GLOBAL READ PERMISSIONS
# ------------------------------------------------------------------------------

resource "google_storage_object_acl" "index_acl" {
bucket = "${module.static_site.website_bucket_name}"
object = "${google_storage_bucket_object.index.name}"
bucket = module.static_site.website_bucket_name
object = google_storage_bucket_object.index.name
role_entity = ["READER:allUsers"]
}

resource "google_storage_object_acl" "not_found_acl" {
bucket = "${module.static_site.website_bucket_name}"
object = "${google_storage_bucket_object.not_found.name}"
bucket = module.static_site.website_bucket_name
object = google_storage_bucket_object.not_found.name
role_entity = ["READER:allUsers"]
}

Expand All @@ -85,13 +91,13 @@ resource "google_storage_object_acl" "not_found_acl" {
# ------------------------------------------------------------------------------

resource "tls_self_signed_cert" "cert" {
count = "${var.enable_ssl ? 1 :0}"
count = var.enable_ssl ? 1 : 0

key_algorithm = "RSA"
private_key_pem = "${join("", tls_private_key.private_key.*.private_key_pem)}"
private_key_pem = join("", tls_private_key.private_key.*.private_key_pem)

subject {
common_name = "${var.website_domain_name}"
common_name = var.website_domain_name
organization = "Examples, Inc"
}

Expand All @@ -105,7 +111,7 @@ resource "tls_self_signed_cert" "cert" {
}

resource "tls_private_key" "private_key" {
count = "${var.enable_ssl ? 1 :0}"
count = var.enable_ssl ? 1 : 0

algorithm = "RSA"
ecdsa_curve = "P256"
Expand All @@ -116,17 +122,18 @@ resource "tls_private_key" "private_key" {
# ------------------------------------------------------------------------------

resource "google_compute_ssl_certificate" "certificate" {
count = "${var.enable_ssl ? 1 :0}"
count = var.enable_ssl ? 1 : 0

project = "${var.project}"
provider = "google-beta"
project = var.project
provider = google-beta

name_prefix = "petri-test"
description = "SSL Certificate for ${var.website_domain_name}"
private_key = "${join("", tls_private_key.private_key.*.private_key_pem)}"
certificate = "${join("", tls_self_signed_cert.cert.*.cert_pem)}"
private_key = join("", tls_private_key.private_key.*.private_key_pem)
certificate = join("", tls_self_signed_cert.cert.*.cert_pem)

lifecycle {
create_before_destroy = true
}
}

13 changes: 7 additions & 6 deletions examples/http-load-balancer-website/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@

output "website_url" {
description = "URL of the website"
value = "${module.static_site.website_url}"
value = module.static_site.website_url
}

output "load_balancer_ip_address" {
description = "Public IP address of the HTTP Load Balancer"
value = "${module.static_site.load_balancer_ip_address}"
value = module.static_site.load_balancer_ip_address
}

output "website_bucket" {
description = "Self link of the website bucket"
value = "${module.static_site.website_bucket}"
value = module.static_site.website_bucket
}

output "website_bucket_name" {
description = "Name of the website bucket"
value = "${module.static_site.website_bucket_name}"
value = module.static_site.website_bucket_name
}

output "access_logs_bucket" {
description = "Self link of the access logs bucket"
value = "${module.static_site.access_logs_bucket}"
value = module.static_site.access_logs_bucket
}

output "access_logs_bucket_name" {
description = "Name of the access logs bucket"
value = "${module.static_site.access_logs_bucket_name}"
value = module.static_site.access_logs_bucket_name
}

14 changes: 14 additions & 0 deletions examples/http-load-balancer-website/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

variable "project" {
description = "The project ID to host the site in."
type = string
}

variable "website_domain_name" {
description = "The name of the website and the Cloud Storage bucket to create (e.g. static.foo.com)."
type = string
}

# ---------------------------------------------------------------------------------------------------------------------
Expand All @@ -18,55 +20,67 @@ variable "website_domain_name" {

variable "enable_http" {
description = "Set to false to disable plain HTTP. Note that disabling http does not force SSL and/or redirect HTTP traffic. See https://issuetracker.google.com/issues/35904733."
type = bool
default = true
}

variable "enable_ssl" {
description = "Set to true to enable SSL. If set to 'true', self-signed certificates are created for you."
type = bool
default = false
}

variable "create_dns_entry" {
description = "If set to true, create a DNS A Record pointing to the LB IP in Cloud DNS using the domain name in var.website_domain_name."
type = bool
default = false
}

variable "dns_managed_zone_name" {
description = "The name of the Cloud DNS Managed Zone in which to create the DNS A Record specified in var.website_domain_name. Only used if var.create_dns_entry is true."
type = string
default = "replace-me"
}

variable "dns_record_ttl" {
description = "The time-to-live for the site CNAME record set (seconds)"
type = number
default = 60
}

variable "website_location" {
description = "Location of the bucket that will store the static website. Once a bucket has been created, its location can't be changed. See https://cloud.google.com/storage/docs/bucket-locations"
type = string
default = "US"
}

variable "enable_versioning" {
description = "Set to true to enable versioning. This means the website bucket will retain all old versions of all files. This is useful for backup purposes (e.g. you can rollback to an older version), but it may mean your bucket uses more storage."
type = bool
default = false
}

variable "index_page" {
description = "Bucket's directory index"
type = string
default = "index.html"
}

variable "not_found_page" {
description = "The custom object to return when a requested resource is not found"
type = string
default = "404.html"
}

variable "force_destroy_website" {
description = "If set to true, this will force the delete of the website bucket when you run terraform destroy, even if there is still content in it. This is only meant for testing and should not be used in production."
type = bool
default = true
}

variable "force_destroy_access_logs_bucket" {
description = "If set to true, this will force the delete of the access logs bucket when you run terraform destroy, even if there is still content in it. This is only meant for testing and should not be used in production."
type = bool
default = true
}

47 changes: 27 additions & 20 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
# This is an example of how to use the cloud-storage-static-website module to deploy a static website with a custom domain.
# ---------------------------------------------------------------------------------------------------------------------

terraform {
# The modules used in this example have been updated with 0.12 syntax, which means the example is no longer
# compatible with any versions below 0.12.
required_version = ">= 0.12"
}

# ------------------------------------------------------------------------------
# CONFIGURE OUR GCP CONNECTION
# ------------------------------------------------------------------------------

provider "google-beta" {
project = "${var.project}"
project = var.project
}

# ------------------------------------------------------------------------------
Expand All @@ -22,52 +28,53 @@ module "static_site" {
# source = "github.com/gruntwork-io/terraform-google-static-assets.git//modules/cloud-storage-static-website?ref=v0.1.1"
source = "./modules/cloud-storage-static-website"

project = "${var.project}"
project = var.project

website_domain_name = "${var.website_domain_name}"
website_location = "${var.website_location}"
website_domain_name = var.website_domain_name
website_location = var.website_location

force_destroy_access_logs_bucket = "${var.force_destroy_access_logs_bucket}"
force_destroy_website = "${var.force_destroy_website}"
force_destroy_access_logs_bucket = var.force_destroy_access_logs_bucket
force_destroy_website = var.force_destroy_website

create_dns_entry = "${var.create_dns_entry}"
dns_record_ttl = "${var.dns_record_ttl}"
dns_managed_zone_name = "${var.dns_managed_zone_name}"
create_dns_entry = var.create_dns_entry
dns_record_ttl = var.dns_record_ttl
dns_managed_zone_name = var.dns_managed_zone_name

enable_versioning = "${var.enable_versioning}"
enable_versioning = var.enable_versioning

index_page = "${var.index_page}"
not_found_page = "${var.not_found_page}"
index_page = var.index_page
not_found_page = var.not_found_page
}

# ------------------------------------------------------------------------------
# CREATE DEFAULT PAGES
# ------------------------------------------------------------------------------

resource "google_storage_bucket_object" "index" {
name = "${var.index_page}"
name = var.index_page
content = "Hello, World!"
bucket = "${module.static_site.website_bucket_name}"
bucket = module.static_site.website_bucket_name
}

resource "google_storage_bucket_object" "not_found" {
name = "${var.not_found_page}"
name = var.not_found_page
content = "Uh oh"
bucket = "${module.static_site.website_bucket_name}"
bucket = module.static_site.website_bucket_name
}

# ------------------------------------------------------------------------------
# SET GLOBAL READ PERMISSIONS
# ------------------------------------------------------------------------------

resource "google_storage_object_acl" "index_acl" {
bucket = "${module.static_site.website_bucket_name}"
object = "${google_storage_bucket_object.index.name}"
bucket = module.static_site.website_bucket_name
object = google_storage_bucket_object.index.name
role_entity = ["READER:allUsers"]
}

resource "google_storage_object_acl" "not_found_acl" {
bucket = "${module.static_site.website_bucket_name}"
object = "${google_storage_bucket_object.not_found.name}"
bucket = module.static_site.website_bucket_name
object = google_storage_bucket_object.not_found.name
role_entity = ["READER:allUsers"]
}

Loading

0 comments on commit ac51064

Please sign in to comment.