Skip to content

Commit 2d4b3b8

Browse files
feat: go releaser (#214)
* fix(readme): update readme * feat(tf-migrate): go releaser * refactor(readme): update section and add supported resources * fix: use tag instead
1 parent 0d1120e commit 2d4b3b8

6 files changed

Lines changed: 177 additions & 49 deletions

File tree

.github/workflows/release.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version-file: go.mod
24+
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v6
27+
with:
28+
version: "~> v2"
29+
args: release --clean
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bin/
2+
dist/
23
.terraformrc-tf-migrate
34

45
# Binaries (should be in bin/ directory only)

.goreleaser.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
version: 2
2+
3+
project_name: tf-migrate
4+
5+
builds:
6+
- id: tf-migrate
7+
main: ./cmd/tf-migrate
8+
binary: tf-migrate
9+
env:
10+
- CGO_ENABLED=0
11+
ldflags:
12+
- -s -w -X main.version={{.Tag}}
13+
goos:
14+
- linux
15+
- darwin
16+
- windows
17+
- freebsd
18+
goarch:
19+
- amd64
20+
- arm64
21+
22+
archives:
23+
- id: tf-migrate
24+
ids:
25+
- tf-migrate
26+
formats:
27+
- tar.gz
28+
format_overrides:
29+
- goos: windows
30+
formats:
31+
- zip
32+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
33+
34+
checksum:
35+
name_template: "checksums.txt"
36+
37+
changelog:
38+
sort: asc
39+
filters:
40+
exclude:
41+
- "^docs:"
42+
- "^test:"
43+
- "^ci:"
44+
groups:
45+
- title: Features
46+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
47+
order: 0
48+
- title: Bug Fixes
49+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
50+
order: 1
51+
- title: Others
52+
order: 999
53+
54+
release:
55+
github:
56+
owner: cloudflare
57+
name: tf-migrate
58+
prerelease: auto
59+
name_template: "{{.Tag}}"

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GO := go
66
MAIN_PACKAGE := ./cmd/tf-migrate
77
E2E_PACKAGE := ./cmd/e2e-runner
88

9-
.PHONY: all build build-e2e build-all test test-unit test-integration lint-testdata clean
9+
.PHONY: all build build-e2e build-all test test-unit test-integration lint-testdata clean release-snapshot
1010

1111
# Default target: build all binaries
1212
all: build-all
@@ -40,6 +40,10 @@ lint-testdata:
4040
@echo "Linting integration testdata for naming conventions..."
4141
@$(GO) run scripts/lint_testdata_names.go
4242

43+
# Test GoReleaser build locally (no publish)
44+
release-snapshot:
45+
goreleaser build --snapshot --clean
46+
4347
# Clean build artifacts
4448
clean:
4549
@echo "Cleaning build artifacts..."

README.md

Lines changed: 77 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,87 @@
11
# tf-migrate - Cloudflare Terraform Provider Migration Tool
22

3-
A powerful CLI tool for automatically migrating Terraform configurations and state files between different versions of the Cloudflare Terraform Provider.
3+
A powerful CLI tool for automatically migrating Terraform configurations between different versions of the Cloudflare Terraform Provider.
4+
5+
> **Disclaimer:** Please note that v1.0.0-beta.1 is in Beta and we are still testing it for stability.
6+
47

58
## Overview
69

710
`tf-migrate` helps you upgrade your Terraform infrastructure code by automatically transforming:
811
- **Configuration files** (`.tf`) - Updates resource types, attribute names, and block structures
9-
- **State files** (`terraform.tfstate`) - Migrates resource state to match new provider schemas
1012

11-
Currently supports migrations:
12-
- **v4 → v5**: Cloudflare Provider v4 to v5
13+
### Supported Migration Paths
14+
15+
| Source Version | Target Version |
16+
|----------------|----------------|
17+
| Cloudflare Provider v4.52.5 | Cloudflare Provider v5.19 |
18+
19+
### Supported Resources (v4 → v5)
20+
21+
<details>
22+
<summary>50 resources with complete config migration support (click to expand)</summary>
23+
24+
| Product | Resource | Type |
25+
|---------|----------|------|
26+
| **Zones** | `cloudflare_zone` | resource |
27+
| | `cloudflare_zone` | data |
28+
| | `cloudflare_zones` | data |
29+
| | `cloudflare_zone_setting` | resource |
30+
| | `cloudflare_zone_subscription` | resource |
31+
| **DNS** | `cloudflare_dns_record` | resource |
32+
| | `cloudflare_zone_dnssec` | resource |
33+
| **Load Balancers** | `cloudflare_load_balancer` | resource |
34+
| | `cloudflare_load_balancer_monitor` | resource |
35+
| | `cloudflare_load_balancer_pool` | resource |
36+
| **Rulesets** | `cloudflare_ruleset` | resource |
37+
| **Page Rules** | `cloudflare_page_rule` | resource |
38+
| **Managed Transforms** | `cloudflare_managed_transforms` | resource |
39+
| **URL Normalization** | `cloudflare_url_normalization_settings` | resource |
40+
| **Snippets** | `cloudflare_snippet` | resource |
41+
| | `cloudflare_snippet_rules` | resource |
42+
| **Workers** | `cloudflare_worker_script` | resource |
43+
| | `cloudflare_worker_route` | resource |
44+
| **KV** | `cloudflare_workers_kv` | resource |
45+
| | `cloudflare_workers_kv_namespace` | resource |
46+
| **Pages** | `cloudflare_pages_project` | resource |
47+
| **Cache** | `cloudflare_tiered_cache` | resource |
48+
| **Argo** | `cloudflare_argo_smart_routing` | resource |
49+
| | `cloudflare_argo_tiered_caching` | resource |
50+
| **Spectrum** | `cloudflare_spectrum_application` | resource |
51+
| **Addressing** | `cloudflare_regional_hostname` | resource |
52+
| **Bot Management** | `cloudflare_bot_management` | resource |
53+
| **Healthchecks** | `cloudflare_healthcheck` | resource |
54+
| **Custom Pages** | `cloudflare_custom_pages` | resource |
55+
| **Rules** | `cloudflare_list` | resource |
56+
| | `cloudflare_list_item` | resource |
57+
| **Logpush** | `cloudflare_logpush_job` | resource |
58+
| **Logs** | `cloudflare_logpull_retention` | resource |
59+
| **Alerting** | `cloudflare_notification_policy_webhooks` | resource |
60+
| **R2** | `cloudflare_r2_bucket` | resource |
61+
| **User** | `cloudflare_api_token` | resource |
62+
| **Zero Trust** | `cloudflare_zero_trust_access_application` | resource |
63+
| | `cloudflare_zero_trust_access_group` | resource |
64+
| | `cloudflare_zero_trust_access_identity_provider` | resource |
65+
| | `cloudflare_zero_trust_access_mtls_certificate` | resource |
66+
| | `cloudflare_zero_trust_access_mtls_hostname_settings` | resource |
67+
| | `cloudflare_zero_trust_access_policy` | resource |
68+
| | `cloudflare_zero_trust_access_service_token` | resource |
69+
| | `cloudflare_zero_trust_device_posture_rule` | resource |
70+
| | `cloudflare_zero_trust_dlp_custom_profile` | resource |
71+
| | `cloudflare_zero_trust_dlp_custom_entry` | resource |
72+
| | `cloudflare_zero_trust_dlp_predefined_entry` | resource |
73+
| | `cloudflare_zero_trust_dlp_integration_entry` | resource |
74+
| | `cloudflare_zero_trust_gateway_policy` | resource |
75+
| | `cloudflare_zero_trust_list` | resource |
76+
| | `cloudflare_zero_trust_tunnel_cloudflared_route` | resource |
77+
78+
</details>
1379

14-
## Documentation
80+
## Installation
1581

16-
For comprehensive documentation including architecture, testing, drift exemptions, and development guide, see **[CLAUDE.md](./CLAUDE.md)** - designed to give AI agents (and humans!) complete project context.
82+
### Pre-built Binaries
1783

18-
## Installation
84+
Download the latest release from the [GitHub Releases](https://github.com/cloudflare/tf-migrate/releases) page. Binaries are available for Linux, macOS, Windows, and FreeBSD on both amd64 and arm64.
1985

2086
### Building from Source
2187

@@ -27,7 +93,7 @@ cd tf-migrate
2793
# Build the binary
2894
make
2995

30-
# The binary will be available as ./tf-migrate
96+
# The binary will be available at ./bin/tf-migrate
3197
```
3298

3399
### Requirements
@@ -37,29 +103,6 @@ make
37103

38104
## Usage
39105

40-
### Authentication
41-
42-
Some resource migrations require access to the Cloudflare API to complete the migration successfully. The tool supports two authentication methods:
43-
44-
**Option 1: API Token (Recommended)**
45-
```bash
46-
export CLOUDFLARE_API_TOKEN="your-api-token"
47-
```
48-
49-
**Option 2: API Key + Email**
50-
```bash
51-
export CLOUDFLARE_API_KEY="your-api-key"
52-
export CLOUDFLARE_EMAIL="your-email@example.com"
53-
```
54-
55-
#### Resources Requiring Authentication
56-
57-
The following resources require API credentials for complete migration:
58-
59-
- `cloudflare_tunnel_route``cloudflare_zero_trust_tunnel_cloudflared_route`
60-
- **Why**: The v4 provider stored network CIDR as the resource ID, but v5 requires the UUID from the API. The migration queries the API to fetch the correct UUID for your tunnel routes.
61-
- **Without credentials**: The migration will still update resource types and attributes, but you'll need to run `terraform refresh` after migration to update the IDs.
62-
63106
### Basic Migration
64107

65108
Migrate all Terraform files in the current directory:
@@ -74,16 +117,6 @@ tf-migrate migrate --source-version v4 --target-version v5
74117
tf-migrate migrate --config-dir ./terraform --source-version v4 --target-version v5
75118
```
76119

77-
### Include State File Migration
78-
79-
```bash
80-
tf-migrate migrate \
81-
--config-dir ./terraform \
82-
--state-file terraform.tfstate \
83-
--source-version v4 \
84-
--target-version v5
85-
```
86-
87120
### Dry Run Mode
88121

89122
Preview changes without modifying files:
@@ -107,8 +140,6 @@ tf-migrate migrate \
107140
tf-migrate migrate \
108141
--config-dir ./terraform \
109142
--output-dir ./terraform-v5 \
110-
--state-file terraform.tfstate \
111-
--output-state terraform-v5.tfstate \
112143
--source-version v4 \
113144
--target-version v5
114145
```
@@ -120,7 +151,6 @@ tf-migrate migrate \
120151
| Flag | Description | Default |
121152
|------|-------------|---------|
122153
| `--config-dir` | Directory containing Terraform configuration files | Current directory |
123-
| `--state-file` | Path to Terraform state file | None |
124154
| `--source-version` | Source provider version (e.g., v4) | Required |
125155
| `--target-version` | Target provider version (e.g., v5) | Required |
126156
| `--resources` | Comma-separated list of resources to migrate | All resources |
@@ -132,7 +162,6 @@ tf-migrate migrate \
132162
| Flag | Description | Default |
133163
|------|-------------|---------|
134164
| `--output-dir` | Output directory for migrated configuration files | In-place |
135-
| `--output-state` | Output path for migrated state file | In-place |
136165
| `--backup` | Create backup of original files before migration | true |
137166

138167
### Development Tools
@@ -168,7 +197,7 @@ go test ./... -cover
168197

169198
#### Integration Tests
170199

171-
Integration tests verify the complete migration workflow using real configuration and state files.
200+
Integration tests verify the complete migration workflow using real configuration files.
172201

173202
```bash
174203
# Run all v4 to v5 integration tests
@@ -346,6 +375,7 @@ bin/ # Built binaries
346375

347376
**CI/CD:**
348377

349-
E2E tests run automatically in GitHub Actions on push to `main` or manual workflow dispatch. See `.github/workflows/e2e-tests.yml`.
378+
- **E2E tests** run automatically in GitHub Actions on push to `main` or manual workflow dispatch. See `.github/workflows/e2e-tests.yml`.
379+
- **Releases** are automated via GoReleaser. Pushing a `v*` tag triggers `.github/workflows/release.yml`, which cross-compiles binaries and creates a GitHub Release with archives and checksums.
350380

351381
**⚠️ Important:** E2E tests create and destroy real Cloudflare resources. Always use a dedicated test account, never production infrastructure.

cmd/tf-migrate/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
"github.com/cloudflare/tf-migrate/internal/transform"
2121
)
2222

23+
// version is set at build time via ldflags.
24+
var version = "dev"
25+
2326
type config struct {
2427
// Input paths
2528
configDir string
@@ -163,7 +166,7 @@ func newVersionCommand() *cobra.Command {
163166
Use: "version",
164167
Short: "Print version information",
165168
Run: func(cmd *cobra.Command, args []string) {
166-
fmt.Println("tf-migrate version 0.1.0")
169+
fmt.Printf("tf-migrate version %s\n", version)
167170
},
168171
}
169172
}

0 commit comments

Comments
 (0)