Skip to content

Commit

Permalink
[kops] Parameterize state backend (#34)
Browse files Browse the repository at this point in the history
* Parameterize kops setup

* Add domain_enabled flag to support gossip mode

* Add `force_destroy` flag to facilitate testing

* Autoapprove destroy parameter
  • Loading branch information
osterman authored Aug 4, 2018
1 parent 1e16003 commit 8b81c5b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ build-harness
*.tfstate.*
.idea
*.iml
.viminfo
.terraform.d
15 changes: 15 additions & 0 deletions aws/kops/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Initialize terraform remote state
init:
init-terraform

## Show terraform plan for this project
plan: init
terraform plan

## Apply terraform plan for this project
apply: init
terraform apply $(TERRAFORM_ARGS)

## Destroy terraform project
destroy: init
terraform destroy $(TERRAFORM_ARGS)
36 changes: 32 additions & 4 deletions aws/kops/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ variable "stage" {
description = "Stage (e.g. `prod`, `dev`, `staging`)"
}

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

variable "region" {
type = "string"
description = "AWS region"
Expand All @@ -28,28 +34,50 @@ variable "zone_name" {
description = "DNS zone name"
}

variable "domain_enabled" {
type = "string"
description = "Enable DNS Zone creation for kops"
default = "true"
}

variable "force_destroy" {
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 "ssh_public_key_path" {
type = "string"
description = "SSH public key path to write master public/private key pair for cluster"
default = "/secrets/tf/ssh"
}

provider "aws" {
assume_role {
role_arn = "${var.aws_assume_role_arn}"
}
}

module "kops_state_backend" {
source = "git::https://github.com/cloudposse/terraform-aws-kops-state-backend.git?ref=tags/0.1.3"
source = "git::https://github.com/cloudposse/terraform-aws-kops-state-backend.git?ref=tags/0.1.5"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "kops-state"
name = "${var.name}"
attributes = ["state"]
cluster_name = "${var.region}"
parent_zone_name = "${var.zone_name}"
zone_name = "$${name}.$${parent_zone_name}"
domain_enabled = "${var.domain_enabled}"
force_destroy = "${var.force_destroy}"
region = "${var.region}"
}

module "ssh_key_pair" {
source = "git::https://github.com/cloudposse/terraform-aws-key-pair.git?ref=tags/0.2.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "kops-${var.region}"
ssh_public_key_path = "/secrets/tf/ssh"
name = "${var.name}"
attributes = ["${var.region}"]
ssh_public_key_path = "${var.ssh_public_key_path}"
generate_ssh_key = "true"
}
2 changes: 1 addition & 1 deletion aws/kops/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ output "ssh_key_name" {
value = "${module.ssh_key_pair.key_name}"
}

output "shh_public_key" {
output "ssh_public_key" {
value = "${module.ssh_key_pair.public_key}"
}
1 change: 1 addition & 0 deletions aws/kops/terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ namespace="cp"
stage="staging"
region="us-west-2"
zone_name="us-west-2.cloudposse.co"
domain_enabled="true"
2 changes: 1 addition & 1 deletion codefresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ steps:
title: Init variables
image: alpine
commands:
- cf_export BUILD_HARNESS_VERSION=0.5.5
- cf_export BUILD_HARNESS_VERSION=0.7.0
- cf_export GIT_BRANCH=${{CF_BRANCH}}

build_image:
Expand Down

0 comments on commit 8b81c5b

Please sign in to comment.