Skip to content

Commit

Permalink
feat: add TF docs build workflow + initial docs
Browse files Browse the repository at this point in the history
  • Loading branch information
parkedwards committed Oct 31, 2023
1 parent f92f5e8 commit e986173
Show file tree
Hide file tree
Showing 35 changed files with 218 additions and 81 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build-terraform-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build Terraform Docs

on:
pull_request:
branches:
- main
paths:
- 'docs/**'
- 'examples/**'

permissions: {}

jobs:
build_tf_docs:
name: Build Terraform Docs
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Install tfplugindocs
run: go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
- name: Build Terraform Docs
run: make docs
- name: Commit changes
run: |
git add .
if [[ $(git diff --staged) != '' ]]; then
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Generate Terraform Docs"
git push --set-upstream origin ${{ github.event.pull_request.head.ref }}
else
echo "No changes to commit"
fi
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ test:
testacc:
TF_ACC=1 make test
.PHONY: testacc

docs:
mkdir -p docs
go generate ./...
.PHONY: docs
15 changes: 0 additions & 15 deletions examples/account_members.tf

This file was deleted.

7 changes: 0 additions & 7 deletions examples/account_roles.tf

This file was deleted.

3 changes: 3 additions & 0 deletions examples/data-sources/prefect_account/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "prefect_account" "my_organization" {
id = "account-UUID"
}
4 changes: 4 additions & 0 deletions examples/data-sources/prefect_account_member/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Read down an existing Account Member by email
data "prefect_account_member" "marvin" {
email = "[email protected]"
}
9 changes: 9 additions & 0 deletions examples/data-sources/prefect_account_role/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read down the default Owner Account Role
data "prefect_account_role" "owner" {
name = "Admin"
}

# Read down the default Member Account Role
data "prefect_account_role" "member" {
name = "Member"
}
3 changes: 3 additions & 0 deletions examples/data-sources/prefect_service_account/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "prefect_service_account" "my_existing_bot" {
id = "service-acount-UUID"
}
7 changes: 7 additions & 0 deletions examples/data-sources/prefect_variable/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "prefect_variable" "existing_by_id" {
id = "variable-UUID"
}

data "prefect_variable" "existing_by_name" {
name = "my-variable-name"
}
3 changes: 3 additions & 0 deletions examples/data-sources/prefect_work_pool/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "prefect_work_pool" "my_pool" {
name = "my-work-pool"
}
2 changes: 2 additions & 0 deletions examples/data-sources/prefect_work_pools/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Query all Work Pools in Account/Workspace
data "prefect_work_pools" "all_pools" {}
3 changes: 3 additions & 0 deletions examples/data-sources/prefect_workspace/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "prefect_workspace" "production_environment" {
id = "workspace-UUID"
}
24 changes: 24 additions & 0 deletions examples/data-sources/prefect_workspace_role/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Read down the default Owner Workspace Role
data "prefect_workspace_role" "owner" {
name = "Owner"
}

# Read down the default Worker Workspace Role
data "prefect_workspace_role" "worker" {
name = "Worker"
}

# Read down the default Developer Workspace Role
data "prefect_workspace_role" "developer" {
name = "Developer"
}

# Read down the default Viewer Workspace Role
data "prefect_workspace_role" "viewer" {
name = "Viewer"
}

# Read down the default Runner Workspace Role
data "prefect_workspace_role" "runner" {
name = "Runner"
}
5 changes: 0 additions & 5 deletions examples/data_sources.tf

This file was deleted.

3 changes: 0 additions & 3 deletions examples/local.tfvars

This file was deleted.

13 changes: 0 additions & 13 deletions examples/main.tf

This file was deleted.

13 changes: 13 additions & 0 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
prefect = {
source = "hashicorp.com/prefecthq/prefect"
}
}
}

provider "prefect" {
endpoint = "https://api.prefect.cloud"
api_key = var.prefect_api_key
account_id = var.prefect_account_id
}
2 changes: 2 additions & 0 deletions examples/resources/prefect_account/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prefect Accounts can be imported using the account's UUID
terraform import prefect_account.example account-uuid
6 changes: 6 additions & 0 deletions examples/resources/prefect_account/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "prefect_account" "example" {
name = "My Imported Account"
description = "A cool account"
billing_email = "[email protected]"
allow_public_workspaces = true
}
2 changes: 2 additions & 0 deletions examples/resources/prefect_service_account/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prefect Service Accounts can be imported using the service account's name
terraform import prefect_service_account.example name-of-service-account
17 changes: 17 additions & 0 deletions examples/resources/prefect_service_account/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# NON-EXPIRING API KEY
resource "prefect_service_account" "example" {
name = "my-service-account"
}

