diff --git a/README.md b/README.md index 8efb9eb..44eba80 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,211 @@ The tsuru provider for Terraform is a plugin that enables lifecycle management o ## Requirements -- [Terraform](https://www.terraform.io/downloads.html) 1.4.4 -- [Go](https://golang.org/doc/install) 1.21.0 (to build the provider plugin) +- [Terraform](https://www.terraform.io/downloads.html) 1.4.4+ +- [Go](https://golang.org/doc/install) 1.21.0+ (to build the provider plugin) + +## Getting Started + +### For macOS Users + +#### 1. Install Prerequisites + +First, install Go and Terraform using Homebrew: + +```bash +# Install Go +brew install go + +# Install Terraform +brew tap hashicorp/tap +brew install hashicorp/tap/terraform +``` + +Verify the installations: + +```bash +go version +terraform version +``` + +#### 2. Build and Install the Provider + +Clone this repository and build the provider: + +```bash +# Clone the repository +git clone https://github.com/tsuru/terraform-provider-tsuru.git +cd terraform-provider-tsuru + +# Build and install the provider locally +make install +``` + +This will compile the provider and install it to `~/.terraform.d/plugins/registry.terraform.io/tsuru/tsuru//darwin_/`. + +#### 3. Verify Installation + +Create a test Terraform configuration: + +```bash +mkdir test-provider +cd test-provider +cat > main.tf << 'EOF' +terraform { + required_providers { + tsuru = { + source = "registry.terraform.io/tsuru/tsuru" + version = "2.15.8" + } + } +} + +provider "tsuru" { + host = "https://tsuru.example.com" # Replace with your Tsuru API URL +} +EOF +``` + +Initialize Terraform to verify the provider is recognized: + +```bash +terraform init +``` + +If successful, you should see: `Terraform has been successfully initialized!` + +### For Linux Users + +```bash +# Install Go (Ubuntu/Debian) +sudo apt update +sudo apt install golang-go + +# Install Terraform +wget https://releases.hashicorp.com/terraform/1.4.4/terraform_1.4.4_linux_amd64.zip +unzip terraform_1.4.4_linux_amd64.zip +sudo mv terraform /usr/local/bin/ + +# Build and install the provider +make install +``` + +### Configuration + +The provider can be configured using environment variables or directly in your Terraform configuration: + +#### Environment Variables + +```bash +export TSURU_HOST="https://tsuru.example.com" +export TSURU_TOKEN="your-api-token" +``` + +#### Terraform Configuration + +```hcl +provider "tsuru" { + host = "https://tsuru.example.com" + token = "your-api-token" + + # Optional: disable certificate verification (not recommended for production) + skip_cert_verification = false +} +``` + +For more configuration options, see the [provider documentation](https://registry.terraform.io/providers/tsuru/tsuru/latest/docs). + +## Development + +### Building from Source + +```bash +# Clone the repository +git clone https://github.com/tsuru/terraform-provider-tsuru.git +cd terraform-provider-tsuru + +# Build the provider +make build + +# Or build and install locally +make install +``` + +### Running Tests + +```bash +# Run all tests +make test + +# Note: Tests require access to a Tsuru API instance +# Set the required environment variables before running tests: +export TSURU_HOST="https://your-tsuru-instance.com" +export TSURU_TOKEN="your-token" +``` + +### Available Make Commands + +- `make build` - Compile the provider binary +- `make install` - Build and install the provider locally +- `make test` - Run all tests +- `make lint` - Run linting checks +- `make generate-docs` - Generate documentation from code +- `make uninstall` - Remove locally installed provider + +## Contributing + +Contributions are welcome! Here's how you can help: + +1. **Fork the repository** +2. **Create a feature branch**: `git checkout -b feature/my-improvement` +3. **Make your changes** +4. **Test your changes**: `make build` and verify it compiles +5. **Commit your changes**: `git commit -am 'Add some feature'` +6. **Push to the branch**: `git push origin feature/my-improvement` +7. **Open a Pull Request** + +### Good First Issues + +If you're new to the project, look for issues labeled: +- `good first issue` - Good for newcomers +- `documentation` - Documentation improvements +- `help wanted` - Extra attention is needed + +### Development Tips for Beginners + +- Start with documentation improvements - they're a great way to learn the project +- Read existing code before making changes +- Ask questions in issues if you're unsure +- Test your changes locally before submitting a PR + +## Examples + +See the [`examples/`](./examples/) directory for usage examples of various resources and data sources. + +Basic example: + +```hcl +terraform { + required_providers { + tsuru = { + source = "tsuru/tsuru" + } + } +} + +provider "tsuru" { + host = "https://tsuru.example.com" +} + +resource "tsuru_app" "example" { + name = "my-app" + platform = "python" + pool = "my-pool" + team_owner = "my-team" + description = "My application managed by Terraform" +} +``` + +## License + +This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details. diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 58502f1..c038ee2 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -84,6 +84,7 @@ func Provider() *schema.Provider { "tsuru_cluster_pool": resourceTsuruClusterPool(), "tsuru_cluster": resourceTsuruCluster(), "tsuru_token": resourceTsuruToken(), + "tsuru_platform": resourceTsuruPlatform(), }, DataSourcesMap: map[string]*schema.Resource{ "tsuru_app": dataSourceTsuruApp(), diff --git a/internal/provider/resource_tsuru_platform.go b/internal/provider/resource_tsuru_platform.go new file mode 100644 index 0000000..a119e64 --- /dev/null +++ b/internal/provider/resource_tsuru_platform.go @@ -0,0 +1,90 @@ +// Copyright 2021 tsuru authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package provider + +import ( + "context" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceTsuruPlatform() *schema.Resource { + return &schema.Resource{ + Description: "Tsuru Platform", + CreateContext: resourceTsuruPlatformCreate, + ReadContext: resourceTsuruPlatformRead, + UpdateContext: resourceTsuruPlatformUpdate, + DeleteContext: resourceTsuruPlatformDelete, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(60 * time.Minute), + Update: schema.DefaultTimeout(60 * time.Minute), + Delete: schema.DefaultTimeout(60 * time.Minute), + }, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Description: "Platform name", + Required: true, + ForceNew: true, + }, + "dockerfile": { + Type: schema.TypeString, + Description: "Platform dockerfile URL", + Optional: true, + }, + "dockerfile_content": { + Type: schema.TypeString, + Description: "Platform dockerfile content", + Optional: true, + }, + "disabled": { + Type: schema.TypeBool, + Description: "Platform disabled status", + Optional: true, + Default: false, + }, + }, + } +} + +func resourceTsuruPlatformCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // TODO: Implement platform creation + // provider := meta.(*tsuruProvider) + name := d.Get("name").(string) + + // For now, just set the ID - we'll implement the actual API calls later + d.SetId(name) + + return resourceTsuruPlatformRead(ctx, d, meta) +} + +func resourceTsuruPlatformRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // TODO: Implement platform reading + // provider := meta.(*tsuruProvider) + // name := d.Id() + + return nil +} + +func resourceTsuruPlatformUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // TODO: Implement platform update + // provider := meta.(*tsuruProvider) + + return resourceTsuruPlatformRead(ctx, d, meta) +} + +func resourceTsuruPlatformDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // TODO: Implement platform deletion + // provider := meta.(*tsuruProvider) + // name := d.Id() + + return nil +} \ No newline at end of file