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

Commit 78f97dc

Browse files
authored
Rename repo. Update module. Add TravisCI. Update README (#2)
* Update module * Update `README` * Update `README` * Add `force_destroy` variable * Add default tag * Add default tag * Update `README` * Update `README` * Update `README`
1 parent d3370d7 commit 78f97dc

File tree

9 files changed

+328
-57
lines changed

9 files changed

+328
-57
lines changed

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
.terraform
1+
# Compiled files
2+
*.tfstate
3+
*.tfstate.backup
4+
.terraform.tfstate.lock.info
5+
6+
# Module directory
7+
.terraform/
8+
.idea
9+
*.iml

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
addons:
2+
apt:
3+
packages:
4+
- git
5+
- make
6+
- curl
7+
8+
install:
9+
- make init
10+
11+
script:
12+
- make terraform/install
13+
- make terraform/get-plugins
14+
- make terraform/get-modules
15+
- make terraform/lint
16+
- make terraform/validate

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2017-2018 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SHELL := /bin/bash
2+
3+
-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness)
4+
5+
lint:
6+
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate

README.md

Lines changed: 180 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,189 @@
1-
# tf_kops_bootstrap
1+
# terraform-aws-kops-state-backend [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-kops-state-backend.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-kops-state-backend)
2+
3+
Terraform module to provision dependencies for `kops` (config S3 bucket & DNS zone).
4+
5+
The module supports the following:
6+
7+
1. Forced server-side encryption at rest for the S3 bucket
8+
2. S3 bucket versioning to allow for `kops` state recovery in the case of accidental deletions or human errors
29

3-
Easily bootstrap dependencies for `kops` (config bucket & DNS zone)
410

511
## Usage
612

7-
Provision environment for `foobar.example.com`.
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.
814

