Skip to content

mondoohq/terraform-provider-mondoo

Repository files navigation

Terraform Provider Mondoo

Status: It is currently in beta. Please report any issues you encounter.

The Mondoo Provider allows Terraform to manage Mondoo resources.

Provider Usage

terraform {
  required_providers {
    mondoo = {
      source = "mondoohq/mondoo"
    }
  }
}

provider "mondoo" {
  region = "us" # use "eu" for the European region
}

Developing the provider

If you wish to work on the provider, you'll first need Go installed on your machine ( see Requirements above).

To compile the provider, run go install. This will build the provider and put the provider binary in the $GOPATH/bin directory.

To generate or update documentation, run go generate.

In order to run the full suite of Acceptance tests, run make testacc.

Note: Acceptance tests create real resources, and often cost money to run.

make testacc

This provider is built on the Terraform Plugin Framework. The template repository built on the Terraform Plugin SDK can be found at terraform-provider-scaffolding. The directory structure contains the following directories:

  • A resource and a data source (internal/provider/),
  • Examples (examples/) and generated documentation (docs/),
  • Miscellaneous meta files.

Requirements

Building The Provider

  1. Clone the repository
  2. Enter the repository directory
  3. Build the provider using the Go install command:
go install

To use the local provider, add the following to your Terraform configuration ~/.terraformrc and provide it with the absolute path to your /go/bin directory:

provider_installation {
  dev_overrides {
    "mondoohq/mondoo" = "/Users/USERNAME/go/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 {}
}

See Terraform documentation for more details about provider install configuration.

Adding Dependencies

This provider uses Go modules. Please see the Go documentation for the most up to date information about using Go modules.

To add a new dependency github.com/author/dependency to your Terraform provider:

go get github.com/author/dependency
go mod tidy

Then commit the changes to go.mod and go.sum.

Adding Resources

The easiest way to create a new resource is to use the Terraform Plugin Framework Code Generator

go install github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework@latest

Now you can scaffold a new resource:

tfplugingen-framework scaffold resource --name policy_upload --output-dir internal/provider