Skip to content

Commit 8b81c5b

Browse files
authored
[kops] Parameterize state backend (#34)
* Parameterize kops setup * Add domain_enabled flag to support gossip mode * Add `force_destroy` flag to facilitate testing * Autoapprove destroy parameter
1 parent 1e16003 commit 8b81c5b

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ build-harness
55
*.tfstate.*
66
.idea
77
*.iml
8+
.viminfo
9+
.terraform.d

aws/kops/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Initialize terraform remote state
2+
init:
3+
init-terraform
4+
5+
## Show terraform plan for this project
6+
plan: init
7+
terraform plan
8+
9+
## Apply terraform plan for this project
10+
apply: init
11+
terraform apply $(TERRAFORM_ARGS)
12+
13+
## Destroy terraform project
14+
destroy: init
15+
terraform destroy $(TERRAFORM_ARGS)

aws/kops/main.tf

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ variable "stage" {
1818
description = "Stage (e.g. `prod`, `dev`, `staging`)"
1919
}
2020

21+
variable "name" {
22+
type = "string"
23+
description = "Name (e.g. `kops`)"
24+
default = "kops"
25+
}
26+
2127
variable "region" {
2228
type = "string"
2329
description = "AWS region"
@@ -28,28 +34,50 @@ variable "zone_name" {
2834
description = "DNS zone name"
2935
}
3036

37+
variable "domain_enabled" {
38+
type = "string"
39+
description = "Enable DNS Zone creation for kops"
40+
default = "true"
41+
}
42+
43+
variable "force_destroy" {
44+
type = "string"
45+
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."
46+
default = "false"
47+
}
48+
49+
variable "ssh_public_key_path" {
50+
type = "string"
51+
description = "SSH public key path to write master public/private key pair for cluster"
52+
default = "/secrets/tf/ssh"
53+
}
54+
3155
provider "aws" {
3256
assume_role {
3357
role_arn = "${var.aws_assume_role_arn}"
3458
}
3559
}
3660

3761
module "kops_state_backend" {
38-
source = "git::https://github.com/cloudposse/terraform-aws-kops-state-backend.git?ref=tags/0.1.3"
62+
source = "git::https://github.com/cloudposse/terraform-aws-kops-state-backend.git?ref=tags/0.1.5"
3963
namespace = "${var.namespace}"
4064
stage = "${var.stage}"
41-
name = "kops-state"
65+
name = "${var.name}"
66+
attributes = ["state"]
4267
cluster_name = "${var.region}"
4368
parent_zone_name = "${var.zone_name}"
4469
zone_name = "$${name}.$${parent_zone_name}"
70+
domain_enabled = "${var.domain_enabled}"
71+
force_destroy = "${var.force_destroy}"
4572
region = "${var.region}"
4673
}
4774

4875
module "ssh_key_pair" {
4976
source = "git::https://github.com/cloudposse/terraform-aws-key-pair.git?ref=tags/0.2.3"
5077
namespace = "${var.namespace}"
5178
stage = "${var.stage}"
52-
name = "kops-${var.region}"
53-
ssh_public_key_path = "/secrets/tf/ssh"
79+
name = "${var.name}"
80+
attributes = ["${var.region}"]
81+
ssh_public_key_path = "${var.ssh_public_key_path}"
5482
generate_ssh_key = "true"
5583
}

aws/kops/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ output "ssh_key_name" {
3838
value = "${module.ssh_key_pair.key_name}"
3939
}
4040

41-
output "shh_public_key" {
41+
output "ssh_public_key" {
4242
value = "${module.ssh_key_pair.public_key}"
4343
}

aws/kops/terraform.tfvars.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ namespace="cp"
22
stage="staging"
33
region="us-west-2"
44
zone_name="us-west-2.cloudposse.co"
5+
domain_enabled="true"

codefresh.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ steps:
66
title: Init variables
77
image: alpine
88
commands:
9-
- cf_export BUILD_HARNESS_VERSION=0.5.5
9+
- cf_export BUILD_HARNESS_VERSION=0.7.0
1010
- cf_export GIT_BRANCH=${{CF_BRANCH}}
1111

1212
build_image:

0 commit comments

Comments
 (0)