Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KM-19: Add module code #2

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4f957cb
chore: added github actions
warrenbrown Jul 8, 2020
2120951
chore: updated terraform.yaml
warrenbrown Jul 8, 2020
2e19393
chore: updated path for worklfow
warrenbrown Jul 8, 2020
c7da091
Apply suggestions from code review
warrenbrown Jul 12, 2020
4c4875f
chore: added pr-labeler to workflows
warrenbrown Jul 12, 2020
2ab620f
chore: added config file for pr labeler
warrenbrown Jul 12, 2020
4268981
udated terrafrom.yaml workflow
warrenbrown Jul 12, 2020
5d56272
updated terrafrom.yaml workflow
warrenbrown Jul 12, 2020
4f0845a
chore: removed main.tf it was not needed
warrenbrown Jul 12, 2020
9325d4b
chore: made updated changes to workflows
warrenbrown Jul 17, 2020
177253d
chore: added workspace module
warrenbrown Jul 8, 2020
eb45e06
chore: adderd pertaining terraform files to repo
warrenbrown Jul 8, 2020
f4d8361
chore: updated terraform files for module
warrenbrown Jul 10, 2020
717d923
pre-commit fixes
Jul 12, 2020
cb7440a
chore: added correct terraform version to terraform workflow
warrenbrown Jul 12, 2020
d2689ee
chore: removed validate step in terraform workflow
warrenbrown Jul 13, 2020
42ac6f7
chore: updated Readme
warrenbrown Jul 17, 2020
b75fd9e
chore: updated readme and added required providers to module
warrenbrown Jul 19, 2020
e0c12bc
chore: updated ssh_key_id value
warrenbrown Jul 19, 2020
9ec1365
pre-commit fixes
Jul 19, 2020
256c1d5
chore: added testing module to test folder and updated terraform.yaml
warrenbrown Jul 19, 2020
cded153
chore: updated test/main.tf
warrenbrown Jul 19, 2020
04d1e9f
pre-commit fixes
Jul 19, 2020
4f959fa
chore: removed tf.vars file
warrenbrown Jul 20, 2020
2ada61b
chore: added tfe to required providers
warrenbrown Jul 20, 2020
a151188
pre-commit fixes
Jul 20, 2020
1ac6927
chore: added tfe provider to test/main.tf
warrenbrown Jul 20, 2020
ccb95b0
chore: changed varibles
warrenbrown Jul 21, 2020
cf01281
Merge ccb95b00068236b66c29846d0aeb92de8bbbb4b6 into 0bc5dff8f541a2c4b…
warrenbrown Jul 21, 2020
ae3f970
pre-commit fixes
Jul 21, 2020
3a026cb
chore: removed provider from config file
warrenbrown Aug 10, 2020
0e4241b
chore: added TFE token to terraform workflow
warrenbrown Aug 10, 2020
ef984e1
chore: updated TFE token
warrenbrown Aug 10, 2020
5de0b99
Merge ef984e19d6591855d5ea1280a758c09e0a84c3a3 into 0bc5dff8f541a2c4b…
warrenbrown Aug 10, 2020
1489dbf
pre-commit fixes
Aug 10, 2020
c293914
chore: Added outputs for workspace resource
warrenbrown Sep 8, 2020
69ee484
Merge c293914622648aca0d15c29058a3cde41923d99f into 0bc5dff8f541a2c4b…
warrenbrown Sep 8, 2020
bff439e
pre-commit fixes
Sep 8, 2020
96b49a1
chore: fixed new variables
warrenbrown Sep 8, 2020
bce44a4
chore: added provider to test/main.tf
warrenbrown Sep 8, 2020
40dcbe4
Merge bce44a4a0f4ddabba346d299696e736cf4ae5d61 into 0bc5dff8f541a2c4b…
warrenbrown Sep 8, 2020
1f188b7
pre-commit fixes
Sep 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

- name: Install terraform
uses: hashicorp/setup-terraform@v1
with:
cli_config_credentials_token: ${{ secrets.TFE_TOKEN }}

- name: Terraform Init
id: init
Expand Down
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
# terraform-tfc-workspace

A Terraform module to easily create workspaces in Terraform Cloud.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| terraform | >= 0.12.0 |
| tfe | ~> 0.15.0 |

## Providers

