Skip to content

Commit

Permalink
Prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
jreyesr committed Aug 18, 2023
1 parent 8ff4b82 commit bbc2fad
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 9 deletions.
33 changes: 33 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
- GO111MODULE=on
- GOPRIVATE=github.com/turbot
goos:
- linux
- darwin

goarch:
- amd64
- arm64

id: "steampipe"
binary: "{{ .ProjectName }}.plugin"

archives:
- format: gz
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
files:
- none*
checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS"
algorithm: sha256
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## v0.1.0 [2023-08-17]

_What's new?_

- First version of the plugin
- Select a Terraform provider, then integrate its datasources with Steampipe
81 changes: 79 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,87 @@
# `steampipe-plugin-tfbridge`
![image](https://hub.steampipe.io/images/plugins/jreyesr/tfbridge-social-graphic.png)

**WORK IN PROGRESS:** Don't use, the code is unstable! It may not do what it says, config values may behave strangely, parts may just print a message and do nothing.
# Terraform Bridge Plugin for Steampipe

Use SQL to query data from the datasources of any Terraform provider.

This repo contains a [Steampipe](https://steampipe.io/) plugin that lets the user call any (?) [data source that is exposed by a Terraform provider](https://developer.hashicorp.com/terraform/language/data-sources). This will expand the reach of Steampipe's plugins to also cover remote APIs that have a Terraform provider but no Steampipe plugin. This will also let users unify efforts: the Terraform provider can be used to manage resources, and querying on the current state of those resources can be done via Steampipe, using the same source code and provider.


- **[Get started →](https://hub.steampipe.io/plugins/jreyesr/tfbridge)**
- Documentation: [Table definitions & examples](https://hub.steampipe.io/plugins/jreyesr/tfbridge/tables)
- Community: [Join #steampipe on Slack →](https://turbot.com/community/join)
- Get involved: [Issues](https://github.com/jreyesr/steampipe-plugin-tfbridge/issues)

## Quick start

Install the plugin with [Steampipe](https://steampipe.io):

```shell
steampipe plugin install jreyesr/tfbridge
```

Configure your [config file](https://hub.steampipe.io/plugins/jreyesr/tfbridge#configuration) to point to a Terraform provider+version. If the Terraform provider requires configuration values, provide them too.

Run steampipe:

```shell
steampipe query
```

Run a query for whatever data source the Terraform provider exposes:

```sql
select
attr1,
attr2
from
datasource_name;
```

## Developing

Prerequisites:

- [Steampipe](https://steampipe.io/downloads)
- [Golang](https://golang.org/doc/install)

Clone:

```sh
git clone https://github.com/jreyesr/steampipe-plugin-tfbridge.git
cd steampipe-plugin-tfbridge
```

Build, which automatically installs the new version to your `~/.steampipe/plugins` directory:

```
make
```

Configure the plugin:

```
cp config/* ~/.steampipe/config
vi ~/.steampipe/config/tfbridge.spc
```

Try it!

```
steampipe query
> .inspect tfbridge
```

Further reading:

- [Writing plugins](https://steampipe.io/docs/develop/writing-plugins)
- [Writing your first table](https://steampipe.io/docs/develop/writing-your-first-table)

## Contributing

Please see the [contribution guidelines](https://github.com/turbot/steampipe/blob/main/CONTRIBUTING.md) and our [code of conduct](https://github.com/turbot/steampipe/blob/main/CODE_OF_CONDUCT.md). All contributions are subject to the [Mozilla Public License 2.0 open source license](https://github.com/jreyesr/steampipe-plugin-tfbridge/blob/main/LICENSE).


## Old proof of concept

Previously (see [the `poc` tag](https://github.com/jreyesr/steampipe-plugin-tfbridge/tree/poc)), the repo only contained a proof of concept Go program that was used to test ways of driving a Terraform plugin. This wasn't too documented before, with [Terraform's docs](https://developer.hashicorp.com/terraform/plugin/best-practices/interacting-with-providers#using-the-rpc-protocol) merely stating that
Expand Down
18 changes: 15 additions & 3 deletions config/tfbridge.spc
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
connection "tfbridge" {
plugin = "jreyesr/tfbridge"

provider = "hashicorp/dns"
version = "3.2.4"
# Write the name of a Terraform provider, in the same way that you'd write it
# in the required_providers block in the Terraform main file
# Examples: "hashicorp/aws", "TimDurward/slack", "hashicorp/random"
# If using a private Terraform registry, also include the hostname: "registry.acme.com/acme/supercloud"
provider = "integrations/github"

# Write a single version for a Terraform provider, in the same way that you'd write it
# in the required_providers block in the Terraform main file
# Note that, unlike in the Terraform file, you can't use a version constraint, such as "~> 1.0" or ">= 1.2.0, < 2.0.0",
# only explicit versions are allowed
version = "5.33.0"

# If the Terraform provider would require some configuration in its provider {...} block,
# copy it here directly (just the _contents_ of the provider {} block, not the entire block!)
provider_config = <<EOT
token = "github_pat_9fu38f0amil9FVOKmI0_0F8PmI0m0FNm"
EOT
}
}
105 changes: 105 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
organization: jreyesr
category: ["software development"]
icon_url: "/images/plugins/jreyesr/tfbridge.svg"
brand_color: "#844FBA"
display_name: Terraform Bridge
name: tfbridge
description: Steampipe plugin for proxying requests to Terraform data sources.
og_description: Query Duo Security with SQL! Open source CLI. No DB required.
og_image: "/images/plugins/jreyesr/tfbridge-social-graphic.png"
---

# Terraform data sources + Steampipe

[Terraform](https://www.terraform.io/) lets you provision and manage resources in any cloud or data center. It has many providers, which let Terraform interface with external systems.

[Steampipe](https://steampipe.io) is an open source CLI to instantly query cloud APIs using SQL.

The Terraform Bridge plugin for Steampipe lets you reuse the data sources that some Terraform providers come with, so you can query them using Steampipe's SQL interface. If there is a Terraform provider that has a data source that already obtains the data that you need, you can consume that data from Steampipe (normally you'd have to use a Terraform file and `data {}` blocks)

For example:

(using the [Github Terraform provider's data sources](https://registry.terraform.io/providers/integrations/github/5.33.0))

```sql
select
*
from
github_repositories
where
query='org:turbot';
```

| query | id | include_repo_id | results_per_page | sort | full_names | names |
|---|---|---|---|---|---|---|
| org:turbot | org:turbot | false | 100 | updated | ["turbot/steampipe", "turbot/steampipe-plugin-aws", "turbot/steampipe-mod-github-sherlock", ...] | ["steampipe", "steampipe-plugin-aws", "steampipe-mod-github-sherlock", ...] |

(using an [Algolia Terraform provider](https://registry.terraform.io/providers/k-yomo/algolia/latest))

```sql
select
*
from
algolia_index
where
name='indexname'
```

| name | id | advanced_config |
|---|---|---|
| yourindex | yourindex | [{"attribute_criteria_computed_by_min_proximity": true, "attribute_for_distinct": "url", "distinct": 1, "max_facet_hits": 10, "min_proximity": 1, ...}]|

## Documentation

- **[Table definitions & examples →](/plugins/jreyesr/tfbridge/tables)**

## Get started

### Install

Download and install the latest Terraform Bridge plugin:

```bash
steampipe plugin install jreyesr/tfbridge
```

### Credentials

See [your Terraform provider](https://registry.terraform.io/) of choice for credentials. Anything that would normally go into the `provider "name" {...}` block in the Terraform file should be placed directly in the Steampipe config file (`~/.steampipe/config/tfbridge.spc`), in the `provider_config` value.

### Configuration

Installing the latest Terraform Bridge plugin will create a config file (`~/.steampipe/config/tfbridge.spc`) with a single connection named `tfbridge`:

```hcl
connection "tfbridge" {
plugin = "jreyesr/tfbridge"
# Write the name of a Terraform provider, in the same way that you'd write it
# in the required_providers block in the Terraform main file
# Examples: "hashicorp/aws", "TimDurward/slack", "hashicorp/random"
# If using a private Terraform registry, also include the hostname: "registry.acme.com/acme/supercloud"
provider = "integrations/github"
# Write a single version for a Terraform provider, in the same way that you'd write it
# in the required_providers block in the Terraform main file
# Note that, unlike in the Terraform file, you can't use a version constraint, such as "~> 1.0" or ">= 1.2.0, < 2.0.0",
# only explicit versions are allowed
version = "5.33.0"
# If the Terraform provider would require some configuration in its provider {...} block,
# copy it here directly (just the _contents_ of the provider {} block, not the entire block!)
provider_config = <<EOT
token = "github_pat_9fu38f0amil9FVOKmI0_0F8PmI0m0FNm"
EOT
}
```

`provider` and `version` define which Terraform provider you want to use. You can find those in [the Terraform registry](https://registry.terraform.io/). If you have a working Terraform configuration, you may also run `terraform version` to retrieve the versions currently in use.

`provider_config` is a string that contains any configuration that must be forwarded to the Terraform provider. It should contain the entire contents of the `provider "yourprovname" {...}` block in the Terraform configuration (_only_ what is inside the curly braces, but not the `provider "yourprovname"` part). Those configuration values can be found in the Terraform Registry docs for your provider of choice.

## Get involved

* Open source: https://github.com/jreyesr/steampipe-plugin-tfbridge
Loading

0 comments on commit bbc2fad

Please sign in to comment.