Oscar Hermoso 58f67c1ce7 Initial commit
2024-08-12 16:32:04 +08:00
2024-08-12 16:32:04 +08:00

binary-lane-terraform-provider

Following the example from the terraform docs

https://developer.hashicorp.com/terraform/plugin/code-generation/workflow-example

Initial setup

mkdir terraform-provider-binarylane
cd terraform-provider-binarylane
go mod init terraform-provider-binarylane
touch main.go
touch provider.go
  1. Run go genereate to generate the OpenAPI spec in internal/binarylane/openapi.yml
  2. Make any changes to provider_gen_config.yml (see https://developer.hashicorp.com/terraform/plugin/code-generation/openapi-generator#generator-config)
  3. Generate JSON spec for provider code
go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest

tfplugingen-openapi generate \
  --config ./provider_gen_config.yml \
  ./openapi.yml \
  --output ./provider_code_spec.json
  1. Generate code for provider, resources and data sources
go install github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework@latest

tfplugingen-framework generate all \
    --input provider_code_spec.json \
    --force \
    --output internal
  1. Scaffold provider, resources and data sources
mkdir -p internal/provider

tfplugingen-framework scaffold provider \
  --name binarylane \
  --output-dir ./internal/provider
tfplugingen-framework scaffold data-source \
    --name REPLACE_ME \
    --output-dir ./internal/provider
tfplugingen-framework scaffold data-source \
    --name REPLACE_ME \
    --output-dir ./internal/provider
  1. Add this to your ~/.terraformrc (your home directory!)
provider_installation {

  dev_overrides {
    # Example GOBIN path, will need to be replaced with your own GOBIN path. Default is $GOPATH/bin
    "hashicorp.com/edu/binarylane" = "/home/oscarhermoso/Git/terraform-provider-binarylane/bin"
  }

  # For all other providers, install them directly from their origin provider
  # registries as normal. If you omit this, Terraform will _only_ use
  # the dev_overrides block, and so no other providers will be available.
  direct {}
}

Notes

Getting a list of images

curl -X GET "https://api.binarylane.com.au/v2/images?type=distribution&&page=1&per_page=200" \
  -H "Authorization: Bearer **********" > images.json

jq '[ .images[] | .slug ] | sort' images.json

Getting a list of regions

curl -X GET "https://api.binarylane.com.au/v2/regions" \
  -H "Authorization: Bearer **********"" > regions.json

jq '[ .regions[] | .slug ] | sort' regions.json

[
  "bne",
  "mel",
  "per",
  "sin",
  "syd"
]

Getting a list of sizes

curl -X GET "https://api.binarylane.com.au/v2/sizes" \
  -H "Authorization: Bearer **********"" > sizes.json

jq '[ .sizes[] | .slug ] | sort' sizes.json

[
  "cpu-2thr",
  "cpu-4thr",
  "cpu-6thr",
  "cpu-8thr",
  "ded-3900x-1600gb",
  "ded-e2136-400gb",
  "ded-e2136-800gb",
  "ded-e2288g-400gb",
  "ded-e2288g-800gb",
  "hdd-1000gb",
  "hdd-2000gb",
  "hdd-500gb",
  "std-1vcpu",
  "std-2vcpu",
  "std-4vcpu",
  "std-6vcpu",
  "std-8vcpu",
  "std-min"
]
S
Description
Pull mirror of github.com/oscarhermoso/terraform-provider-binarylane, the Terraform provider for BinaryLane
Readme MIT 1.3 MiB
Languages
Go 92%
Shell 8%