Skip to content

Commit ffd1b78

Browse files
authored
feat: add code (#1)
1 parent fc8436c commit ffd1b78

File tree

9 files changed

+225
-2
lines changed

9 files changed

+225
-2
lines changed

.github/main.workflow

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
workflow "Terraform" {
2+
resolves = "terraform-validate"
3+
on = "pull_request"
4+
}
5+
6+
workflow "Release" {
7+
on = "push"
8+
resolves = ["goreleaser"]
9+
}
10+
11+
action "filter-to-pr-open-synced" {
12+
uses = "actions/bin/filter@master"
13+
args = "action 'opened|synchronize'"
14+
}
15+
16+
action "terraform-fmt" {
17+
uses = "hashicorp/terraform-github-actions/[email protected]"
18+
needs = "filter-to-pr-open-synced"
19+
secrets = ["GITHUB_TOKEN"]
20+
21+
env = {
22+
TF_ACTION_WORKING_DIR = "."
23+
}
24+
}
25+
26+
action "terraform-init" {
27+
uses = "hashicorp/terraform-github-actions/[email protected]"
28+
needs = "terraform-fmt"
29+
secrets = ["GITHUB_TOKEN"]
30+
31+
env = {
32+
TF_ACTION_WORKING_DIR = "./examples/basic"
33+
}
34+
}
35+
36+
action "terraform-validate" {
37+
uses = "hashicorp/terraform-github-actions/[email protected]"
38+
needs = "terraform-init"
39+
secrets = ["GITHUB_TOKEN"]
40+
41+
env = {
42+
TF_ACTION_WORKING_DIR = "./examples/basic"
43+
}
44+
}
45+
46+
action "is-tag" {
47+
uses = "actions/bin/filter@master"
48+
args = "tag"
49+
}
50+
51+
action "goreleaser" {
52+
uses = "docker://goreleaser/goreleaser"
53+
secrets = ["GITHUB_TOKEN"]
54+
args = "release"
55+
needs = ["is-tag"]
56+
}

.goreleaser.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
builds:
2+
-
3+
main: ./.goreleaser/main.go
4+
binary: dirty-hack
5+
ignore:
6+
- goos: darwin
7+
goarch: 386
8+
- goos: darwin
9+
goarch: amd64
10+
- goos: linux
11+
goarch: 386
12+
archive:
13+
name_template: "dirty-hack-for-goreleaser"
14+
files:
15+
- README.md
16+
release:
17+
name_template: "{{.Tag}}"

.goreleaser/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package main
2+
3+
func main() {
4+
}

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 2019 Vladimir Syromyatnikov
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.

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
11
# terraform-google-project
2-
terraform-google-project
2+
3+
The terraform module for creation and management of a GCP project with normalized name and labels.
4+
5+
## Usage
6+
7+
```hcl
8+
module "my_awesome_project" {
9+
source = "git::https://github.com/SweetOps/terraform-google-project.git?ref=master"
10+
name = "awesome"
11+
stage = "production"
12+
namespace = "sweetops"
13+
}
14+
```
15+
16+
## Inputs
17+
18+
19+
| Name | Description | Type | Default | Required |
20+
|:---------------------------|:------------------------------------------------------------------------------------------------|:------:|:---------:|:--------:|
21+
| name | Solution name, e.g. 'app' or 'jenkins' | string | n/a | yes |
22+
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | n/a | yes |
23+
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | n/a | yes |
24+
| attributes | Additional attributes (e.g. `1`) | list | `[]` | no |
25+
| auto_create_network | Create the 'default' network automatically | string | `"true"` | no |
26+
| context | Default context to use for passing state between label invocations | map | `{}` | no |
27+
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `"-"` | no |
28+
| enable_deletion_protection | If true, the Terraform resource can be deleted without deleting the Project via the Google API. | string | `"false"` | no |
29+
| enabled | Set to false to prevent the module from creating any resources | string | `"true"` | no |
30+
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `""` | no |
31+
| folder_id | The numeric ID of the folder this project should be created under | string | `""` | no |
32+
| org_id | The numeric ID of the organization this project belongs to | string | `""` | no |
33+
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `{}` | no |
34+
35+
## Outputs
36+
37+
| Name | Description |
38+
|:-------|:--------------------------------------|
39+
| name | The project ID |
40+
| number | The numeric identifier of the project |

examples/basic/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module "my_awesome_project" {
2+
source = "../../"
3+
name = "awesome"
4+
stage = "production"
5+
namespace = "sweetops"
6+
}

main.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module "label" {
2+
source = "git::https://github.com/SweetOps/terraform-null-label.git?ref=tags/0.6.0"
3+
enabled = "${var.enabled}"
4+
namespace = "${var.namespace}"
5+
name = "${var.name}"
6+
stage = "${var.stage}"
7+
environment = "${var.environment}"
8+
delimiter = "${var.delimiter}"
9+
attributes = "${var.attributes}"
10+
context = "${var.context}"
11+
tags = "${var.tags}"
12+
}
13+
14+
resource "google_project" "default" {
15+
count = "${var.enabled == "true" ? 1 : 0}"
16+
name = "${module.label.id}"
17+
project_id = "${module.label.id}"
18+
labels = "${module.label.gcp_list_of_maps}"
19+
org_id = "${var.org_id}"
20+
folder_id = "${var.folder_id}"
21+
skip_delete = "${var.enable_deletion_protection}"
22+
auto_create_network = "${var.auto_create_network}"
23+
}

outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "number" {
2+
value = "${join("", google_project.default.*.number)}"
3+
description = "The numeric identifier of the project"
4+
}
5+
6+
output "name" {
7+
value = "${join("", google_project.default.*.name)}"
8+
description = "The project ID"
9+
}

variables.tf

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
variable "namespace" {
2+
type = "string"
3+
description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'"
4+
}
5+
6+
variable "environment" {
7+
type = "string"
8+
default = ""
9+
description = "Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT'"
10+
}
11+
12+
variable "stage" {
13+
type = "string"
14+
description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'"
15+
}
16+
17+
variable "name" {
18+
type = "string"
19+
description = "Solution name, e.g. 'app' or 'jenkins'"
20+
}
21+
22+
variable "enabled" {
23+
type = "string"
24+
default = "true"
25+
description = "Set to false to prevent the module from creating any resources"
26+
}
27+
28+
variable "delimiter" {
29+
type = "string"
30+
default = "-"
31+
description = "Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`"
32+
}
33+
34+
variable "attributes" {
35+
type = "list"
36+
default = []
37+
description = "Additional attributes (e.g. `1`)"
38+
}
39+
40+
variable "tags" {
41+
type = "map"
42+
default = {}
43+
description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`"
44+
}
45+
46+
variable "context" {
47+
type = "map"
48+
default = {}
49+
description = "Default context to use for passing state between label invocations"
50+
}
51+
52+
variable "org_id" {
53+
default = ""
54+
description = "The numeric ID of the organization this project belongs to"
55+
}
56+
57+
variable "folder_id" {
58+
default = ""
59+
description = "The numeric ID of the folder this project should be created under"
60+
}
61+
62+
variable "enable_deletion_protection" {
63+
default = "false"
64+
description = "If true, the Terraform resource can be deleted without deleting the Project via the Google API."
65+
}
66+
67+
variable "auto_create_network" {
68+
default = "true"
69+
description = "Create the 'default' network automatically"
70+
}

0 commit comments

Comments
 (0)