Skip to content

d-strobel/terraform-provider-windows

Repository files navigation

Terraform Provider Windows

Build GoReport Conventional Commits

This Terraform provider enables the management of Windows-based resources within your infrastructure.

It is built on top of the gowindows SDK, which acts as the underlying interface for interacting with Windows environments.

To introduce new features or enhancements to this provider, the corresponding functionality must first be implemented in the gowindows library. Contributions or feature requests should therefore begin with updates to the GoWindows SDK before being integrated into the provider.

Using the provider

terraform {
  required_providers {
    windows = {
      source = "d-strobel/windows"
    }
  }
}

provider "windows" {
  endpoint = "127.0.0.1"

  ssh = {
    username = "vagrant"
    password = "vagrant"
    port     = 1222
  }
}

// Create a new local security group.
resource "windows_local_group" "this" {
    name = "MyNewGroup"
}

// Create a new local user.
resource "windows_local_user" "this" {
    name = "MyNewUser"
}

Developing the Provider

Pre-commit

To ensure smooth execution in the pipeline and eliminate potential linting errors, it's highly advisable to integrate pre-commit hooks. These hooks can be effortlessly installed to streamline the process and maintain code quality standards.

You can find more details about pre-commit hooks on their official website: pre-commit.

Conventional Commits

This Terraform provider follows the conventional commit guidelines. For more information, see conventionalcommits.org.

Code Generation

Some parts of this provider are automatically generated using the terraform-plugin-codegen-framework.

Schema

The schemas for providers, resources, and data sources are defined as JSON files located in the internal/schema directory.

To generate the corresponding code, simply run go generate.
This will execute all commands in the main.go file that are prefixed with the following syntax: //go:generate <CMD>.

If you are adding a new resource within an existing subpackage, update the JSON schema in the respective subpackage file.

For a new subpackage, you’ll need to create a new file for the resources and data sources.
Additionally, you'll also need to add the appropriate code generation commands in the main.go file.

Scaffolding

Once the schema code is generated, you may want to create the data source or resource files that utilize the generated code.

To help with this, you can use the scaffold command from the terraform-plugin-codegen-framework to initially generate these files.
Since the scaffolded files require manual modification, you only need to generate them once.

  • Create a Resource
tfplugingen-framework scaffold resource --name subpackage_resource_name --output-dir internal/provider/subpackage --package subpackage
  • Create a Datasources
tfplugingen-framework scaffold data-source --name subpackage_datasource_name --output-dir internal/provider/subpackage --package subpackage

After generating the files, update them as needed. Review the existing resources and data sources for guidance on what changes to make initially.

Once the CRUD operation logic is implemented in the corresponding functions, ensure that the New...Resource or New...DataSource function is called in the provider.go file under the appropriate Resources or DataSources function.

Finally, don’t forget to add acceptance tests to validate the functionality (see section Acceptance Test).

Acceptance test

The acceptance tests are currently not available via Github action.

Prerequisites

Run tests

Boot the Vagrant machines:

make vagrant-up

Run acceptance tests for terraform and opentofu:

make testacc

Destroy the Vagrant machines:

make vagrant-down

Inspirations

Hashicorp made a great start with the terraform-provider-ad. Currently, it seems that the provider is not actively maintained.
Beyond that, my goal is to split the terraform-provider into a library and a provider and extend its functionality with non Active-Directory systems.

License

This project is licensed under the Mozilla Public License Version 2.0.