| Name | Version |
|------|---------|
| tfe | ~> 0.15.0 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. | `bool` | `false` | no |
| branch | The repository branch that Terraform will execute from. Default to master. | `any` | n/a | yes |
| file\_triggers\_enabled | n/a | `bool` | `true` | no |
| hcl\_vars | n/a | `map` | `{}` | no |
| ingress\_submodules | n/a | `bool` | `false` | no |
| name | Name of the workspace. | `any` | n/a | yes |
| oauth\_token\_id | The OAuth token id for the VCS provider. | `any` | n/a | yes |
| organization | The name of the organization the workspace is under. | `any` | n/a | yes |
| queue\_all\_runs | n/a | `bool` | `true` | no |
| repo | A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. | `any` | n/a | yes |
| secrets | A map of custom secrets. | `map` | `{}` | no |
| ssh\_key | The github ssh key for tfe | `any` | n/a | yes |
| terraform\_version | The version of Terraform to use for this workspace. Defaults to the latest available version. | `string` | `"latest"` | no |
| variables | A map of custom variables. | `map` | `{}` | no |
| working\_directory | A relative path that Terraform will execute within. Defaults to the root of your repository. | `any` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| auto\_apply | Whether to automatically apply changes when a Terraform plan is successful. Defaults to false. |
| branch | The repository branch that Terraform will execute from. Default to master. |
| identifier | A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider. |
| name | The name of the workspace. |
| organization | The name of the organization the workspace is under. |
| terraform\_version | The version of Terraform to use for this workspace. Defaults to the latest available version. |
| working\_directory | A relative path that Terraform will execute within. Defaults to the root of your repository. |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
19 changes: 19 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "tfe_workspace" "workspace" {
name = var.name
organization = var.organization

auto_apply = var.auto_apply
file_triggers_enabled = var.file_triggers_enabled
queue_all_runs = var.queue_all_runs
ssh_key_id = var.ssh_key
terraform_version = var.terraform_version
working_directory = var.working_directory

vcs_repo {
identifier = var.repo
branch = var.branch
ingress_submodules = var.ingress_submodules
oauth_token_id = var.oauth_token_id
}
}

34 changes: 34 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
output "name" {
warrenbrown marked this conversation as resolved.
Show resolved Hide resolved
description = "The name of the workspace."
value = var.name
}

output "organization" {
description = "The name of the organization the workspace is under."
value = var.organization
}

output "auto_apply" {
description = "Whether to automatically apply changes when a Terraform plan is successful. Defaults to false."
value = var.auto_apply
}

output "terraform_version" {
description = "The version of Terraform to use for this workspace. Defaults to the latest available version."
value = var.terraform_version
}

output "working_directory" {
description = "A relative path that Terraform will execute within. Defaults to the root of your repository."
value = var.working_directory
}

output "identifier" {
description = "A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider."
value = var.repo
}

output "branch" {
description = "The repository branch that Terraform will execute from. Default to master."
value = var.branch
}
14 changes: 14 additions & 0 deletions test/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
backend "remote" {
hostname = "app.terraform.io"
organization = "km-sandbox"

workspaces {
name = "terraform-tfc-workspace"
}
}
}

provider "tfe" {
token = var.tfe_token
}
19 changes: 17 additions & 2 deletions test/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
provider "aws" {
region = "us-west-2"
region = "us-west-1"
}

resource "null_resource" "test1" {
variable "tfe_token" {
default = ""
}
variable "ssh_key" {
default = ""
}

module "core" {
source = "../"

organization = "organization-test"
branch = "master"
ssh_key = var.ssh_key
working_directory = "/test"
name = "terraform-tfc-workspace"
oauth_token_id = "alkasiopejk"
repo = "katapultmedia/terraform-tfc-workspace"
}
72 changes: 72 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// TFC Config

variable "auto_apply" {
default = false
description = "Whether to automatically apply changes when a Terraform plan is successful. Defaults to false."
}

variable "name" {
description = "Name of the workspace."
}

variable "organization" {
description = "The name of the organization the workspace is under."
}

variable "oauth_token_id" {
description = "The OAuth token id for the VCS provider."
}

variable "terraform_version" {
default = "latest"
description = "The version of Terraform to use for this workspace. Defaults to the latest available version."
}

// VCS

variable "repo" {
description = "A reference to your VCS repository in the format :org/:repo where :org and :repo refer to the organization and repository in your VCS provider."
}

variable "branch" {
description = "The repository branch that Terraform will execute from. Default to master."
}

variable "ingress_submodules" {
default = false
}

variable "working_directory" {
description = "A relative path that Terraform will execute within. Defaults to the root of your repository."
}

variable "ssh_key" {
description = "The github ssh key for tfe"
}

// App Vars

variable "secrets" {
default = {}
description = "A map of custom secrets."
type = map
}

variable "variables" {
default = {}
description = "A map of custom variables."
type = map
}

variable "hcl_vars" {
type = map
default = {}
}

variable "file_triggers_enabled" {
default = true
}

variable "queue_all_runs" {
default = true
}
6 changes: 6 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
terraform {
required_version = ">= 0.12.0"
required_providers {
tfe = "~> 0.15.0"
}
}