Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
87 changes: 61 additions & 26 deletions dev/main/main.tf-sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,45 @@ provider "hoop" {
api_url = "http://localhost:8009/api"
}

resource "hoop_connection" "bash-console" {
name = "bash-console"
type = "custom"
# subtype = ""
resource "hoop_connection" "postgres-demo" {
name = "postgres-demo"
type = "database"
subtype = "postgres"
agent_id = "75122bce-f957-49eb-a812-2ab60977cd9f"

command = [
"bash",
]

secrets = {
"envvar:MYENV" = "value"
"filesystem:MYFILE" = "content of my file"
"envvar:HOST" = "demo-pg-public-dns-url"
"envvar:PORT" = "5432"
"envvar:USER" = "pguser-demo"
"envvar:PASS" = "pg-pw-demo"
"envvar:DB" = "dellstore"
"envvar:SSLMODE" = "prefer"
}

reviewers = [
"admin",
]

redact_types = [
"EMAIL_ADDRESS",
"PHONE_NUMBER"
command = [
"psql",
"-v",
"ON_ERROR_STOP=1",
"-A",
"-F\t",
"-P",
"pager=off",
"-h",
"$HOST",
"-U",
"$USER",
"--port=$PORT",
"$DB",
]

access_mode_runbooks = "enabled"
access_mode_exec = "enabled"
access_mode_connect = "enabled"
access_schema = "enabled"

# guardrail_rules = []
# jira_issue_template_id = ""

access_mode_exec = "enabled"
access_mode_connect = "enabled"
access_schema = "enabled"

tags = {
environment = "development"
type = "custom"
purpose = "demo"
type = "database"
}
}

Expand All @@ -63,3 +65,36 @@ resource "hoop_plugin_connection" "webhooks" {
connection_id = hoop_connection.bash-console.id
config = []
}

resource "hoop_runbook_configuration" "hoop-public-runbooks" {
git_url = "https://github.com/hoophq/runbooks.git"
git_hook_ttl = 0
git_user = ""
git_password = ""
ssh_user = ""
ssh_key = ""
ssh_keypass = ""
ssh_known_hosts = ""
}

resource "hoop_runbook_rule" "pg_dev" {
name = "Example Runbook Rule"
description = "An example runbook rule"
connections = [hoop_connection.postgres-demo.name]
user_groups = ["developers"]
runbooks = [
{
repository = hoop_runbook_configuration.hoop-public-runbooks.repository
name = "postgres-demo/update-customer-email.runbook.sql"
},
{
repository = hoop_runbook_configuration.hoop-public-runbooks.repository
name = "postgres-demo/delete-customer-by-id.runbook.sql"
},
{
repository = hoop_runbook_configuration.hoop-public-runbooks.repository
name = "postgres-demo/fetch-customer-by-id.runbook.sql"
}
]
}

240 changes: 240 additions & 0 deletions docs/guides/upgrade-guide-0.0.19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great!

page_title: "Terraform Hoop Provider 0.0.19 Upgrade Guide"
subcategory: ""
---

Version 0.0.19 introduces integration with new endpoints for defining multiple repository Runbook Configurations and rules. This allows you to specify which user groups and connections can interact with a given runbook. This guide outlines the key updates and how to adapt your configurations accordingly.

Hoop Gateway version 1.46.0 introduces breaking changes that remove support for managing `hoop_plugin_connection` and `hoop_plugin_config` for the **runbooks plugin**.

## Resource: `hoop_plugin_connection`

This resource no longer supports the **runbooks** plugin. It has been superseded by the new `hoop_runbook_rule` resource.

## Resource: `hoop_plugin_config`

This resource no longer supports the **runbooks** plugin. It has been superseded by the new `hoop_runbook_configuration` resource.

## Deprecated Resources

The following resources are deprecated for managing the **plugin runbooks**

- `hoop_plugin_connection`
- `hoop_plugin_config`

## State Migration

If your state files contain the removed resources, you'll need to manually remove them from your state using the terraform state rm command:

```sh
terraform state rm hoop_plugin_config.runbooks
terraform state rm hoop_plugin_connection.myrule1
terraform state rm hoop_plugin_connection.myrule2
```

### Practical Example

Here's an outdated resource configuration that requires updating. The example below shows a connection using the deprecated plugin runbook configuration.

```hcl
terraform {
required_providers {
hoop = {
source = "hoophq/hoop"
version = "0.0.18"
}
}
}

provider "hoop" {
api_url = "http://localhost:8009/api"
api_key = "<api-key>"
}

resource "hoop_connection" "postgres-demo" {
name = "postgres-demo"
type = "database"
subtype = "postgres"
agent_id = "75122bce-f957-49eb-a812-2ab60977cd9f"

secrets = {
"envvar:HOST" = "pg-demo-public-dns-url"
"envvar:PORT" = "5432"
"envvar:USER" = "pguser"
"envvar:PASS" = "pgpwd"
"envvar:DB" = "dellstore"
"envvar:SSLMODE" = "prefer"
}

command = [
"psql",
"-v",
"ON_ERROR_STOP=1",
"-A",
"-F\t",
"-P",
"pager=off",
"-h",
"$HOST",
"-U",
"$USER",
"--port=$PORT",
"$DB",
]

access_mode_runbooks = "enabled"
access_mode_exec = "enabled"
access_mode_connect = "enabled"
access_schema = "enabled"

tags = {
environment = "development"
type = "database"
}
}

resource "hoop_plugin_config" "runbooks" {
plugin_name = "runbooks"
config = {
GIT_URL = "https://github.com/hoophq/runbooks.git"
}
}

resource "hoop_plugin_connection" "postgres-demo" {
plugin_name = "runbooks"
connection_id = hoop_connection.postgres-demo.id
config = ["postgres-demo/fetch-customer-by-id.runbook.sql"]
}
```

- **Updating the new resources**

```hcl
terraform {
required_providers {
hoop = {
source = "hoophq/hoop"
version = "0.0.19"
}
}
}

provider "hoop" {
api_url = "http://localhost:8009/api"
api_key = "<api-key>"
}

resource "hoop_connection" "postgres-demo" {
name = "postgres-demo"
type = "database"
subtype = "postgres"
agent_id = "75122bce-f957-49eb-a812-2ab60977cd9f"

secrets = {
"envvar:HOST" = "demo-pg-db.public-dns"
"envvar:PORT" = "5432"
"envvar:USER" = "pgdemo-user"
"envvar:PASS" = "pgdemo-pwd"
"envvar:DB" = "dellstore"
"envvar:SSLMODE" = "prefer"
}

command = [
"psql",
"-v",
"ON_ERROR_STOP=1",
"-A",
"-F\t",
"-P",
"pager=off",
"-h",
"$HOST",
"-U",
"$USER",
"--port=$PORT",
"$DB",
]

access_mode_runbooks = "enabled"
access_mode_exec = "enabled"
access_mode_connect = "enabled"
access_schema = "enabled"

tags = {
environment = "development"
type = "database"
}
}

resource "hoop_runbook_configuration" "runbooks" {
git_url = "https://github.com/hoophq/runbooks.git"
git_hook_ttl = 0
git_user = ""
git_password = ""
ssh_user = ""
ssh_key = ""
ssh_keypass = ""
ssh_known_hosts = ""
}

resource "hoop_runbook_rule" "postgres-demo" {
name = "Postgres Dev Migration"
description = "Postgres Dev Migration Tool Rule"
connections = [hoop_connection.postgres-demo.name]
user_groups = []
runbooks = [
{
repository = hoop_runbook_configuration.runbooks.repository
name = "postgres-dev/run-migration.runbook.sql"
}
]
}

```

1. Upgrade the provider with the new version

```sh
terraform init -upgrade
```

2. Remove the old resources from the state

```sh
terraform state rm hoop_plugin_config.runbooks
terraform state rm hoop_plugin_connection.postgres-demo
```

3. Import the new resources into the state

To import the runbook rule resource into the state, you must first retrieve the current state from the API.

When you start the gateway on version 1.46 or later, it automatically migrates plugin connections to runbook rules and removes the old resources. As a result, you'll need to list the rules from the API to identify which rules are associated with this repository.

You can list the runbook rules from the command line using the following command:

```sh
hoop config create --api-url https://your-public-gateway-url
hoop login
curl -H "Authorization: Bearer $(hoop config view token)" https://your-public-gateway-url/api/runbooks/rules |jq
```

Then, import the state of the new resource:

```sh
terraform import hoop_runbook_configuration.runbooks https://github.com/hoophq/runbooks.git
terraform import hoop_runbook_rule.postgres-demo <runbook-rule-resource-id>
```

In case you have many rules and it's hard to map all the resources properly, it's possible to erase all the **Runbook Rules** migrated and just build the new resources via terraform and apply it.

```sql
DELETE FROM private.runbook_rules
WHERE description = 'Auto-migrated from Runbooks';
```

4. Apply the changes

```sh
terraform apply
```
9 changes: 6 additions & 3 deletions docs/resources/plugin_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "hoop_plugin_config Resource - hoop"
subcategory: ""
description: |-
Plugin Config resources allows configuring plugin definitions. The supported plugins that accept configurations are: slack, and runbooks. Make sure to work with this resource only with the gateway version 1.39.1 and onwards.
Plugin Config resources allows configuring plugin definitions. The supported plugins that accept configurations are: slack, and runbooks (DEPRECATED). Make sure to work with this resource only with the gateway version 1.39.1 and onwards.
---

# hoop_plugin_config (Resource)

Plugin Config resources allows configuring plugin definitions. The supported plugins that accept configurations are: `slack`, and `runbooks`. Make sure to work with this resource only with the gateway version 1.39.1 and onwards.
Plugin Config resources allows configuring plugin definitions. The supported plugins that accept configurations are: `slack`, and `runbooks` (DEPRECATED). Make sure to work with this resource only with the gateway version 1.39.1 and onwards.

## Example Usage

Expand All @@ -25,6 +25,7 @@ resource "hoop_plugin_config" "slack" {
}

# Runbooks plugin configuration. Public Repositories
# DEPRECATED in favor of hoop_runbook_configuration resource
resource "hoop_plugin_config" "runbooks" {
plugin_name = "runbooks"
config = {
Expand All @@ -33,6 +34,7 @@ resource "hoop_plugin_config" "runbooks" {
}

# Runbooks plugin configuration. Basic Credentials
# DEPRECATED in favor of hoop_runbook_configuration resource
resource "hoop_plugin_config" "runbooks" {
plugin_name = "runbooks"
config = {
Expand All @@ -43,6 +45,7 @@ resource "hoop_plugin_config" "runbooks" {
}

# Runbooks plugin configuration. SSH Private Keys
# DEPRECATED in favor of hoop_runbook_configuration resource
resource "hoop_plugin_config" "runbooks" {
plugin_name = "runbooks"
config = {
Expand All @@ -61,7 +64,7 @@ resource "hoop_plugin_config" "runbooks" {
### Required

- `config` (Map of String, Sensitive) A map of generic configuration required for this plugin.
- `plugin_name` (String) The name of the plugin that this configuration refers to. Accepted values are: `slack`, and `runbooks`.
- `plugin_name` (String) The name of the plugin that this configuration refers to. Accepted values are: `slack`, and `runbooks` (DEPRECATED).

### Read-Only

Expand Down
Loading