Skip to content

Commit bcf9e88

Browse files
Supamj10czar
authored andcommitted
[TFgen] (Phase 1) Create stubs and add dependencies.
Added stubs for the current .go files. Added cobra, libopenapi, and their dependencies to the LICENSE-3rdparty file.
1 parent 18b5865 commit bcf9e88

9 files changed

Lines changed: 180 additions & 0 deletions

File tree

.generator-v2/cmd/tfgen/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/terraform-providers/terraform-provider-datadog/generator/internal/cli"
7+
)
8+
9+
// Version is stamped at link time via -ldflags "-X main.Version=<tag>".
10+
var Version = "dev"
11+
12+
func main() {
13+
os.Exit(cli.Execute(Version))
14+
}

.generator-v2/go.mod

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module github.com/terraform-providers/terraform-provider-datadog/generator
2+
3+
go 1.25.8
4+
5+
toolchain go1.26.1
6+
7+
require (
8+
github.com/pb33f/libopenapi v0.37.2
9+
github.com/spf13/cobra v1.10.2
10+
)
11+
12+
require (
13+
github.com/bahlo/generic-list-go v0.2.0 // indirect
14+
github.com/buger/jsonparser v1.1.2 // indirect
15+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
16+
github.com/pb33f/jsonpath v0.8.2 // indirect
17+
github.com/pb33f/ordered-map/v2 v2.3.1 // indirect
18+
github.com/spf13/pflag v1.0.9 // indirect
19+
go.yaml.in/yaml/v4 v4.0.0-rc.4 // indirect
20+
golang.org/x/sync v0.20.0 // indirect
21+
)

