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

Commit 8efd413

Browse files
authored
Separate S3 bucket name from Kops cluster name (#3)
* Separate S3 bucket name from Kops cluster name * Update examples
1 parent 78f97dc commit 8efd413

File tree

4 files changed

+56
-53
lines changed

4 files changed

+56
-53
lines changed

README.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ The module supports the following:
1010

1111
## Usage
1212

13-
This example will create a DNS zone called `kops.cloudxl.net` and delegate it from the parent zone `cloudxl.net` by setting `NS` and `SOA` records in the parent zone.
13+
This example will create a DNS zone called `us-east-1.cloudxl.net` and delegate it from the parent zone `cloudxl.net` by setting `NS` and `SOA` records in the parent zone.
1414

15-
It will also create an S3 bucket with the name `cp-prod-kops-state` for storing `kops` manifests.
15+
It will also create an S3 bucket with the name `cp-prod-kops-state` for storing `kops` state.
1616

1717
```hcl
1818
module "kops" {
1919
source = "git::https://github.com/cloudposse/terraform-aws-kops-state-backend.git?ref=master"
2020
namespace = "cp"
2121
stage = "prod"
22-
name = "kops"
23-
attributes = ["state"]
22+
bucket_name = "kops-state"
23+
cluster_name = "us-east-1"
2424
parent_zone_name = "cloudxl.net"
2525
zone_name = "$${name}.$${parent_zone_name}"
2626
region = "us-east-1"
@@ -33,23 +33,24 @@ module "kops" {
3333

3434
<br/>
3535

36-
To check that the created `kops` DNS zone has been tagged correctly, run
36+
To verify that the created `kops` DNS zone has been tagged correctly, run
3737

3838
```sh
39-
aws route53 list-tags-for-resources --resource-type hostedzone --resource-ids Z58RWQWFVU4HT
39+
aws route53 list-tags-for-resources --resource-type hostedzone --resource-ids Z27EGVGENRTTZZ
4040
```
4141

4242

4343
```js
44+
{
4445
{
4546
"ResourceTagSets": [
4647
{
4748
"ResourceType": "hostedzone",
48-
"ResourceId": "Z58RWQWFVU4HT",
49+
"ResourceId": "Z27EGVGENRTTZZ",
4950
"Tags": [
5051
{
5152
"Key": "Cluster",
52-
"Value": "kops.cloudxl.net"
53+
"Value": "us-east-1.cloudxl.net"
5354
},
5455
{
5556
"Key": "Stage",
@@ -61,7 +62,7 @@ aws route53 list-tags-for-resources --resource-type hostedzone --resource-ids Z5
6162
},
6263
{
6364
"Key": "Name",
64-
"Value": "cp-prod-kops-state"
65+
"Value": "cp-prod-us-east-1"
6566
}
6667
]
6768
}
@@ -76,20 +77,21 @@ __NOTE:__ One of `parent_zone_name` or `parent_zone_id` is required, but not bot
7677
The module will lookup the parent zone by either name or ID.
7778
7879
79-
| Name | Default | Description | Required |
80-
|:-------------------------|:----------------------------------|:----------------------------------------------------------------------------------|:--------:|
81-
| `namespace` | `` | Namespace (_e.g._ `cp` or `cloudposse`) | Yes |
82-
| `stage` | `` | Stage (_e.g._ `prod`, `dev`, `staging`) | Yes |
83-
| `region` | `us-east-1` | AWS Region the S3 bucket should reside in | Yes |
84-
| `parent_zone_name` | `` | Parent DNS zone name (e.g. `domain.com`). Required if `parent_zone_id` is not provided | Yes |
85-
| `parent_zone_id` | `` | Parent DNS zone ID. Required if `parent_zone_name` is not provided | Yes |
86-
| `name` | `kops` | Name (_e.g._ `kops`) | No |
87-
| `attributes` | `["state"]` | Additional attributes (_e.g._ `state`) | No |
88-
| `tags` | `{}` | Additional tags (_e.g._ `map("BusinessUnit","XYZ")` | No |
89-
| `delimiter` | `-` | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | No |
90-
| `acl` | `private` | The canned ACL to apply to the S3 bucket | No |
91-
| `zone_name` | `$${name}.$${parent_zone_name}` | Template for `kops` DNS zone name | No |
92-
| `force_destroy` | `false` | A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without errors | No |
80+
| Name | Default | Description | Required |
81+
|:-------------------------|:-----------------------------------------|:----------------------------------------------------------------------------------|:--------:|
82+
| `namespace` | `` | Namespace (_e.g._ `cp` or `cloudposse`) | Yes |
83+
| `stage` | `` | Stage (_e.g._ `prod`, `dev`, `staging`) | Yes |
84+
| `region` | `us-east-1` | AWS Region the S3 bucket should reside in | Yes |
85+
| `parent_zone_name` | `` | Parent DNS zone name (e.g. `domain.com`). Required if `parent_zone_id` is not provided | Yes |
86+
| `parent_zone_id` | `` | Parent DNS zone ID. Required if `parent_zone_name` is not provided | Yes |
87+
| `bucket_name` | `kops-state` | S3 bucket name (_e.g._ `kops-state`) | Yes |
88+
| `cluster_name` | `us-east-1` | Kops cluster name (_e.g._ `us-east-1` or `cluster-1`) | Yes |
89+
| `attributes` | `[]` | Additional attributes (_e.g._ `1`) | No |
90+
| `tags` | `{}` | Additional tags (_e.g._ `map("BusinessUnit","XYZ")` | No |
91+
| `delimiter` | `-` | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | No |
92+
| `acl` | `private` | The canned ACL to apply to the S3 bucket | No |
93+
| `zone_name` | `$${name}.$${parent_zone_name}` | Template for the DNS zone name | No |
94+
| `force_destroy` | `false` | A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without errors | No |
9395
9496
9597
## Outputs
@@ -98,8 +100,8 @@ The module will lookup the parent zone by either name or ID.
98100
|:-----------------------|:--------------------------|
99101
| `parent_zone_id` | Parent zone ID |
100102
| `parent_zone_name` | Parent zone name |
101-
| `zone_id` | `kops` zone ID |
102-
| `zone_name` | `kops` zone name |
103+
| `zone_id` | `kops` cluster zone ID |
104+
| `zone_name` | `kops` cluster zone name |
103105
| `bucket_name` | S3 bucket name |
104106
| `bucket_region` | S3 bucket region |
105107
| `bucket_domain_name` | S3 bucket domain name |

images/kops-state-backend.png

-75.8 KB
Loading

main.tf

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,13 @@ data "template_file" "zone_name" {
33

44
vars {
55
namespace = "${var.namespace}"
6-
name = "${var.name}"
6+
name = "${var.cluster_name}"
77
stage = "${var.stage}"
88
parent_zone_name = "${var.parent_zone_name}"
99
}
1010
}
1111

12-
# Label & Tags
13-
module "label" {
14-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
15-
namespace = "${var.namespace}"
16-
name = "${var.name}"
17-
stage = "${var.stage}"
18-
delimiter = "${var.delimiter}"
19-
attributes = "${var.attributes}"
20-
12+
locals {
2113
tags = "${
2214
merge(
2315
var.tags,
@@ -32,26 +24,29 @@ module "label" {
3224
module "domain" {
3325
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-zone.git?ref=tags/0.2.3"
3426
namespace = "${var.namespace}"
35-
name = "${var.name}"
27+
name = "${var.cluster_name}"
3628
stage = "${var.stage}"
3729
delimiter = "${var.delimiter}"
3830
attributes = "${var.attributes}"
3931
zone_name = "${var.zone_name}"
4032
parent_zone_id = "${var.parent_zone_id}"
4133
parent_zone_name = "${var.parent_zone_name}"
34+
tags = "${local.tags}"
35+
}
4236

43-
tags = "${
44-
merge(
45-
var.tags,
46-
map(
47-
"Cluster", "${data.template_file.zone_name.rendered}"
48-
)
49-
)
50-
}"
37+
# Label & Tags
38+
module "s3_label" {
39+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
40+
namespace = "${var.namespace}"
41+
name = "${var.bucket_name}"
42+
stage = "${var.stage}"
43+
delimiter = "${var.delimiter}"
44+
attributes = "${var.attributes}"
45+
tags = "${local.tags}"
5146
}
5247

5348
resource "aws_s3_bucket" "default" {
54-
bucket = "${module.label.id}"
49+
bucket = "${module.s3_label.id}"
5550
acl = "${var.acl}"
5651
region = "${var.region}"
5752
force_destroy = "${var.force_destroy}"
@@ -68,5 +63,5 @@ resource "aws_s3_bucket" "default" {
6863
}
6964
}
7065

71-
tags = "${module.label.tags}"
66+
tags = "${module.s3_label.tags}"
7267
}

variables.tf

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ variable "stage" {
88
description = "Stage (e.g. `prod`, `dev`, `staging`)"
99
}
1010

11-
variable "name" {
11+
variable "bucket_name" {
1212
type = "string"
13-
default = "kops"
14-
description = "Name (e.g. `kops`)"
13+
default = "kops-state"
14+
description = "S3 bucket name (e.g. `kops-state`)"
15+
}
16+
17+
variable "cluster_name" {
18+
type = "string"
19+
default = "us-east-1"
20+
description = "Kops cluster name (e.g. `us-east-1` or `cluster-1`)"
1521
}
1622

1723
variable "delimiter" {
@@ -22,8 +28,8 @@ variable "delimiter" {
2228

2329
variable "attributes" {
2430
type = "list"
25-
default = ["state"]
26-
description = "Additional attributes (e.g. `state`)"
31+
default = []
32+
description = "Additional attributes (e.g. `1`)"
2733
}
2834

2935
variable "tags" {
@@ -35,7 +41,7 @@ variable "tags" {
3541
variable "zone_name" {
3642
type = "string"
3743
default = "$${name}.$${parent_zone_name}"
38-
description = "Template for `kops` DNS zone name"
44+
description = "Template for the DNS zone name"
3945
}
4046

4147
variable "parent_zone_id" {
@@ -46,7 +52,7 @@ variable "parent_zone_id" {
4652

4753
variable "parent_zone_name" {
4854
type = "string"
49-
default = "cloudxl.net"
55+
default = ""
5056
description = "Parent DNS zone name (e.g. `domain.com`)"
5157
}
5258

0 commit comments

Comments
 (0)