diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index c1eec8b..de295fe 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -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 diff --git a/README.md b/README.md index 05f1951..3952646 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,49 @@ # terraform-tfc-workspace -A Terraform module to easily create workspaces in Terraform Cloud. - +## 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. | + diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..a1d02e8 --- /dev/null +++ b/main.tf @@ -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 + } +} + diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..ed7050a --- /dev/null +++ b/outputs.tf @@ -0,0 +1,34 @@ +output "name" { + 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 +} \ No newline at end of file diff --git a/test/config.tf b/test/config.tf new file mode 100644 index 0000000..07df49f --- /dev/null +++ b/test/config.tf @@ -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 +} \ No newline at end of file diff --git a/test/main.tf b/test/main.tf index a4149de..b25b35a 100644 --- a/test/main.tf +++ b/test/main.tf @@ -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" } diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..fd9988e --- /dev/null +++ b/variables.tf @@ -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 +} \ No newline at end of file diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..12babb1 --- /dev/null +++ b/versions.tf @@ -0,0 +1,6 @@ +terraform { + required_version = ">= 0.12.0" + required_providers { + tfe = "~> 0.15.0" + } +} \ No newline at end of file