Skip to content

Commit

Permalink
Merge branch 'main' into jorlando/add-mobile-app-oncall-integration-t…
Browse files Browse the repository at this point in the history
…emplates
  • Loading branch information
joeyorlando authored Sep 24, 2024
2 parents f3e6c61 + efc549c commit 611b13a
Show file tree
Hide file tree
Showing 206 changed files with 7,411 additions and 1,537 deletions.
61 changes: 39 additions & 22 deletions .github/workflows/acc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ jobs:
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.21'
- uses: hashicorp/setup-terraform@v3
go-version-file: go.mod
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
- run: make integration-test

cloudinstance:
concurrency: cloud-instance
concurrency:
group: cloud-instance
cancel-in-progress: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.21'
- uses: hashicorp/setup-terraform@v3
go-version-file: go.mod
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
- name: Get Secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@main
with:
Expand All @@ -41,12 +43,16 @@ jobs:
GRAFANA_SM_ACCESS_TOKEN=cloud-instance-tests:sm-token
GRAFANA_SM_URL=cloud-instance-tests:sm-url
GRAFANA_URL=cloud-instance-tests:url
- uses: iFaxity/[email protected]
- uses: iFaxity/wait-on-action@a7d13170ec542bdca4ef8ac4b15e9c6aa00a6866 # v1.2.1
with:
resource: ${{ env.GRAFANA_URL }}
interval: 2000 # 2s
timeout: 30000 # 30s
- run: make testacc-cloud-instance
- uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
with:
timeout_minutes: 30
max_attempts: 3 # Try 3 times to make sure we don't report failures on flaky tests
command: make testacc-cloud-instance

