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

Commit

Permalink
Initial Implementation (#1)
Browse files Browse the repository at this point in the history
* Init

* Add Terraform config

* Update `README`

* Parameterize bastion server, K8s master and nodes DNS subdomain names

* Update `README`
  • Loading branch information
aknysh authored Mar 21, 2018
1 parent e39e85a commit a92eb16
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

# Module directory
.terraform/
.idea
terraform-aws-kops-metadata.iml
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
addons:
apt:
packages:
- git
- make
- curl

install:
- make init

script:
- make terraform/install
- make terraform/get-plugins
- make terraform/get-modules
- make terraform/lint
- make terraform/validate
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2018 Cloud Posse, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SHELL := /bin/bash

-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness)

lint:
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate
132 changes: 131 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,131 @@
# terraform-aws-vpc-kops
# terraform-aws-kops-metadata [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-kops-metadata.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-kops-metadata)

Terraform module to lookup resources within a [Kops](https://github.com/kubernetes/kops) cluster


## Usage

```hcl
module "kops_metadata" {
source = "git::https://github.com/cloudposse/terraform-aws-kops-metadata.git?ref=master"
dns_zone = "cluster.domain.com"
bastion_name = "bastion"
masters_name = "masters"
nodes_name = "nodes"
}
```


## Variables

| Name | Default | Description | Required |
|:-----------------|:---------------------|:---------------------------------------------------------------------------------|:--------:|
| `dns_zone` | `` | Name of the Kops DNS zone | Yes |
| `enabled` | `true` | Set to `false` to prevent the module from creating or accessing any resources | No |
| `bastion_name` | `bastion` | Bastion server subdomain name in the Kops DNS zone | No |
| `masters_name` | `masters` | K8s masters subdomain name in the Kops DNS zone | No |
| `nodes_name` | `nodes` | K8s nodes subdomain name in the Kops DNS zone | No |


## Outputs

| Name | Description |
|:--------------------------------|:---------------------------------------|
| `vpc_id` | Kops VPC ID |
| `private_subnet_ids` | Private subnets IDs in the VPC |
| `utility_subnet_ids` | Utility submets IDs in the VPC |
| `bastion_security_group_arn` | Bastion server Security Group ARN |
| `bastion_security_group_id` | Bastion server Security Group ID |
| `masters_security_group_arn` | K8s masters Security Group ARN |
| `masters_security_group_id` | K8s masters Security Group ID |
| `nodes_security_group_arn` | K8s nodes Security Group ARN |
| `nodes_security_group_id` | K8s nodes Security Group ID |


## Credits

Thanks to [Gladly.com](https://www.gladly.com/) for the inspiration with this wonderful module:

https://github.com/sagansystems/terraform-aws-vpc-kops


## Help

**Got a question?**

File a GitHub [issue](https://github.com/cloudposse/terraform-aws-kops-metadata/issues), send us an [email](mailto:hello@cloudposse.com) or reach out to us on [Gitter](https://gitter.im/cloudposse/).


## Contributing

### Bug Reports & Feature Requests

Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-kops-metadata/issues) to report any bugs or file feature requests.

### Developing

If you are interested in being a contributor and want to get involved in developing `terraform-aws-kops-metadata`, we would love to hear from you! Shoot us an [email](mailto:hello@cloudposse.com).

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

1. **Fork** the repo on GitHub
2. **Clone** the project to your own machine
3. **Commit** changes to your own branch
4. **Push** your work back up to your fork
5. Submit a **Pull request** so that we can review your changes

**NOTE:** Be sure to merge the latest from "upstream" before making a pull request!


## License

[APACHE 2.0](LICENSE) © 2018 [Cloud Posse, LLC](https://cloudposse.com)

See [LICENSE](LICENSE) for full details.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.


## About

`terraform-aws-kops-metadata` is maintained and funded by [Cloud Posse, LLC][website].

![Cloud Posse](https://cloudposse.com/logo-300x69.png)


Like it? Please let us know at <hello@cloudposse.com>

We love [Open Source Software](https://github.com/cloudposse/)!

See [our other projects][community]
or [hire us][hire] to help build your next cloud platform.

[website]: https://cloudposse.com/
[community]: https://github.com/cloudposse/
[hire]: https://cloudposse.com/contact/


## Contributors

| [![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web] | [![Andriy Knysh][andriy_img]][andriy_web]<br/>[Andriy Knysh][andriy_web] |
|-------------------------------------------------------|------------------------------------------------------------------|

[erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144
[erik_web]: https://github.com/osterman/
[andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[andriy_web]: https://github.com/aknysh/
59 changes: 59 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
data "aws_vpc" "kops" {
count = "${var.enabled == "true" ? 1 : 0}"

filter {
name = "tag:Name"
values = ["${var.dns_zone}"]
}
}

data "aws_subnet_ids" "private" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${data.aws_vpc.kops.id}"

tags {
"kubernetes.io/role/internal-elb" = "1"
}
}

data "aws_subnet_ids" "utility" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${data.aws_vpc.kops.id}"

tags {
"kubernetes.io/role/elb" = "1"
}
}

data "aws_security_group" "bastion" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${data.aws_vpc.kops.id}"
name = "${var.bastion_name}.${var.dns_zone}"

tags {
Name = "${var.bastion_name}.${var.dns_zone}"
KubernetesCluster = "${var.dns_zone}"
}
}

data "aws_security_group" "masters" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${data.aws_vpc.kops.id}"
name = "${var.masters_name}.${var.dns_zone}"

tags {
Name = "${var.masters_name}.${var.dns_zone}"
KubernetesCluster = "${var.dns_zone}"
}
}

data "aws_security_group" "nodes" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${data.aws_vpc.kops.id}"
name = "${var.nodes_name}.${var.dns_zone}"

tags {
Name = "${var.nodes_name}.${var.dns_zone}"
KubernetesCluster = "${var.dns_zone}"
}
}
35 changes: 35 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
output "vpc_id" {
value = "${join("", data.aws_vpc.kops.*.id)}"
}

output "private_subnet_ids" {
value = "${flatten(data.aws_subnet_ids.private.*.ids)}"
}

output "utility_subnet_ids" {
value = "${flatten(data.aws_subnet_ids.utility.*.ids)}"
}

output "bastion_security_group_arn" {
value = "${join("", data.aws_security_group.bastion.*.arn)}"
}

output "bastion_security_group_id" {
value = "${join("", data.aws_security_group.bastion.*.id)}"
}

output "masters_security_group_arn" {
value = "${join("", data.aws_security_group.masters.*.arn)}"
}

output "masters_security_group_id" {
value = "${join("", data.aws_security_group.masters.*.id)}"
}

output "nodes_security_group_arn" {
value = "${join("", data.aws_security_group.nodes.*.arn)}"
}

output "nodes_security_group_id" {
value = "${join("", data.aws_security_group.nodes.*.id)}"
}
27 changes: 27 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variable "enabled" {
default = "true"
description = "Set to false to prevent the module from creating or accessing any resources"
}

variable "dns_zone" {
type = "string"
description = "Name of the Kops DNS zone"
}

variable "bastion_name" {
type = "string"
default = "bastion"
description = "Bastion server subdomain name in the Kops DNS zone"
}

variable "masters_name" {
type = "string"
default = "masters"
description = "K8s masters subdomain name in the Kops DNS zone"
}

variable "nodes_name" {
type = "string"
default = "nodes"
description = "K8s nodes subdomain name in the Kops DNS zone"
}

0 comments on commit a92eb16

Please sign in to comment.