Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Handle grants on multiple columns of a table #40

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 25 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# This uses an action (crazy-max/ghaction-import-gpg@v5) that assumes you set your
# private key in the `gpg_private_key` secret and passphrase in the `passphrase`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release
on:
push:
tags:
- 'v*'
branches:
- 'feature/add-complex-grants-support'
jobs:
goreleaser:
runs-on: ubuntu-latest
runs-on: tf-registry-provider-mysql
steps:
-
name: Checkout
Expand All @@ -32,16 +34,23 @@ jobs:
-
name: Import GPG key
id: import_gpg
uses: paultyng/[email protected]
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: crazy-max/ghaction-import-gpg@v5
with:
version: latest
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
# -
# name: Run GoReleaser
# uses: goreleaser/goreleaser-action@v3
# with:
# version: latest
# args: release
# env:
# GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
# GITHUB_TOKEN: ${{ secrets.TOKEN }}
-
name: Test ref name
run: echo ${{github.ref_name}}
# -
# name: Publish provider
# run: /home/ec2-user/citizen-linux-x64 provider --registry http://localhost:3000 stable mysql ${{ steps.module-version.outputs.data }}
# working-directory: dist
14 changes: 5 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@ builds:
ldflags:
- "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}"
goos:
- freebsd
- windows
- linux
- darwin
goarch:
- amd64
- "386"
- arm
- arm64
ignore:
- goos: darwin
goarch: "386"
binary: "{{ .ProjectName }}_v{{ .Version }}"
- goos: linux
goarch: arm64
binary: "stable-mysql_v{{ .Version }}"
archives:
- format: zip
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
name_template: "stable-mysql_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS"
name_template: "stable-mysql_{{ .Version }}_SHA256SUMS"
algorithm: sha256
signs:
- artifacts: checksum
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.10.8 (August 29, 2022)

FEATURES:
* Updated read complex `grants` ([#6](https://github.com/bitvavo/terraform-provider-mysql/pull/6))

## 1.10.7 (August 8, 2022)

FEATURES:
* New way of handling `grants` ([#1](https://github.com/bitvavo/terraform-provider-mysql/pull/1))

...

## 1.9.1 (Unreleased)
## 1.9.0 (November 07, 2019)

Expand Down
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,41 @@

---

Terraform Provider
==================
# Terraform Provider

Usage
-----
## Publish

Packages for version and different os_architecture are generated with `.goreleaser.yaml`, triggered by pushing a new `git tag`

### Manual build and publish to private terraform registry using [citizen](https://github.com/outsideris/citizen/)

Before publishing an executable is required, executable is found in the releases page on the specific version of the private tf registry that is needed(example: [v0.5.2](https://github.com/outsideris/citizen/releases/tag/v0.5.2))

```sh
env GOOS=target-OS GOARCH=target-architecture make build
```

A zip archive format is required by the private terraform registry, multiple os_architecture builds under the same name and version will be uploaded together:

```sh
zip stable-mysql_0.0.1_<target-OS>_<target-architecture>.zip terraform-provider-mysql
ex:
stable-mysql_0.0.1_darwin_arm64.zip
stable-mysql_0.0.1_linux_amd64.zip

CITIZEN_ADDR=http://localhost:3000 ./citizen-macos-amd64 provider stable mysql 0.0.1 -v
```

---

## Usage

```hcl
terraform {
required_providers {
mysql = {
source = "winebarrel/mysql"
version = "~> 1.10.2"
source = "localhost/stable/mysql"
version = "~> 0.0.1"
}
}
required_version = ">= 0.13"
Expand All @@ -23,4 +46,12 @@ provider "mysql" {
endpoint = "localhost"
username = "root"
}

resource "mysql_grant" "test_db1" {
user = "test"
host = "%"
database = "db"
table = "table"
privileges = [ "SELECT", "INSERT (`column1`)", "UPDATE (`column1`, `column2`, `column3`)"]
}
```
4 changes: 3 additions & 1 deletion mysql/resource_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ func showGrants(db *sql.DB, user string) ([]*MySQLGrant, error) {
}

privsStr := m[1]
priv_list := strings.Split(privsStr, ",")
rem1 := regexp.MustCompile("[A-Z]+\\ ?\\([a-zA-Z0-9_,\\ `]+\\)|[A-Z]+ [A-Z]+ [A-Z]+|[A-Z]+ [A-Z]+|[A-Z]+")
priv_list := rem1.FindAllString(privsStr, -1)

privileges := make([]string, len(priv_list))

for i, priv := range priv_list {
Expand Down