added examples

This commit is contained in:
Manuel Ganter 2025-11-11 15:32:09 +01:00
parent 67b9b2ea29
commit ea2f69060a
No known key found for this signature in database
11 changed files with 434 additions and 0 deletions

14
examples/.gitignore vendored Normal file
View file

@ -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

195
examples/README.md Normal file
View file

@ -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.

29
examples/basic/main.tf Normal file
View file

@ -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
}

View file

@ -0,0 +1,2 @@
# Copy this file to terraform.tfvars and fill in your values
edge_connect_token = "your-api-token-here"

View file

@ -0,0 +1,5 @@
variable "edge_connect_token" {
description = "Authentication token for Edge Connect API"
type = string
sensitive = true
}

92
examples/complete/main.tf Normal file
View file

@ -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
}
}
}

View file

@ -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"

View file

@ -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
}

View file

@ -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
}

View file

@ -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"

View file

@ -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
}