local:
strategy:
Expand All @@ -55,7 +61,7 @@ jobs:
# OSS tests, run on all versions
version: ['11.0.0', '10.4.3', '9.5.18']
type: ['oss']
subset: ['basic', 'other', 'long', 'generate']
subset: ['basic', 'other', 'long']
include:
- version: '11.0.0'
type: 'oss'
Expand All @@ -74,36 +80,47 @@ jobs:
# Enterprise tests
- version: '11.0.0'
type: 'enterprise'
subset: 'all'
subset: 'enterprise'
- version: '10.4.3'
type: 'enterprise'
subset: 'all'
subset: 'enterprise'
- version: '9.5.18'
type: 'enterprise'
subset: 'all'
subset: 'enterprise'
# Generate tests
- version: '11.0.0'
type: 'enterprise'
subset: 'generate'
- version: '10.4.3'
type: 'enterprise'
subset: 'generate'
name: ${{ matrix.version }} - ${{ matrix.type }} - ${{ matrix.subset }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.21'
- uses: hashicorp/setup-terraform@v3
go-version-file: go.mod
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
- name: Get Enterprise License
uses: grafana/shared-workflows/actions/get-vault-secrets@main
if: matrix.type == 'enterprise'
with:
repo_secrets: |
GF_ENTERPRISE_LICENSE_TEXT=enterprise:license
- name: Cache Docker image
uses: ScribeMD/docker-cache@0.5.0
uses: ScribeMD/docker-cache@fb28c93772363301b8d0a6072ce850224b73f74e # v0.5.0
with:
key: docker-${{ runner.os }}-${{ matrix.type == 'enterprise' && 'enterprise' || 'oss' }}-${{ matrix.version }}
- run: make testacc-${{ matrix.type }}-docker
- uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
with:
timeout_minutes: 30
max_attempts: 3 # Try 3 times to make sure we don't report failures on flaky tests
command: make testacc-${{ matrix.type }}-docker
env:
GRAFANA_VERSION: ${{ matrix.version }}
TESTARGS: >-
${{ matrix.subset == 'all' && '-parallel 2' || '' }}
${{ matrix.subset == 'enterprise' && '-skip="TestAccGenerate" -parallel 2' || '' }}
${{ matrix.subset == 'basic' && '-run=".*_basic" -short -parallel 2' || '' }}
${{ matrix.subset == 'other' && '-skip=".*_basic" -short -parallel 2' || '' }}
${{ matrix.subset == 'long' && '-run=".*longtest" -parallel 1' || '' }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/cloud-acc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
concurrency: cloud-api
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.21'
- uses: hashicorp/setup-terraform@v3
go-version-file: go.mod
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
- name: Get Secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@main
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/comment-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
permissions:
pull-requests: write
steps:
- uses: mshick/add-pr-comment@v2
- uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
with:
message: |
In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ jobs:
- run-cloud-tests
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.21'
go-version-file: go.mod
- name: Import GPG key
id: import_gpg
uses: crazy-max/[email protected]
uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
with:
version: latest
args: release --clean
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- run: make golangci-lint # Using the makefile to have the same command in CI and locally

terraform_fmt:
name: terraform fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
- name: terraform fmt
run: terraform fmt -recursive -check || (echo "Terraform files aren't formatted. Run 'terraform fmt -recursive && go generate'"; exit 1;)
run: terraform fmt -recursive -check || (echo "Terraform files aren't formatted. Run 'terraform fmt -recursive && go generate ./...'"; exit 1;)

docs:
name: docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.21'
go-version-file: go.mod
- name: generate docs
run: |
go generate
go generate ./...
gitstatus="$(git status --porcelain)"
if [ -n "$gitstatus" ]; then
echo "$gitstatus"
echo 'docs are out of sync, run "go generate"'
echo 'docs are out of sync, run "go generate ./..."'
exit 1
fi
- run: make linkcheck
Expand All @@ -45,9 +45,9 @@ jobs:
name: unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: '1.21'
- uses: hashicorp/setup-terraform@v3
go-version-file: go.mod
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
- run: go test ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ website/vendor
testdata/*.crt
testdata/*.key
testdata/integration/*
testdata/plugins
!testdata/integration/main.tf
!testdata/integration/test.sh

Expand Down
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
version: 2
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
Expand Down
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GRAFANA_VERSION ?= 11.0.0
DOCKER_COMPOSE_ARGS ?= --force-recreate --detach --remove-orphans --wait --renew-anon-volumes

testacc:
go build -o testdata/plugins/registry.terraform.io/grafana/grafana/999.999.999/$$(go env GOOS)_$$(go env GOARCH)/terraform-provider-grafana_v999.999.999_$$(go env GOOS)_$$(go env GOARCH) .
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m

# Test OSS features
Expand Down
44 changes: 38 additions & 6 deletions cmd/generate/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"log"
"os"
Expand All @@ -9,6 +10,7 @@ import (
"github.com/grafana/terraform-provider-grafana/v3/pkg/generate"

"github.com/fatih/color"
goVersion "github.com/hashicorp/go-version"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -68,6 +70,24 @@ This supports a glob format. Examples:
EnvVars: []string{"TFGEN_INCLUDE_RESOURCES"},
Required: false,
},
&cli.BoolFlag{
Name: "output-credentials",
Usage: "Output credentials in the generated resources",
EnvVars: []string{"TFGEN_OUTPUT_CREDENTIALS"},
Value: false,
},
&cli.StringFlag{
Name: "terraform-install-dir",
Usage: `Directory to install Terraform to. If not set, a temporary directory will be created.`,
EnvVars: []string{"TFGEN_TERRAFORM_INSTALL_DIR"},
Required: false,
},
&cli.StringFlag{
Name: "terraform-install-version",
Usage: `Version of Terraform to install. If not set, the latest version _tested in this tool_ will be installed.`,
EnvVars: []string{"TFGEN_TERRAFORM_INSTALL_VERSION"},
Required: false,
},

// Grafana OSS flags
&cli.StringFlag{
Expand Down Expand Up @@ -148,7 +168,8 @@ This supports a glob format. Examples:
if err != nil {
return fmt.Errorf("failed to parse flags: %w", err)
}
return generate.Generate(ctx.Context, cfg)
result := generate.Generate(ctx.Context, cfg)
return errors.Join(result.Errors...)
},
}

Expand All @@ -157,10 +178,11 @@ This supports a glob format. Examples:

func parseFlags(ctx *cli.Context) (*generate.Config, error) {
config := &generate.Config{
OutputDir: ctx.String("output-dir"),
Clobber: ctx.Bool("clobber"),
Format: generate.OutputFormat(ctx.String("output-format")),
ProviderVersion: ctx.String("terraform-provider-version"),
OutputDir: ctx.String("output-dir"),
Clobber: ctx.Bool("clobber"),
Format: generate.OutputFormat(ctx.String("output-format")),
ProviderVersion: ctx.String("terraform-provider-version"),
OutputCredentials: ctx.Bool("output-credentials"),
Grafana: &generate.GrafanaConfig{
URL: ctx.String("grafana-url"),
Auth: ctx.String("grafana-auth"),
Expand All @@ -177,14 +199,24 @@ func parseFlags(ctx *cli.Context) (*generate.Config, error) {
StackServiceAccountName: ctx.String("cloud-stack-service-account-name"),
},
IncludeResources: ctx.StringSlice("include-resources"),
TerraformInstallConfig: generate.TerraformInstallConfig{
InstallDir: ctx.String("terraform-install-dir"),
},
}
var err error
if tfVersion := ctx.String("terraform-install-version"); tfVersion != "" {
config.TerraformInstallConfig.Version, err = goVersion.NewVersion(ctx.String("terraform-install-version"))
if err != nil {
return nil, fmt.Errorf("terraform-install-version must be a valid version: %w", err)
}
}

if config.ProviderVersion == "" {
return nil, fmt.Errorf("terraform-provider-version must be set")
}

// Validate flags
err := newFlagValidations().
err = newFlagValidations().
atLeastOne("grafana-url", "cloud-access-policy-token").
conflicting(
[]string{"grafana-url", "grafana-auth", "synthetic-monitoring-url", "synthetic-monitoring-access-token", "oncall-url", "oncall-access-token"},
Expand Down
16 changes: 16 additions & 0 deletions cmd/without-lister/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"

"github.com/grafana/terraform-provider-grafana/v3/pkg/provider"
)

func main() {
fmt.Println("Listing resources without lister functions:")
for _, r := range provider.Resources() {
if r.ListIDsFunc == nil {
fmt.Println(r.Name)
}
}
}
Loading

0 comments on commit 611b13a

Please sign in to comment.