Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Sample repository implementing a terraform provider designed for managing resources in Azure and AWS

License

Notifications You must be signed in to change notification settings

MGTheTrain/terraform-provider-mgtt

Repository files navigation

terraform-provider-mgtt

Table of Contents

Description

Sample repository implementing a Terraform provider designed for managing resources in Azure and AWS.

References

Getting started

Precondition

  • Install the Docker engine
  • In VS Code install the Dev Containers extension in order to utilize dev containers
  • You can optionally install tools like go and terraform yourself instead of utilizing a dev container

(Optional) Check CLI tools serving as a basis for implementing resources

CLI tools can be found here:

Exporting environment variables

Create from the secrets.template.cfg a secrets.cfg file in the project root directory and replace the PLACEHOLDER_* values. Some tests need environment variables listed in the secrets.cfg file.

source secrets.cfg

In order to run tests

source secrets.cfg
# go test ./...
cd mgtt/test
go test

NOTE: For tests managing Azure objects refer to following README.md. Topics on how to retrieve a fresh AZURE_ACCESS_TOKEN should be covered.

Compile custom provider

On modern Windows OS (version 10 or 11) run:

go build -o terraform-provider-mgtt.exe

On Unix systems (MacOS, Linux Ubuntu >=20.04, debian >=11) run:

go build -o terraform-provider-mgtt

Copy provider executable to plugins directory

Refer to How to develop/ test existing provider locally?.

Navigate to and remove :

cd terraform

# Remove previous build artifacts
rm .terraform # Powershell
rm -rf .terraform # Unix terminals
rm  terraform.tfstate terraform.tfstate.backup

On modern Windows OS with amd64 CPU architecture run:

mkdir -p .terraform\plugins\terraform-mgtt.com\mgttprovider\mgtt\1.0.0\windows_amd64
cp ..\terraform-provider-mgtt.exe .terraform\plugins\terraform-mgtt.com\mgttprovider\mgtt\1.0.0\windows_amd64

On Unix systems run:

# Linux Ubuntu >=18.04 or debian >=11 with amd64 CPU architecture
mkdir -p .terraform/plugins/terraform-mgtt.com/mgttprovider/mgtt/1.0.0/linux_amd64
cp ../terraform-provider-mgtt .terraform/plugins/terraform-mgtt.com/mgttprovider/mgtt/1.0.0/linux_amd64

# MacOS with amd64 CPU architecture 
mkdir -p .terraform/plugins/terraform-mgtt.com/mgttprovider/mgtt/1.0.0/darwin_amd64
cp ../terraform-provider-mgtt .terraform/plugins/terraform-mgtt.com/mgttprovider/mgtt/1.0.0/darwin_amd64

Test provider executable with hcl files and terraform commands

source secrets.cfg
cd terraform
terraform init -plugin-dir="./.terraform/plugins/"
terraform plan
# It is important to set the the DEBUG log level before applying `teraform apply` or `teraform destroy` 
export TF_LOG=DEBUG
terraform apply --auto-approve # initial create requests
# Update input variables in tf files, e.g. 
# ```hcl
# resource "mgtt_azurerm_rg" "this" {
#     name = "rg-test-9000"
#     location = "West Europe"
# }
# ```
terraform apply --auto-approve # update requests 
terraform destroy --auto-approve # delete requests

About

Sample repository implementing a terraform provider designed for managing resources in Azure and AWS

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published