https://github.com/priyanshujain/infrasync
InfraSync is a tool for converting existing cloud infrastructure to Terraform code and maintaining synchronization between Infrastructure-as-Code and actual cloud resources.
https://github.com/priyanshujain/infrasync
aws google-cloud-platform infragpt infrastructure-as-code terraform wip
Last synced: about 1 year ago
JSON representation
InfraSync is a tool for converting existing cloud infrastructure to Terraform code and maintaining synchronization between Infrastructure-as-Code and actual cloud resources.
- Host: GitHub
- URL: https://github.com/priyanshujain/infrasync
- Owner: priyanshujain
- Created: 2025-03-25T14:47:57.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-11T08:40:07.000Z (about 1 year ago)
- Last Synced: 2025-05-11T09:27:51.982Z (about 1 year ago)
- Topics: aws, google-cloud-platform, infragpt, infrastructure-as-code, terraform, wip
- Language: Go
- Homepage:
- Size: 3.04 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# InfraSync
InfraSync is a tool for converting existing cloud infrastructure to Terraform code and maintaining synchronization between Infrastructure-as-Code and actual cloud resources.
## Features
- Initialize new IaC repositories
- Import existing GCP resources
- Generate Terraform import blocks and resource definitions
- Detect drift between cloud state and Terraform state
- Create PRs with changes when drift is detected
## Structure Approach
- Separated imports and resources into different directories:
```
project/
├── resources/
│ └── [provider]/
│ └── [project]/
│ └── [service]/
│ └── resource.tf
├── main.tf
├── variables.tf
├── providers.tf
└── outputs.tf
```
## Supported Providers
- Google Cloud Platform (GCP)
- PubSub (Topics, Subscriptions, IAM bindings)
- CloudSQL (Instances, Databases, Users)
- Storage (Buckets, IAM bindings)
- More services coming soon!
## Usage
### As a CLI Tool
#### Initialize a new IaC repository
```bash
infrasync init
```
This creates a new repository with:
- Basic Terraform configuration
- GCS backend configuration
- GitHub Actions workflow for drift detection
- Git repository initialization (optional)
#### Import existing resources
```bash
infrasync import
```
This discovers existing resources and generates:
- Import blocks for Terraform
- Directory structure for resources
- Provider configurations
### As a Go Package
InfraSync can also be used as a Go package in your own applications:
```go
import (
"context"
"log"
"github.com/priyanshujain/infrasync/internal/config"
"github.com/priyanshujain/infrasync/pkg/infrasync"
)
func main() {
// Load configuration
cfg, err := config.Load()
if err != nil {
log.Fatalf("Error loading config: %v", err)
}
// Create a new client
client := infrasync.NewClient(cfg)
// Initialize a project
ctx := context.Background()
if err := client.Initialize(ctx); err != nil {
log.Fatalf("Error initializing project: %v", err)
}
// Import all configured resources
if err := client.Import(ctx); err != nil {
log.Fatalf("Error importing resources: %v", err)
}
// Or import specific services
if err := client.ImportPubSub(ctx); err != nil {
log.Fatalf("Error importing PubSub resources: %v", err)
}
// Import a specific resource
// Note: Currently imports all resources of the specified service
// Future updates will support importing individual resources
if err := client.ImportSingleResource(ctx, "storage", "google_storage_bucket", "my-bucket"); err != nil {
log.Fatalf("Error importing specific bucket: %v", err)
}
}
```
See the `examples/` directory for more detailed usage examples.
## GitHub Actions Integration
InfraSync includes GitHub Actions workflow templates for:
- Automated drift detection
- PR creation when changes are detected
- Seamless integration with existing CI/CD pipelines
## Development
```bash
# Build
make build
# Install
go install
# Test
make test
# Run locally
make run
```
## Roadmap
1. Support for additional GCP services
2. Support for other cloud providers (AWS, Azure)
3. Comprehensive drift detection and reconciliation
4. Enhanced resource templating and customization