Skip to content

Commit

Permalink
Fix README.md and LICENSE, add examples (#8)
Browse files Browse the repository at this point in the history
* Fix `README.md`, fix `LICENSE`

* Fix `README.md`

* Fix `README.md`

* Add `examples` to conform to community standard https://www.terraform.io/docs/registry/modules/publish.html
  • Loading branch information
aknysh authored Sep 29, 2017
1 parent b885186 commit 941f2ac
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 48 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
*.tfstate.backup

# Module directory
.terraform/
.terraform
.idea
*.iml

.gitignore
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 2017 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
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

Terraform module designed to generate consistent label names and tags for resources. Use `terraform-null-label` to implement a strict naming convention.

A label follows the following convention: `{namespace}-{stage}-{name}-{attributes}`. The delimiter (e.g. `-`) is interchangeable.

A label follows the following convention: `{namespace}-{stage}-{name}-{attributes}`. The delimiter (e.g. `-`) is interchangable.

It's recommended to use one `terraform-null-label` module for every unique resource of a given resource type. For example, if you have 10 instances, there should be 10 different labels. However, if you have multiple different kinds of resources (e.g. instances, security groups, file systems, and elastic ips), then they can all share the same label assuming they are logically related.
It's recommended to use one `terraform-null-label` module for every unique resource of a given resource type.
For example, if you have 10 instances, there should be 10 different labels.
However, if you have multiple different kinds of resources (e.g. instances, security groups, file systems, and elastic ips), then they can all share the same label assuming they are logically related.

All [Cloud Posse modules](https://github.com/cloudposse?utf8=%E2%9C%93&q=tf_&type=&language=) use this module to ensure resources can be instantiated multiple times within an account and without conflict.

**NOTE:** The `null` refers to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.
-**NOTE:** The `null` refers to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.


## Usage

### Simple Example

Include this repository as a module in your existing terraform code:

```
```hcl
module "eg_prod_bastion_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
namespace = "eg"
Expand All @@ -32,15 +34,17 @@ module "eg_prod_bastion_label" {
This will create an `id` with the value of `eg-prod-bastion-public`.

Now reference the label when creating an instance (for example):
```

```hcl
resource "aws_instance" "eg_prod_bastion_public" {
instance_type = "t1.micro"
tags = "${module.eg_prod_bastion_label.tags}"
}
```

Or define a security group:
```

```hcl
resource "aws_security_group" "eg_prod_bastion_public" {
vpc_id = "${var.vpc_id}"
name = "${module.eg_prod_bastion_label.id}"
Expand All @@ -59,7 +63,7 @@ resource "aws_security_group" "eg_prod_bastion_public" {

Here is a more complex example with two instances using two different labels. Note how efficiently the tags are defined for both the instance and the security group.

```
```hcl
module "eg_prod_bastion_abc_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
namespace = "eg"
Expand Down Expand Up @@ -130,7 +134,7 @@ resource "aws_instance" "eg_prod_bastion_xyz" {

## Outputs

| Name | Decription |
| Name | Description |
|:------------------|:----------------------|
| id | Disambiguated ID |
| name | Normalized name |
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "label" {
source = "../../"
namespace = "Namespace"
stage = "Stage"
name = "Name"
attributes = ["1", "2", "3", ""]
tags = "${map("Key", "Value")}"
}
23 changes: 23 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
output "id" {
value = "${module.label.id}"
}

output "name" {
value = "${module.label.name}"
}

output "namespace" {
value = "${module.label.namespace}"
}

output "stage" {
value = "${module.label.stage}"
}

output "attributes" {
value = "${module.label.attributes}"
}

output "tags" {
value = "${module.label.tags}"
}
32 changes: 0 additions & 32 deletions tests/test.tf

This file was deleted.

14 changes: 9 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ variable "stage" {}
variable "name" {}

variable "delimiter" {
default = "-"
type = "string"
default = "-"
description = "Delimiter to be used between `name`, `namespace`, `stage`, etc."
}

variable "attributes" {
type = "list"
default = []
type = "list"
default = []
description = "Additional attributes (e.g. `policy` or `role`)"
}

variable "tags" {
type = "map"
default = {}
type = "map"
default = {}
description = "Additional tags (e.g. `map('BusinessUnit`,`XYZ`)"
}

0 comments on commit 941f2ac

Please sign in to comment.