diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..1caf3c9 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,14 @@ +# Terraform files +*.tfstate +*.tfstate.* +*.tfvars +!*.tfvars.example +.terraform/ +.terraform.lock.hcl +crash.log +override.tf +override.tf.json +*_override.tf +*_override.tf.json +.terraformrc +terraform.rc diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..14343ab --- /dev/null +++ b/examples/README.md @@ -0,0 +1,195 @@ +# Terraform Provider Edge Connect Examples + +This directory contains example Terraform configurations demonstrating the usage of the Edge Connect Terraform provider. + +## Available Examples + +### 1. Basic Example (`basic/`) + +The simplest example showing how to create a single application. + +**Features:** +- Provider configuration +- Creating a basic app resource +- Output values + +**Usage:** +```bash +cd basic +cp terraform.tfvars.example terraform.tfvars +# Edit terraform.tfvars with your credentials +terraform init +terraform plan +terraform apply +``` + +### 2. Complete Example (`complete/`) + +A comprehensive example demonstrating multiple resources and realistic scenarios. + +**Features:** +- Creating multiple applications +- Creating multiple app instances +- Configuring app instances with JSON config +- Deploying instances across different regions +- Multiple output values + +**Usage:** +```bash +cd complete +cp terraform.tfvars.example terraform.tfvars +# Edit terraform.tfvars with your credentials +terraform init +terraform plan +terraform apply +``` + +### 3. Data Sources Example (`data-sources/`) + +Demonstrates using data sources to look up existing resources and use them in configurations. + +**Features:** +- Using `edge-connect_app` data source +- Using `edge-connect_app_instance` data source +- Creating new resources based on existing data +- Referencing data source attributes + +**Usage:** +```bash +cd data-sources +cp terraform.tfvars.example terraform.tfvars +# Edit terraform.tfvars with your credentials and existing resource IDs +terraform init +terraform plan +terraform apply +``` + +## Provider Configuration + +All examples require the following provider configuration: + +```hcl +provider "edge-connect" { + endpoint = "https://api.edge-connect.example.com" + token = var.edge_connect_token +} +``` + +### Configuration Options + +- `endpoint` (required): The Edge Connect API endpoint URL +- `token` (required, sensitive): Authentication token for the Edge Connect API + +## Resources + +### edge-connect_app + +Manages an Edge Connect application. + +**Arguments:** +- `name` (required): Application name +- `version` (optional): Application version +- `description` (optional): Application description + +**Attributes:** +- `id`: Application identifier +- `status`: Application status + +**Example:** +```hcl +resource "edge-connect_app" "example" { + name = "my-app" + version = "1.0.0" + description = "My application" +} +``` + +### edge-connect_app_instance + +Manages an Edge Connect application instance. + +**Arguments:** +- `name` (required): Instance name +- `app_id` (required): Associated application ID +- `description` (optional): Instance description +- `config` (optional): Instance configuration (JSON string) + +**Attributes:** +- `id`: Instance identifier +- `status`: Instance status + +**Example:** +```hcl +resource "edge-connect_app_instance" "example" { + name = "my-app-instance" + app_id = edge-connect_app.example.id + config = jsonencode({ + environment = "production" + replicas = 3 + }) +} +``` + +## Data Sources + +### edge-connect_app + +Retrieves information about an existing application. + +**Arguments:** +- `id` (required): Application identifier + +**Attributes:** +- `name`: Application name +- `version`: Application version +- `description`: Application description +- `status`: Application status + +### edge-connect_app_instance + +Retrieves information about an existing application instance. + +**Arguments:** +- `id` (required): Instance identifier + +**Attributes:** +- `name`: Instance name +- `app_id`: Associated application ID +- `description`: Instance description +- `config`: Instance configuration +- `status`: Instance status + +## Prerequisites + +1. Terraform >= 1.0 +2. Valid Edge Connect API credentials +3. Access to an Edge Connect API endpoint + +## Getting Started + +1. Choose an example that fits your use case +2. Navigate to the example directory +3. Copy `terraform.tfvars.example` to `terraform.tfvars` +4. Edit `terraform.tfvars` with your actual credentials +5. Run `terraform init` to initialize the provider +6. Run `terraform plan` to see what will be created +7. Run `terraform apply` to create the resources + +## Cleanup + +To destroy the resources created by these examples: + +```bash +terraform destroy +``` + +## Notes + +- Keep your `terraform.tfvars` file secure as it contains sensitive credentials +- The `terraform.tfvars` file is gitignored by default +- Always review the plan output before applying changes +- Some resources may take time to provision + +## Support + +For issues or questions about the provider, please refer to the main provider documentation. diff --git a/examples/basic/main.tf b/examples/basic/main.tf new file mode 100644 index 0000000..52e85ee --- /dev/null +++ b/examples/basic/main.tf @@ -0,0 +1,29 @@ +terraform { + required_providers { + edge-connect = { + source = "local/edge-connect" + } + } +} + +provider "edge-connect" { + endpoint = "https://api.edge-connect.example.com" + token = var.edge_connect_token +} + +# Create a simple app +resource "edge-connect_app" "example" { + name = "my-app" + version = "1.0.0" + description = "Example application" +} + +output "app_id" { + description = "The ID of the created app" + value = edge-connect_app.example.id +} + +output "app_status" { + description = "The status of the created app" + value = edge-connect_app.example.status +} diff --git a/examples/basic/terraform.tfvars.example b/examples/basic/terraform.tfvars.example new file mode 100644 index 0000000..e0045a9 --- /dev/null +++ b/examples/basic/terraform.tfvars.example @@ -0,0 +1,2 @@ +# Copy this file to terraform.tfvars and fill in your values +edge_connect_token = "your-api-token-here" diff --git a/examples/basic/variables.tf b/examples/basic/variables.tf new file mode 100644 index 0000000..60a44e6 --- /dev/null +++ b/examples/basic/variables.tf @@ -0,0 +1,5 @@ +variable "edge_connect_token" { + description = "Authentication token for Edge Connect API" + type = string + sensitive = true +} diff --git a/examples/complete/main.tf b/examples/complete/main.tf new file mode 100644 index 0000000..0429de9 --- /dev/null +++ b/examples/complete/main.tf @@ -0,0 +1,92 @@ +terraform { + required_providers { + edge-connect = { + source = "local/edge-connect" + } + } +} + +provider "edge-connect" { + endpoint = var.edge_connect_endpoint + token = var.edge_connect_token +} + +# Create an application +resource "edge-connect_app" "web_app" { + name = "web-application" + version = "2.1.0" + description = "Production web application" +} + +# Create an app instance for the application +resource "edge-connect_app_instance" "web_app_instance" { + name = "web-app-prod-instance" + app_id = edge-connect_app.web_app.id + description = "Production instance of web application" + config = jsonencode({ + environment = "production" + replicas = 3 + resources = { + cpu = "2" + memory = "4Gi" + } + }) +} + +# Create another app with a different version +resource "edge-connect_app" "api_app" { + name = "api-service" + version = "1.5.0" +} + +# Create multiple instances of the API app +resource "edge-connect_app_instance" "api_instance_east" { + name = "api-service-east" + app_id = edge-connect_app.api_app.id + config = jsonencode({ + region = "us-east-1" + }) +} + +resource "edge-connect_app_instance" "api_instance_west" { + name = "api-service-west" + app_id = edge-connect_app.api_app.id + config = jsonencode({ + region = "us-west-2" + }) +} + +# Outputs +output "web_app_id" { + description = "ID of the web application" + value = edge-connect_app.web_app.id +} + +output "web_app_status" { + description = "Status of the web application" + value = edge-connect_app.web_app.status +} + +output "web_app_instance_id" { + description = "ID of the web app instance" + value = edge-connect_app_instance.web_app_instance.id +} + +output "web_app_instance_status" { + description = "Status of the web app instance" + value = edge-connect_app_instance.web_app_instance.status +} + +output "api_instances" { + description = "API service instances" + value = { + east = { + id = edge-connect_app_instance.api_instance_east.id + status = edge-connect_app_instance.api_instance_east.status + } + west = { + id = edge-connect_app_instance.api_instance_west.id + status = edge-connect_app_instance.api_instance_west.status + } + } +} diff --git a/examples/complete/terraform.tfvars.example b/examples/complete/terraform.tfvars.example new file mode 100644 index 0000000..8910caf --- /dev/null +++ b/examples/complete/terraform.tfvars.example @@ -0,0 +1,3 @@ +# Copy this file to terraform.tfvars and fill in your values +edge_connect_endpoint = "https://api.edge-connect.example.com" +edge_connect_token = "your-api-token-here" diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf new file mode 100644 index 0000000..c705711 --- /dev/null +++ b/examples/complete/variables.tf @@ -0,0 +1,11 @@ +variable "edge_connect_endpoint" { + description = "Edge Connect API endpoint URL" + type = string + default = "https://api.edge-connect.example.com" +} + +variable "edge_connect_token" { + description = "Authentication token for Edge Connect API" + type = string + sensitive = true +} diff --git a/examples/data-sources/main.tf b/examples/data-sources/main.tf new file mode 100644 index 0000000..02530cd --- /dev/null +++ b/examples/data-sources/main.tf @@ -0,0 +1,57 @@ +terraform { + required_providers { + edge-connect = { + source = "local/edge-connect" + } + } +} + +provider "edge-connect" { + endpoint = var.edge_connect_endpoint + token = var.edge_connect_token +} + +# Data source: Look up an existing app by ID +data "edge-connect_app" "existing_app" { + id = var.app_id +} + +# Data source: Look up an existing app instance by ID +data "edge-connect_app_instance" "existing_instance" { + id = var.app_instance_id +} + +# You can use data from data sources to create new resources +resource "edge-connect_app_instance" "new_instance" { + name = "new-instance-based-on-existing" + app_id = data.edge-connect_app.existing_app.name + description = "New instance created based on existing app: ${data.edge-connect_app.existing_app.name}" +} + +# Outputs showing data source information +output "existing_app_info" { + description = "Information about the existing app" + value = { + id = data.edge-connect_app.existing_app.id + name = data.edge-connect_app.existing_app.name + version = data.edge-connect_app.existing_app.version + description = data.edge-connect_app.existing_app.description + status = data.edge-connect_app.existing_app.status + } +} + +output "existing_instance_info" { + description = "Information about the existing app instance" + value = { + id = data.edge-connect_app_instance.existing_instance.id + name = data.edge-connect_app_instance.existing_instance.name + app_id = data.edge-connect_app_instance.existing_instance.app_id + description = data.edge-connect_app_instance.existing_instance.description + status = data.edge-connect_app_instance.existing_instance.status + } +} + +output "new_instance_id" { + description = "ID of the newly created instance" + value = edge-connect_app_instance.new_instance.id +} diff --git a/examples/data-sources/terraform.tfvars.example b/examples/data-sources/terraform.tfvars.example new file mode 100644 index 0000000..96229f6 --- /dev/null +++ b/examples/data-sources/terraform.tfvars.example @@ -0,0 +1,5 @@ +# Copy this file to terraform.tfvars and fill in your values +edge_connect_endpoint = "https://api.edge-connect.example.com" +edge_connect_token = "your-api-token-here" +app_id = "my-existing-app" +app_instance_id = "my-existing-instance" diff --git a/examples/data-sources/variables.tf b/examples/data-sources/variables.tf new file mode 100644 index 0000000..e45c7a1 --- /dev/null +++ b/examples/data-sources/variables.tf @@ -0,0 +1,21 @@ +variable "edge_connect_endpoint" { + description = "Edge Connect API endpoint URL" + type = string + default = "https://api.edge-connect.example.com" +} + +variable "edge_connect_token" { + description = "Authentication token for Edge Connect API" + type = string + sensitive = true +} + +variable "app_id" { + description = "ID of an existing app to look up" + type = string +} + +variable "app_instance_id" { + description = "ID of an existing app instance to look up" + type = string +}