# ROTATING API KEY
# Use the hashicorp/time provider to generate a time_rotating resource
provider "time" {}
resource "time_rotating" "ninety_days" {
rotation_days = 90
}
# Pass the time_rotating resource to the `api_key_expiration` attribute
# in order to automate the rotation of the Service Account key
resource "prefect_service_account" "example" {
name = "my-service-account"
api_key_expiration = time_rotating.ninety_days.rotation_rfc3339
}
5 changes: 5 additions & 0 deletions examples/resources/prefect_variable/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Prefect Variables can be imported via name in the form `name/name-of-variable`
terraform import prefect_variable.example name/name-of-variable

# Prefect Variables can also be imported via UUID
terraform import prefect_variable.example variable-uuid
4 changes: 4 additions & 0 deletions examples/resources/prefect_variable/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "prefect_variable" "example" {
name = "My Variable"
value = "variable value goes here"
}
2 changes: 2 additions & 0 deletions examples/resources/prefect_work_pool/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prefect Work Pools can be imported using the work pool's name
terraform import prefect_work_pool.example name-of-work-pool
5 changes: 5 additions & 0 deletions examples/resources/prefect_work_pool/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "prefect_work_pool" "example" {
name = "My Work Pool"
type = "Kubernetes"
paused = false
}
5 changes: 5 additions & 0 deletions examples/resources/prefect_workspace/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Prefect Workspaces can be imported via name in the form `name/name-of-workspace`
terraform import prefect_workspace.example name/name-of-workspace

# Prefect Workspaces can also be imported via UUID
terraform import prefect_workspace.example workspace-uuid
4 changes: 4 additions & 0 deletions examples/resources/prefect_workspace/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "prefect_workspace" "example" {
name = "My Workspace"
Handle = "my-workspace"
}
32 changes: 32 additions & 0 deletions examples/resources/prefect_workspace_access/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ASSIGNING WORKSPACE ACCESS TO A USER
# Read down a default Workspace Role (or create your own)
data "prefect_workspace_role" "developer" {
name = "Developer"
}

# Read down an existing Account Member by email
data "prefect_account_member" "marvin" {
email = "[email protected]"
}

# Assign the Workspace Role to the Account Member
resource "prefect_workspace_access" "marvin_developer" {
accessor_type = "USER"
accessor_id = prefect_account_member.marvin.user_id
workspace_id = "workspace-UUID"
workspace_role_id = data.prefect_workspace_role.developer.id
}

# ASSIGNING WORKSPACE ACCESS TO A SERVICE ACCOUNT
# Create a Service Account resource
resource "prefect_service_account" "bot" {
name = "a-cool-bot"
}

# Assign the Workspace Role to the Service Account
resource "prefect_workspace_access" "bot_developer" {
accessor_type = "SERVICE_ACCOUNT"
accessor_id = prefect_service_account.bot.id
workspace_id = "workspace-UUID"
workspace_role_id = data.prefect_workspace_role.developer.id
}
2 changes: 2 additions & 0 deletions examples/resources/prefect_workspace_role/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prefect Workspace Roles can be imported using the workspace role's UUID
terraform import prefect_workspace_role.example workspace-role-uuid
7 changes: 7 additions & 0 deletions examples/resources/prefect_workspace_role/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "prefect_workspace_role" "example" {
name = "Custom Workspace Role"
scopes = [
"manage_blocks",
"see_flows"
]
}
9 changes: 0 additions & 9 deletions examples/service_accounts.tf

This file was deleted.

14 changes: 0 additions & 14 deletions examples/variables.tf

This file was deleted.

15 changes: 0 additions & 15 deletions examples/workspace_access.tf

This file was deleted.

3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (

const providerAddress = "registry.terraform.io/prefecthq/prefect"

// Run "go generate" to generate the docs
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate --rendered-provider-name Prefect --provider-name prefect

func main() {
providerServer := providerserver.NewProtocol6(&provider.PrefectProvider{})

Expand Down
8 changes: 8 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build tools

package tools

import (
// Documentation generation
_ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs"
)

0 comments on commit e986173

Please sign in to comment.