9-
```
15+
It will also create an S3 bucket with the name `cp-prod-kops-state` for storing `kops` manifests.
16+
17+
```hcl
1018
module "kops" {
11-
source = "git::https://github.com/cloudposse/tf_kops_bootstrap.git?ref=master"
12-
namespace = "example"
13-
stage = "dev"
14-
name = "foobar"
15-
parent_dns_zone = "example.com"
19+
source = "git::https://github.com/cloudposse/terraform-aws-kops-state-backend.git?ref=master"
20+
namespace = "cp"
21+
stage = "prod"
22+
name = "kops"
23+
attributes = ["state"]
24+
parent_zone_name = "cloudxl.net"
25+
zone_name = "$${name}.$${parent_zone_name}"
26+
region = "us-east-1"
27+
}
28+
```
29+
30+
<br/>
31+
32+
![kops-state-backend](images/kops-state-backend.png)
33+
34+
<br/>
35+
36+
To check that the created `kops` DNS zone has been tagged correctly, run
37+
38+
```sh
39+
aws route53 list-tags-for-resources --resource-type hostedzone --resource-ids Z58RWQWFVU4HT
40+
```
41+
42+
43+
```js
44+
{
45+
"ResourceTagSets": [
46+
{
47+
"ResourceType": "hostedzone",
48+
"ResourceId": "Z58RWQWFVU4HT",
49+
"Tags": [
50+
{
51+
"Key": "Cluster",
52+
"Value": "kops.cloudxl.net"
53+
},
54+
{
55+
"Key": "Stage",
56+
"Value": "prod"
57+
},
58+
{
59+
"Key": "Namespace",
60+
"Value": "cp"
61+
},
62+
{
63+
"Key": "Name",
64+
"Value": "cp-prod-kops-state"
65+
}
66+
]
67+
}
68+
]
1669
}
1770
```
1871

19-
This example will create a DNS zone called `foobar.example.com` and delegate it from `example.com` by setting `NS` and `SOA` records. It will also provision a bucket called `config.foobar.example.com` for storing kops manifests.
72+
73+
## Variables
74+
75+
__NOTE:__ One of `parent_zone_name` or `parent_zone_id` is required, but not both.
76+
The module will lookup the parent zone by either name or ID.
77+
78+
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 |
93+
94+
95+
## Outputs
96+
97+
| Name | Description |
98+
|:-----------------------|:--------------------------|
99+
| `parent_zone_id` | Parent zone ID |
100+
| `parent_zone_name` | Parent zone name |
101+
| `zone_id` | `kops` zone ID |
102+
| `zone_name` | `kops` zone name |
103+
| `bucket_name` | S3 bucket name |
104+
| `bucket_region` | S3 bucket region |
105+
| `bucket_domain_name` | S3 bucket domain name |
106+
| `bucket_id` | S3 bucket ID |
107+
| `bucket_arn` | S3 bucket ARN |
108+
109+
110+
## Help
111+
112+
**Got a question?**
113+
114+
File a GitHub [issue](https://github.com/cloudposse/terraform-aws-kops-state-backend/issues), send us an [email](mailto:[email protected]) or reach out to us on [Gitter](https://gitter.im/cloudposse/).
115+
116+
117+
## Contributing
118+
119+
### Bug Reports & Feature Requests
120+
121+
Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-kops-state-backend/issues) to report any bugs or file feature requests.
122+
123+
### Developing
124+
125+
If you are interested in being a contributor and want to get involved in developing `terraform-aws-kops-state-backend`, we would love to hear from you! Shoot us an [email](mailto:[email protected]).
126+
127+
In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
128+
129+
1. **Fork** the repo on GitHub
130+
2. **Clone** the project to your own machine
131+
3. **Commit** changes to your own branch
132+
4. **Push** your work back up to your fork
133+
5. Submit a **Pull request** so that we can review your changes
134+
135+
**NOTE:** Be sure to merge the latest from "upstream" before making a pull request!
136+
137+
138+
## License
139+
140+
[APACHE 2.0](LICENSE) © 2017-2018 [Cloud Posse, LLC](https://cloudposse.com)
141+
142+
See [LICENSE](LICENSE) for full details.
143+
144+
Licensed to the Apache Software Foundation (ASF) under one
145+
or more contributor license agreements. See the NOTICE file
146+
distributed with this work for additional information
147+
regarding copyright ownership. The ASF licenses this file
148+
to you under the Apache License, Version 2.0 (the
149+
"License"); you may not use this file except in compliance
150+
with the License. You may obtain a copy of the License at
151+
152+
http://www.apache.org/licenses/LICENSE-2.0
153+
154+
Unless required by applicable law or agreed to in writing,
155+
software distributed under the License is distributed on an
156+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
157+
KIND, either express or implied. See the License for the
158+
specific language governing permissions and limitations
159+
under the License.
160+
161+
162+
## About
163+
164+
`terraform-aws-kops-state-backend` is maintained and funded by [Cloud Posse, LLC][website].
165+
166+
![Cloud Posse](https://cloudposse.com/logo-300x69.png)
167+
168+
169+
Like it? Please let us know at <[email protected]>
170+
171+
We love [Open Source Software](https://github.com/cloudposse/)!
172+
173+
See [our other projects][community]
174+
or [hire us][hire] to help build your next cloud platform.
175+
176+
[website]: https://cloudposse.com/
177+
[community]: https://github.com/cloudposse/
178+
[hire]: https://cloudposse.com/contact/
179+
180+
181+
### Contributors
182+
183+
| [![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web] | [![Andriy Knysh][andriy_img]][andriy_web]<br/>[Andriy Knysh][andriy_web] |
184+
|-------------------------------------------------------|------------------------------------------------------------------|
185+
186+
[erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144
187+
[erik_web]: https://github.com/osterman/
188+
[andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
189+
[andriy_web]: https://github.com/aknysh/

images/kops-state-backend.png

141 KB
Loading

main.tf

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,72 @@
1-
# Label & Tags (e.g. `example-dev-foobar`)
1+
data "template_file" "zone_name" {
2+
template = "${replace(var.zone_name, "$$$$", "$")}"
3+
4+
vars {
5+
namespace = "${var.namespace}"
6+
name = "${var.name}"
7+
stage = "${var.stage}"
8+
parent_zone_name = "${var.parent_zone_name}"
9+
}
10+
}
11+
12+
# Label & Tags
213
module "label" {
3-
source = "git::https://github.com/cloudposse/tf_label.git?ref=tags/0.1.0"
4-
namespace = "${var.namespace}"
5-
stage = "${var.stage}"
6-
name = "${var.name}"
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+
21+
tags = "${
22+
merge(
23+
var.tags,
24+
map(
25+
"Cluster", "${data.template_file.zone_name.rendered}"
26+
)
27+
)
28+
}"
729
}
830

9-
# Kops domain (e.g. `foobar.example.com`)
31+
# Kops domain (e.g. `kops.domain.com`)
1032
module "domain" {
11-
source = "git::https://github.com/cloudposse/tf_domain.git?ref=tags/0.2.0"
12-
namespace = "${var.namespace}"
13-
name = "${var.name}"
14-
stage = "${var.stage}"
15-
16-
zone_name = "$${namespace}.$${parent_zone_name}"
33+
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-zone.git?ref=tags/0.2.3"
34+
namespace = "${var.namespace}"
35+
name = "${var.name}"
36+
stage = "${var.stage}"
37+
delimiter = "${var.delimiter}"
38+
attributes = "${var.attributes}"
39+
zone_name = "${var.zone_name}"
1740
parent_zone_id = "${var.parent_zone_id}"
1841
parent_zone_name = "${var.parent_zone_name}"
19-
ttl = 60
20-
}
2142

22-
data "template_file" "bucket_name" {
23-
template = "${replace(var.bucket_name, "$$$$", "$")}"
24-
25-
vars {
26-
namespace = "${var.namespace}"
27-
name = "${var.name}"
28-
stage = "${var.stage}"
29-
id = "${module.label.id}"
30-
zone_name = "${module.domain.zone_name}"
31-
parent_zone_name = "${module.domain.parent_zone_name}"
32-
}
43+
tags = "${
44+
merge(
45+
var.tags,
46+
map(
47+
"Cluster", "${data.template_file.zone_name.rendered}"
48+
)
49+
)
50+
}"
3351
}
3452

35-
# Kops bucket for manifests (e.g. `config.foobar.example.com`)
3653
resource "aws_s3_bucket" "default" {
37-
bucket = "${data.template_file.bucket_name.rendered}"
38-
acl = "private"
39-
tags = "${module.label.tags}"
40-
force_destroy = true
54+
bucket = "${module.label.id}"
55+
acl = "${var.acl}"
56+
region = "${var.region}"
57+
force_destroy = "${var.force_destroy}"
4158

4259
versioning {
4360
enabled = true
4461
}
4562

46-
tags = "${module.label.tags}"
47-
48-
lifecycle {
49-
create_before_destroy = true
63+
server_side_encryption_configuration {
64+
rule {
65+
apply_server_side_encryption_by_default {
66+
sse_algorithm = "AES256"
67+
}
68+
}
5069
}
70+
71+
tags = "${module.label.tags}"
5172
}

outputs.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ output "bucket_region" {
2222
value = "${aws_s3_bucket.default.region}"
2323
}
2424

25-
output "id" {
26-
value = "${module.label.id}"
25+
output "bucket_domain_name" {
26+
value = "${aws_s3_bucket.default.bucket_domain_name}"
27+
}
28+
29+
output "bucket_id" {
30+
value = "${aws_s3_bucket.default.id}"
31+
}
32+
33+
output "bucket_arn" {
34+
value = "${aws_s3_bucket.default.arn}"
2735
}

0 commit comments

Comments
 (0)