Skip to content

Commit

Permalink
fix: local testing
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Sep 27, 2024
1 parent 503c76f commit c39213e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 22 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,25 @@ jobs:
with:
go-version-file: ./go.mod
check-latest: true
- run: make lint
- 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 }}
18 changes: 9 additions & 9 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ env:
before:
hooks:
- go mod tidy
- go mod vendor
- go mod download

builds:
Expand Down
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ./...
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# template-cdktf
# CDKTF Template with Go

This is a template for a CDKTF project with Go.

## Get Started

```bash
make deploy
```

## Help

```bash
make help
```
9 changes: 9 additions & 0 deletions cdktf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"language": "go",
"app": "go run main.go",
"codeMakerOutput": "generated",
"sendCrashReports": "false",
"terraformProviders": [],
"terraformModules": [],
"context": {}
}
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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{
Expand All @@ -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()
}

0 comments on commit c39213e

Please sign in to comment.