.generator-v2/go.sum

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
2+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
3+
github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
4+
github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
5+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
6+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
9+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
10+
github.com/pb33f/jsonpath v0.8.2 h1:Ou4C7zjYClBm97dfZjDCjdZGusJoynv/vrtiEKNfj2Y=
11+
github.com/pb33f/jsonpath v0.8.2/go.mod h1:zBV5LJW4OQOPatmQE2QdKpGQJvhDTlE5IEj6ASaRNTo=
12+
github.com/pb33f/libopenapi v0.37.2 h1:4Kb4w/h2BVKb099oYIZqeDxEBhUioWA+z6WJhBOk2r8=
13+
github.com/pb33f/libopenapi v0.37.2/go.mod h1:MsDdUlQ1CdrIDO5v26JfgBxQs7kcaOUEpMP3EqU6bI4=
14+
github.com/pb33f/ordered-map/v2 v2.3.1 h1:5319HDO0aw4DA4gzi+zv4FXU9UlSs3xGZ40wcP1nBjY=
15+
github.com/pb33f/ordered-map/v2 v2.3.1/go.mod h1:qxFQgd0PkVUtOMCkTapqotNgzRhMPL7VvaHKbd1HnmQ=
16+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
17+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
18+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
19+
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
20+
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
21+
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
22+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
23+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
24+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
25+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
26+
go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U=
27+
go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
28+
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
29+
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
30+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
31+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
32+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cli
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
func newGenerateCmd(flags *globalFlags) *cobra.Command {
8+
var check bool
9+
var include string
10+
11+
cmd := &cobra.Command{
12+
Use: "generate",
13+
Short: "Generate Terraform artifacts from the OpenAPI spec",
14+
RunE: func(cmd *cobra.Command, args []string) error {
15+
// TODO: implement in T033
16+
return nil
17+
},
18+
}
19+
20+
cmd.Flags().BoolVar(&check, "check", false, "Read-only mode: exit 3 if any file would change")
21+
cmd.Flags().StringVar(&include, "include", "", "Comma-separated artifact names to generate (empty = all)")
22+
_ = check
23+
_ = include
24+
25+
return cmd
26+
}

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cli
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
type globalFlags struct {
8+
spec string
9+
outputRoot string
10+
hooksRoot string
11+
trackingField string
12+
maxDepth int
13+
report string
14+
quiet bool
15+
}
16+
17+
func newRootCmd(version string, flags *globalFlags) *cobra.Command {
18+
cmd := &cobra.Command{
19+
Use: "tfgen",
20+
Short: "Datadog Terraform Provider Generator",
21+
Version: version,
22+
SilenceUsage: true,
23+
}
24+
25+
cmd.PersistentFlags().StringVar(&flags.spec, "spec", ".generator/V2/openapi.yaml", "OpenAPI spec to read")
26+
cmd.PersistentFlags().StringVar(&flags.outputRoot, "output-root", "datadog/fwprovider", "Root directory for generated artifacts")
27+
cmd.PersistentFlags().StringVar(&flags.hooksRoot, "hooks-root", "datadog/fwprovider/hooks", "Root directory for hook subpackages")
28+
cmd.PersistentFlags().StringVar(&flags.trackingField, "tracking-field", "x-datadog-tf-generator", "OpenAPI extension name for the tracking field")
29+
cmd.PersistentFlags().IntVar(&flags.maxDepth, "max-depth", 8, "Hard limit on recursive $ref expansion")
30+
cmd.PersistentFlags().StringVar(&flags.report, "report", "-", "Where to write the run report (\"-\" = stdout)")
31+
cmd.PersistentFlags().BoolVar(&flags.quiet, "quiet", false, "Suppress informational logging")
32+
33+
return cmd
34+
}
35+
36+
// Execute is the entry point called by main. Returns an exit code.
37+
func Execute(version string) int {
38+
flags := &globalFlags{}
39+
root := newRootCmd(version, flags)
40+
root.AddCommand(newGenerateCmd(flags))
41+
root.AddCommand(newVerifyCmd(flags))
42+
43+
if err := root.Execute(); err != nil {
44+
return 1
45+
}
46+
return 0
47+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cli
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
func newVerifyCmd(flags *globalFlags) *cobra.Command {
8+
var strict bool
9+
10+
cmd := &cobra.Command{
11+
Use: "verify",
12+
Short: "Run post-generation checks without writing files",
13+
RunE: func(cmd *cobra.Command, args []string) error {
14+
// TODO: implement in T065
15+
return nil
16+
},
17+
}
18+
19+
cmd.Flags().BoolVar(&strict, "strict", false, "Treat orphaned-hook warnings as errors")
20+
_ = strict
21+
22+
return cmd
23+
}

.generator-v2/internal/parser/.gitkeep

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package parser
2+
3+
import "github.com/pb33f/libopenapi"
4+
5+
// LoadSpec loads and parses the OpenAPI specification at path.
6+
// Full implementation in T009.
7+
func LoadSpec(path string) (libopenapi.Document, error) {
8+
panic("not implemented")
9+
}

LICENSE-3rdparty.csv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,12 @@ go.sum,github.com/bmatcuk/doublestar/v4,MIT,2014 Bob Matcuk
257257
go.sum,github.com/hashicorp/cli,MPL-2.0,
258258
go.sum,github.com/yuin/goldmark-meta,MIT,2019 Yusuke Inuzuka
259259
go.sum,go.abhg.dev/goldmark/frontmatter,BSD-3-Clause,2023 Abhinav Gupta
260+
go.sum,github.com/pb33f/libopenapi,MIT,2022-Present pb33f / Dave Shanley
261+
go.sum,github.com/pb33f/jsonpath,MIT,2022-Present pb33f / Dave Shanley
262+
go.sum,github.com/pb33f/ordered-map/v2,MIT,2022-Present pb33f / Dave Shanley
263+
go.sum,github.com/spf13/cobra,Apache-2.0,2013 Steve Francia
264+
go.sum,github.com/bahlo/generic-list-go,MIT,2021 Nils Müller
265+
go.sum,github.com/buger/jsonparser,MIT,2016 Yuriy Vasiyarov
266+
go.sum,github.com/inconshreveable/mousetrap,Apache-2.0,2014 Alan Shreve
267+
go.sum,go.yaml.in/yaml/v4,MIT and Apache-2.0,2006-2011 Kirill Simonov and 2011-2019 Canonical Ltd
260268

0 commit comments

Comments
 (0)