diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 52f8e01..066fc06 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,4 +44,25 @@ jobs: with: go-version-file: ./go.mod check-latest: true - - run: make lint \ No newline at end of file + - run: make lint + + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - run: npx cdktf-cli get + + - uses: hashicorp/terraform-cdk-action@v5 + with: + cdktfVersion: 0.20.9 + terraformVersion: 1.9.5 + mode: auto-approve-apply + stackName: my-stack + githubToken: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0acf952..2e13391 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,30 +1,30 @@ name: "Plan" on: - pull_request: - branches: - - main + pull_request: + branches: + - main permissions: contents: read pull-requests: write jobs: - terraform: + test: + permissions: + checks: write + uses: ./.github/workflows/main.yml + + plan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v4 with: node-version: 20 - - run: npx cdktf-cli get - - - run: make test - - uses: hashicorp/terraform-cdk-action@v5 with: cdktfVersion: 0.20.9 diff --git a/.goreleaser.yml b/.goreleaser.yml index fd029a6..7ed09b3 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -7,7 +7,6 @@ env: before: hooks: - go mod tidy - - go mod vendor - go mod download builds: diff --git a/Makefile b/Makefile index c276012..081855a 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,21 @@ .DEFAULT_GOAL := build +PWD := $(shell pwd) + GO ?= go GO_RUN_TOOLS ?= $(GO) run -modfile ./tools/go.mod GO_TEST ?= $(GO_RUN_TOOLS) gotest.tools/gotestsum --format pkgname GO_RELEASER ?= $(GO_RUN_TOOLS) github.com/goreleaser/goreleaser GO_MOD ?= $(shell ${GO} list -m) -.PHONY: build -build: ## Build the Terraform - $(GO_RELEASER) build --snapshot --clean - .PHONY: release release: ## Release the Terraform provider $(GO_RELEASER) release --rm-dist -.PHONY: out -out: ## Build the Terraform provider - $(GO) run main.go - +.PHONY: deploy +deploy: ## Deploy the Terraform provider + npx -y cdktf-cli deploy + .PHONY: generate generate: ## Generate code. $(GO) generate ./... diff --git a/README.md b/README.md index d296b5f..9f04c8b 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ -# template-cdktf \ No newline at end of file +# CDKTF Template with Go + +This is a template for a CDKTF project with Go. + +## Get Started + +```bash +make deploy +``` + +## Help + +```bash +make help +``` \ No newline at end of file diff --git a/cdktf.json b/cdktf.json new file mode 100644 index 0000000..e08dfac --- /dev/null +++ b/cdktf.json @@ -0,0 +1,9 @@ +{ + "language": "go", + "app": "go run main.go", + "codeMakerOutput": "generated", + "sendCrashReports": "false", + "terraformProviders": [], + "terraformModules": [], + "context": {} +} \ No newline at end of file diff --git a/main.go b/main.go index 9db55b9..cd75532 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,9 @@ import ( "github.com/hashicorp/terraform-cdk-go/cdktf" ) -type config struct{} +type config struct { + filename string +} func NewNoopStack(scope constructs.Construct, id string, cfg *config) cdktf.TerraformStack { stack := cdktf.NewTerraformStack(scope, jsii.String(id)) @@ -17,7 +19,7 @@ func NewNoopStack(scope constructs.Construct, id string, cfg *config) cdktf.Terr file := file.NewFile(stack, jsii.String("file"), &file.FileConfig{ Content: jsii.String("Hello, World!"), - Filename: jsii.String("hello.txt"), + Filename: jsii.String(cfg.filename), }) cdktf.NewTerraformOutput(stack, jsii.String("filename"), &cdktf.TerraformOutputConfig{ @@ -30,5 +32,9 @@ func NewNoopStack(scope constructs.Construct, id string, cfg *config) cdktf.Terr func main() { app := cdktf.NewApp(nil) + NewNoopStack(app, "stack", &config{ + filename: "hello.txt", + }) + app.Synth() }