An open API service indexing awesome lists of open source software.

https://github.com/gilbertrios/terraform-provider-utils

Terraform function-only provider with utilities for string manipulation, encoding, hashing, and data transformation. Perfect for resource naming and data processing.
https://github.com/gilbertrios/terraform-provider-utils

data-transformation hashicorp string-manipulation terraform-functions terraform-plugin utility-functions

Last synced: 3 months ago
JSON representation

Terraform function-only provider with utilities for string manipulation, encoding, hashing, and data transformation. Perfect for resource naming and data processing.

Awesome Lists containing this project

README

          

# Terraform Provider Utils

[![Go Version](https://img.shields.io/github/go-mod/go-version/gilbertrios/terraform-provider-utils)](https://golang.org)
[![License](https://img.shields.io/github/license/gilbertrios/terraform-provider-utils)](LICENSE)

A function-only Terraform provider that provides utility functions for data manipulation and transformation in your Terraform configurations.

## ๐ŸŽฏ Key Features

- **Encoding & Hashing** - Base64 encoding/decoding, SHA256, MD5 hashing
- **Deterministic ID Generation** - UUID v4 generation from seed values
- **String Manipulation** - Slugify, truncate, reverse, trim, case conversion
- **List Operations** - Join and split operations for list handling
- **Zero Configuration** - No provider configuration required
- **Lightweight** - Pure function provider with no external dependencies
- **Type-Safe** - Strong typing with proper error handling

## ๐ŸŒŸ What This Repo Demonstrates

### Terraform Best Practices
- โœ… Function-only provider implementation
- โœ… Terraform Plugin Framework usage
- โœ… Type-safe function definitions
- โœ… Comprehensive testing strategy

### Development Best Practices
- โœ… Clean, modular Go code
- โœ… Extensive unit test coverage
- โœ… CI/CD automation with GitHub Actions
- โœ… Cross-platform build support

### Documentation
- โœ… Comprehensive function reference
- โœ… Real-world usage examples
- โœ… Developer-friendly guides

## ๐Ÿ› ๏ธ Tech Stack

**Application**
- Go 1.21+ - Modern Go with generics support
- Terraform Plugin Framework - Official provider framework
- Terraform 1.8+ - Provider-defined functions support

**DevOps**
- GitHub Actions - CI/CD automation
- Makefile - Build automation
- golangci-lint - Code quality checks

## ๐Ÿ“‹ Available Functions

| Category | Functions |
|----------|-----------|
| **Encoding & Hashing** | `base64_encode`, `base64_decode`, `sha256`, `md5` |
| **ID Generation** | `uuidv4` |
| **String Manipulation** | `slugify`, `truncate`, `reverse`, `trim`, `to_upper`, `to_lower` |
| **List Operations** | `join`, `split` |

See [Function Reference](docs/functions.md) for complete documentation.

## ๐Ÿ’ป Quick Start

### Installation

```bash
git clone https://github.com/gilbertrios/terraform-provider-utils.git
cd terraform-provider-utils
make install
```

See [Installation Guide](docs/installation.md) for manual installation and platform-specific instructions.

### Basic Usage

Add the provider to your Terraform configuration:

```hcl
terraform {
required_providers {
utils = {
source = "gilbertrios/utils"
}
}
}

provider "utils" {}
```

### Example: Resource Naming

```hcl
locals {
environment = "production"
application = "web-app"

# Generate URL-friendly resource name
resource_name = provider::utils::slugify("${local.application} ${local.environment}")
# Result: "web-app-production"

# Create deterministic UUID
resource_id = provider::utils::uuidv4(local.resource_name)
# Result: "a1b2c3d4-e5f6-4789-a012-b3c4d5e6f7a8"
}
```

### Example: Data Transformation

```hcl
locals {
# Parse CSV data
ip_ranges = "10.0.1.0/24,10.0.2.0/24,10.0.3.0/24"
ip_list = provider::utils::split(local.ip_ranges, ",")

# Join tags
tags = ["production", "web", "critical"]
tag_string = provider::utils::join(local.tags, "-")
# Result: "production-web-critical"
}
```

### Example: Content Hashing

```hcl
locals {
config_content = jsonencode({
version = "1.0"
features = ["auth", "api"]
})

# Generate content hash for cache busting
config_hash = provider::utils::sha256(local.config_content)
}
```

## ๐Ÿ—๏ธ Repository Structure

```
terraform-provider-utils/
โ”œโ”€โ”€ main.go # Provider entry point
โ”œโ”€โ”€ go.mod # Go module definition
โ”œโ”€โ”€ Makefile # Build automation
โ”œโ”€โ”€ README.md # This file
โ”œโ”€โ”€ LICENSE # MIT License
โ”œโ”€โ”€ CHANGELOG.md # Version history
โ”‚
โ”œโ”€โ”€ internal/
โ”‚ โ””โ”€โ”€ provider/
โ”‚ โ”œโ”€โ”€ provider.go # Provider definition
โ”‚ โ”œโ”€โ”€ provider_test.go # Provider tests
โ”‚ โ”œโ”€โ”€ functions.go # Function implementations
โ”‚ โ””โ”€โ”€ functions_test.go # Function tests
โ”‚
โ”œโ”€โ”€ examples/ # Example configurations
โ”‚ โ”œโ”€โ”€ basic/ # Basic usage examples
โ”‚ โ””โ”€โ”€ advanced/ # Real-world use cases
โ”‚
โ””โ”€โ”€ docs/ # Documentation
โ”œโ”€โ”€ installation.md # Installation guide
โ”œโ”€โ”€ quickstart.md # Quick start guide
โ”œโ”€โ”€ functions.md # Function reference
โ”œโ”€โ”€ usage.md # Usage patterns
โ”œโ”€โ”€ development.md # Development guide
โ””โ”€โ”€ contributing.md # Contributing guidelines
```

## ๐Ÿ“š Documentation

### Getting Started
- [Installation Guide](docs/installation.md) - Install the provider
- [Quick Start Guide](docs/quickstart.md) - Get up and running quickly
- [Usage Guide](docs/usage.md) - Common patterns and best practices

### Reference
- [Function Reference](docs/functions.md) - Complete API documentation
- [Examples](examples/) - Working example configurations

### Development
- [Development Guide](docs/development.md) - Build and test the provider
- [Contributing Guidelines](docs/contributing.md) - How to contribute

## ๐Ÿงช Testing

Run the test suite:

```bash
# Run all tests
make test

# Run with coverage
make test-coverage

# Run specific test
go test ./internal/provider -run TestBase64Encode
```

See [Development Guide](docs/development.md) for detailed testing documentation.

## ๐Ÿš€ CI/CD Pipeline

Automated workflow for:
- โœ… Running tests on multiple Go versions
- โœ… Linting and formatting checks
- โœ… Building binaries for multiple platforms
- โœ… Release automation ready

## ๐Ÿ’ก Use Cases

### Consistent Resource Naming
Generate deterministic, URL-friendly names across environments:
```hcl
resource_name = provider::utils::slugify("${var.app_name} ${var.environment}")
```

### Content Hashing
Create cache keys and version identifiers:
```hcl
version_id = provider::utils::sha256(local.config_content)
```

### Data Processing
Transform external data sources (CSV, JSON) for Terraform:
```hcl
ip_list = provider::utils::split(data.http.allowed_ips.body, ",")
```

### Length Constraints
Handle cloud provider name length restrictions:
```hcl
bucket_name = provider::utils::truncate(local.full_name, 63, "")
```

See [Usage Guide](docs/usage.md) for more examples and patterns.

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-function`)
3. Commit your changes (`git commit -m 'Add some amazing function'`)
4. Push to the branch (`git push origin feature/amazing-function`)
5. Open a Pull Request

See [Contributing Guidelines](docs/contributing.md) for detailed instructions.

### ๐ŸŒ Connect With Me
Interested in Infrastructure as Code, Azure, or DevOps? Let's connect!

- ๐Ÿ’ผ LinkedIn: [Connect with me](https://linkedin.com/in/gilbert-rios-22586918)
- ๐Ÿ“ง Email: [gilbertrios@hotmail.com](mailto:gilbertrios@hotmail.com)
- ๐Ÿ’ก GitHub: [@gilbertrios](https://github.com/gilbertrios)

## ๐ŸŽ“ Quick Links

- [Quick Start Guide](docs/quickstart.md) - Get started in 5 minutes
- [Function Reference](docs/functions.md) - Complete API documentation
- [Usage Guide](docs/usage.md) - Real-world patterns and examples
- [Examples Directory](examples/) - Working configurations

---

โญ If you find this project useful, please consider giving it a star!