Skip to content

Commit

Permalink
Add example terraform code
Browse files Browse the repository at this point in the history
Add some example code as a reference. Additionally, add
a `make demo` target that uses the simulator to run the
example code.
  • Loading branch information
stuart-mclaren-hpe committed Sep 12, 2024
1 parent 3c11a52 commit 79b6746
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Hewlett Packard Enterprise Development LP
name: Demo

on:
push:
branches:
- main
pull_request:
jobs:
demo:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.22.3'
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.5
# set wrapper to false, otherwise any time
# terraform is run the first line of stdout is
# the path to the terraform binary. This causes
# eg the output of "terraform providers schema -json"
# be unusable
terraform_wrapper: false
- run: make demo
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ testacc-simulation:
env TF_ACC=1 env TF_CLI_CONFIG_FILE=$$tfconfig \
go test -v -tags simulation ./test/...

demo:
go install -tags experimental,simulation ./cmd/...
tfconfig=$$(mktemp); \
sed "s@__HOME__@${HOME}@g" test/.terraformrc > $$tfconfig; \
env TF_LOG=INFO env TF_CLI_CONFIG_FILE=$$tfconfig \
terraform -chdir=examples apply -auto-approve

lint:
@golangci-lint --version
# Will use .golangci.yml
Expand Down
32 changes: 32 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#(C) Copyright 2024 Hewlett Packard Enterprise Development LP

data "hpegl_pc_system" "my_system" {
name = "array-5305-grp"
}

resource "hpegl_pc_datastore" "my_datastore" {
name = "mclaren-ds19"
datastore_type = "VMFS"
capacity_in_bytes = 17179869184
hci_cluster_uuid = data.hpegl_pc_system.my_system.id
cluster_info = {
"name": "5305-CL"
}
}

resource "hpegl_pc_hypervisor_cluster" "my_hypervisor_cluster" {
name = "mclaren01"
hci_cluster_uuid = data.hpegl_pc_system.my_system.id
app_info = {
vmware = {
datacenter_info = {
name = "5305-DC"
}
}
}
}

resource "hpegl_pc_server" "my_server" {
name = "16.182.105.217"
system_id = data.hpegl_pc_system.my_system.id
}
21 changes: 21 additions & 0 deletions examples/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#(C) Copyright 2024 Hewlett Packard Enterprise Development LP

terraform {
required_providers {
hpegl = {
source = "github.com/HewlettPackard/hpegl-pcbe-terraform-resources"
}
}
}

provider "hpegl" {
pc {
host = "http://localhost:8080"
token = "abcdefghijklmnopqrstuvwxyz-0123456789"

http_dump = true
# poll_interval in seconds
poll_interval = 10.0
max_polls = 10
}
}

0 comments on commit 79b6746

Please sign in to comment.