Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tooling: support for auto-registering clients and services #18629

Merged
merged 1 commit into from
Oct 4, 2022
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
26 changes: 26 additions & 0 deletions .github/workflows/automation-open-pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Open Pull Request when an `auto-pr` is pushed
on:
push:
branches:
- 'auto-pr/**'

jobs:
open-pull-request:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v3

- name: "open a pull request"
id: open-pr
run: |
# this runs everytime the PR gets pushed too, whilst you can only create a PR a single time
# so we should be smarter, but piping this to /dev/null is a fine workaround for MVP
gh pr create --title "$PR_TITLE" --body "$PR_BODY" -B "$PR_TARGET" > /dev/null

env:
PR_TITLE: "Auto PR: Regenerating based on (${{ github.sha }})"
PR_BODY: "Regenerating the Terraform Provider based on the latest changes"
PR_TARGET: "main"
GITHUB_TOKEN: ${{ secrets.SERVICE_ACCOUNT_TERRAFORM_TOKEN }}
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ run:
modules-download-mode: vendor
skip-dirs:
- /sdk/ # Excluding sdk folders as these are externally generated
skip-files:
- ".*\\*_gen.go$"

issues:
max-per-linter: 0
Expand Down
6 changes: 6 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ acctests: fmtcheck
debugacc: fmtcheck
TF_ACC=1 dlv test $(TEST) --headless --listen=:2345 --api-version=2 -- -test.v $(TESTARGS)

prepare:
@echo "==> Preparing the repository (removing all '*_gen.go' files)..."
@find . -iname \*_gen.go -type f -delete
@echo "==> Preparing the repository (removing all '*_gen_test.go' files)..."
@find . -iname \*_gen_test.go -type f -delete

website-lint:
@echo "==> Checking documentation for .html.markdown extension present"
@if ! find website/docs -type f -not -name "*.html.markdown" -print -exec false {} +; then \
Expand Down
7 changes: 7 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clients

import (
"context"
"fmt"

"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/validation"
Expand Down Expand Up @@ -117,6 +118,8 @@ import (
)

type Client struct {
autoClient

// StopContext is used for propagating control from Terraform Core (e.g. Ctrl/Cmd+C)
StopContext context.Context

Expand Down Expand Up @@ -238,6 +241,10 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
// Disable the Azure SDK for Go's validation since it's unhelpful for our use-case
validation.Disabled = true

if err := buildAutoClients(&client.autoClient, o); err != nil {
return fmt.Errorf("building auto-sdk clients: %+v", err)
}

client.Features = o.Features
client.StopContext = ctx

Expand Down
14 changes: 14 additions & 0 deletions internal/clients/client_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package clients

// NOTE: this file is generated - manual changes will be overwritten.

import (
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type autoClient struct {
}

func buildAutoClients(client *autoClient, o *common.ClientOptions) error {
return nil
}
4 changes: 3 additions & 1 deletion internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ import (
//go:generate go run ../tools/generator-services/main.go -path=../../

func SupportedTypedServices() []sdk.TypedServiceRegistration {
return []sdk.TypedServiceRegistration{
services := []sdk.TypedServiceRegistration{
aadb2c.Registration{},
apimanagement.Registration{},
appconfiguration.Registration{},
Expand Down Expand Up @@ -151,6 +151,8 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
search.Registration{},
web.Registration{},
}
services = append(services, autoRegisteredTypedServices()...)
return services
}

func SupportedUntypedServices() []sdk.UntypedServiceRegistration {
Expand Down
9 changes: 9 additions & 0 deletions internal/provider/services_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package provider

// NOTE: this file is generated - manual changes will be overwritten.

import "github.com/hashicorp/terraform-provider-azurerm/internal/sdk"

func autoRegisteredTypedServices() []sdk.TypedServiceRegistration {
return []sdk.TypedServiceRegistration{}
}