Skip to content
This repository has been archived by the owner on Jan 30, 2021. It is now read-only.

Terraform 0.12 changes #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 41 additions & 43 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,71 @@ provider "aws" {
version = "~> 2.17"

alias = "s3"
region = "${var.region}"
region = var.region
}

data "template_file" "zone_name" {
template = "${replace(var.zone_name, "$$$$", "$")}"
template = replace(var.zone_name, "$$$$", "$")

vars {
namespace = "${var.namespace}"
name = "${var.cluster_name}"
stage = "${var.stage}"
parent_zone_name = "${var.parent_zone_name}"
vars = {
namespace = var.namespace
name = var.cluster_name
stage = var.stage
parent_zone_name = var.parent_zone_name
}
}

locals {
create_s3_bucket = "${!(var.create_bucket == "false")}"
create_s3_bucket = !(var.create_bucket == "false")

tags = "${
merge(
tags = merge(
var.tags,
map(
"Cluster", "${data.template_file.zone_name.rendered}"
"Cluster", data.template_file.zone_name.rendered
)
)
}"
}

# Kops domain (e.g. `kops.domain.com`)
module "domain" {
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-zone.git?ref=tags/0.3.1"
namespace = "${var.namespace}"
name = "${var.cluster_name}"
stage = "${var.stage}"
delimiter = "${var.delimiter}"
attributes = "${var.attributes}"
zone_name = "${var.zone_name}"
parent_zone_id = "${var.parent_zone_id}"
parent_zone_name = "${var.parent_zone_name}"
tags = "${local.tags}"
enabled = "${var.domain_enabled}"
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-zone.git?ref=tags/0.4.0"
namespace = var.namespace
name = var.cluster_name
stage = var.stage
delimiter = var.delimiter
attributes = var.attributes
zone_name = var.zone_name
parent_zone_id = var.parent_zone_id
parent_zone_name = var.parent_zone_name
tags = local.tags
enabled = var.domain_enabled
}

module "s3_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
delimiter = "${var.delimiter}"
attributes = "${var.attributes}"
tags = "${local.tags}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
namespace = var.namespace
name = var.name
stage = var.stage
delimiter = var.delimiter
attributes = var.attributes
tags = local.tags
}

data "aws_s3_bucket" "default" {
provider = "aws.s3"
provider = aws.s3

count = "${local.create_s3_bucket ? 0 : 1}"
bucket = "${module.s3_label.id}"
count = local.create_s3_bucket ? 0 : 1
bucket = module.s3_label.id
}

resource "aws_s3_bucket" "default" {
provider = "aws.s3"
provider = aws.s3

count = "${local.create_s3_bucket ? 1 : 0}"
bucket = "${module.s3_label.id}"
acl = "${var.acl}"
region = "${var.region}"
force_destroy = "${var.force_destroy}"
count = local.create_s3_bucket ? 1 : 0
bucket = module.s3_label.id
acl = var.acl
region = var.region
force_destroy = var.force_destroy

versioning {
enabled = true
Expand All @@ -82,14 +80,14 @@ resource "aws_s3_bucket" "default" {
}
}

tags = "${module.s3_label.tags}"
tags = module.s3_label.tags
}

resource "aws_s3_bucket_public_access_block" "default" {
provider = "aws.s3"
provider = aws.s3

count = "${local.create_s3_bucket && var.block_public_access_enabled == "true" ? 1 : 0}"
bucket = "${aws_s3_bucket.default.id}"
count = local.create_s3_bucket && var.block_public_access_enabled == "true" ? 1 : 0
bucket = aws_s3_bucket.default[0].id

block_public_acls = true
block_public_policy = true
Expand Down
32 changes: 16 additions & 16 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
variable "namespace" {
type = "string"
type = string
description = "Namespace (e.g. `eg` or `cp`)"
}

variable "stage" {
type = "string"
type = string
description = "Stage (e.g. `prod`, `dev`, `staging`)"
}

variable "name" {
type = "string"
type = string
default = "kops-state"
description = "Name (e.g. `kops-state`)"
}

variable "cluster_name" {
type = "string"
type = string
default = "us-east-1"
description = "Kops cluster name (e.g. `us-east-1` or `cluster-1`)"
}

variable "delimiter" {
type = "string"
type = string
default = "-"
description = "Delimiter to be used between `namespace`, `stage`, `name`, and `attributes`"
}

variable "attributes" {
type = "list"
type = list(string)
default = []
description = "Additional attributes (e.g. `1`)"
}

variable "tags" {
type = "map"
type = map(string)
default = {}
description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)"
}

variable "zone_name" {
type = "string"
type = string
default = "$${name}.$${parent_zone_name}"
description = "Template for the DNS zone name"
}

variable "parent_zone_id" {
type = "string"
type = string
default = ""
description = "Parent DNS zone ID"
}

variable "parent_zone_name" {
type = "string"
type = string
default = ""
description = "Parent DNS zone name (e.g. `domain.com`)"
}

variable "region" {
type = "string"
type = string
description = "AWS Region the S3 bucket should reside in"
default = "us-east-1"
}

variable "acl" {
type = "string"
type = string
description = "The canned ACL to apply to the S3 bucket"
default = "private"
}

variable "block_public_access_enabled" {
type = "string"
type = string
description = "Block all public access from bucket level"
default = "true"
}

variable "force_destroy" {
type = "string"
type = string
description = "A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without errors. These objects are not recoverable"
default = false
}

variable "domain_enabled" {
type = "string"
type = string
default = "true"
description = "A boolean that determines whether a DNS Zone for the kops domain is created"
}

variable "create_bucket" {
type = "string"
type = string
default = "true"
description = "Set to `false` to use existing S3 bucket for kops state store instead of creating one."
}