Skip to content

Commit 022f705

Browse files
authored
[TFgen] Phase 1 Setup CLI (#3842)
* [1.4] Add a github workflow for build + vet * [1.5] Add make command to build/test the generator * [1.6] Create testdata/fixtures with README * root formatting fixes * updated 1.4 to any branch and added go depencency files to paths
1 parent bcf9e88 commit 022f705

4 files changed

Lines changed: 89 additions & 4 deletions

File tree

.generator-v2/internal/cli/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ type globalFlags struct {
1616

1717
func newRootCmd(version string, flags *globalFlags) *cobra.Command {
1818
cmd := &cobra.Command{
19-
Use: "tfgen",
20-
Short: "Datadog Terraform Provider Generator",
21-
Version: version,
19+
Use: "tfgen",
20+
Short: "Datadog Terraform Provider Generator",
21+
Version: version,
2222
SilenceUsage: true,
2323
}
2424

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Fixture Catalogue
2+
3+
Curated test inputs for the `tfgen` end-to-end suite. Each fixture is a self-contained directory holding everything needed to drive the generator and assert on its output: an OpenAPI input spec and the expected golden code the generator should produce from it.
4+
5+
The E2E suite runs `tfgen` against a fixture's `openapi.yaml` and compares the result against the committed `out/` directory. Each fixture therefore exercises one specific generator capability end to end.
6+
7+
## Layout
8+
9+
Each fixture is a directory under this one:
10+
11+
```
12+
<fixture_name>/
13+
├── openapi.yaml # Input spec with x-datadog-tf-generator annotations
14+
├── out/ # Expected golden output (committed)
15+
│ └── *.go
16+
└── README.md # (optional) what this fixture exercises
17+
```
18+
19+
- **`openapi.yaml`** — the OpenAPI spec the generator reads. The resources and data sources to generate are marked with the `x-datadog-tf-generator` extension.
20+
- **`out/`** — the golden output: the `.go` files the generator is expected to emit. These are committed and diffed against on every run. When generator behavior changes intentionally, regenerate this directory and review the diff by hand.
21+
- **`README.md`** *(optional)* — a short note describing the capability the fixture targets (e.g. a particular schema shape, a hook, or an error path).
22+
23+
## Naming
24+
25+
Name each fixture after the artifact it generates so the catalogue reads as a list of capabilities:
26+
27+
- `data_source_<name>` — a generated data source (e.g. `data_source_pet`).
28+
- `resource_<name>` — a generated resource.
29+
- Append a distinguishing suffix when a fixture targets a variant or edge case (e.g. `data_source_team_with_hooks`, `broken_hook_signature`).
30+
31+
> [!NOTE]
32+
> This catalogue is currently empty. Fixtures are added in later phases as the corresponding generator capabilities land.

.github/workflows/tfgen.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Generator Checks
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- ".generator-v2/internal/**"
10+
- ".generator-v2/cmd/tfgen/**"
11+
- ".generator-v2/go.mod"
12+
- ".generator-v2/go.sum"
13+
- ".github/workflows/tfgen.yml"
14+
15+
concurrency:
16+
group: ${{ github.head_ref || github.run_id }}-tfgen
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build-and-vet:
21+
name: build and vet
22+
runs-on: ubuntu-latest
23+
if: github.event.action != 'closed' && github.event.pull_request.merged != true
24+
defaults:
25+
run:
26+
working-directory: .generator-v2
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
30+
31+
- name: Install Go
32+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe
33+
with:
34+
go-version-file: .generator-v2/go.mod
35+
cache: true
36+
cache-dependency-path: .generator-v2/go.sum
37+
38+
- name: go build
39+
run: go build ./cmd/tfgen/...
40+
41+
- name: go vet
42+
run: go vet ./cmd/tfgen/...

GNUmakefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ DIR=~/.terraform.d/plugins
66
ZORKIAN_VERSION?=master
77
API_CLIENT_VERSION?=master
88
LOCAL_PACKAGE="github.com/terraform-providers/terraform-provider-datadog"
9+
GO?=go
910

1011
default: build
1112

@@ -68,6 +69,16 @@ test-compile: get-test-deps
6869
exit 1; \
6970
fi
7071
gotestsum --format testname -- -c $(TEST) $(TESTARGS)
72+
73+
# Build the tfgen binary into bin/tfgen (generator lives in its own module under .generator-v2)
74+
tfgen-build:
75+
cd .generator-v2 && $(GO) build -o $(CURDIR)/bin/tfgen ./cmd/tfgen
76+
@echo "Built tfgen -> bin/tfgen"
77+
78+
# Run the tfgen module's unit tests
79+
tfgen-test:
80+
cd .generator-v2 && $(GO) test ./internal/... ./cmd/tfgen/...
81+
@echo "tfgen tests passed"
7182

7283
update-go-client:
7384
echo "Updating the Zorkian client to ${ZORKIAN_VERSION} and the API Client to ${API_CLIENT_VERSION}"
@@ -103,4 +114,4 @@ check-docs: docs
103114
echo "Success: No generated documentation changes detected"; \
104115
fi
105116

106-
.PHONY: build check-docs docs test testall testacc cassettes vet fmt fmtcheck errcheck lint lint-new lint-fix test-compile get-test-deps license-check sweep
117+
.PHONY: build check-docs docs test testall testacc tfgen-build tfgen-test cassettes vet fmt fmtcheck errcheck lint lint-new lint-fix test-compile get-test-deps license-check sweep

0 commit comments

Comments
 (0)