mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 02:31:10 +00:00
feat(core): migrate version
datasource to TF plugin framework (#440)
* feat: migrate `version` datasource to tf framework * set up documentation generator * add generated docs for network resources * fix test mux server, add import examples to network resources * fix network tests * fix shell examples
This commit is contained in:
parent
8e2d18053f
commit
a9a7329d9f
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,6 +12,7 @@ bin/
|
||||
cache/
|
||||
dist/
|
||||
modules-dev/
|
||||
docs-gen/
|
||||
|
||||
.terraform/
|
||||
.vagrant/
|
||||
|
7
Makefile
7
Makefile
@ -23,6 +23,7 @@ clean:
|
||||
rm -rf ./dist
|
||||
rm -rf ./cache
|
||||
rm -rf ./build
|
||||
rm -rf ./docs-gen
|
||||
|
||||
build:
|
||||
mkdir -p "$(TERRAFORM_PLUGIN_OUTPUT_DIRECTORY)"
|
||||
@ -80,6 +81,10 @@ lint:
|
||||
release-build:
|
||||
go run -modfile=tools/go.mod github.com/goreleaser/goreleaser build --clean --skip-validate
|
||||
|
||||
docs:
|
||||
@mkdir -p ./docs-gen
|
||||
@cd ./tools && go generate tools.go
|
||||
|
||||
targets: $(TARGETS)
|
||||
|
||||
$(TARGETS):
|
||||
@ -90,4 +95,4 @@ $(TARGETS):
|
||||
-j "dist/$(NAME)_v$(VERSION)-custom_$@_amd64.zip" \
|
||||
"dist/$@/$(NAME)_v$(VERSION)-custom"
|
||||
|
||||
.PHONY: clean build example example-apply example-destroy example-init example-plan fmt init targets test $(TARGETS)
|
||||
.PHONY: clean build example example-apply example-destroy example-init example-plan fmt init targets test docs $(TARGETS)
|
||||
|
@ -1,29 +1,36 @@
|
||||
---
|
||||
layout: page
|
||||
title: proxmox_virtual_environment_version
|
||||
permalink: /data-sources/virtual_environment_version
|
||||
nav_order: 20
|
||||
parent: Data Sources
|
||||
subcategory: Virtual Environment
|
||||
description: |-
|
||||
Retrieves API version details.
|
||||
---
|
||||
|
||||
# Data Source: proxmox_virtual_environment_version
|
||||
|
||||
Retrieves the version information from the API endpoint.
|
||||
Retrieves API version details.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```terraform
|
||||
data "proxmox_virtual_environment_version" "current_version" {}
|
||||
data "proxmox_virtual_environment_version" "example" {}
|
||||
|
||||
output "data_proxmox_virtual_environment_version" {
|
||||
value = {
|
||||
release = data.proxmox_virtual_environment_version.example.release
|
||||
repository_id = data.proxmox_virtual_environment_version.example.repository_id
|
||||
version = data.proxmox_virtual_environment_version.example.version
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
There are no arguments available for this data source.
|
||||
### Read-Only
|
||||
|
||||
## Attribute Reference
|
||||
|
||||
- `keyboard_layout` - The keyboard layout.
|
||||
- `release` - The release number.
|
||||
- `repository_id` - The repository identifier.
|
||||
- `version` - The version string.
|
||||
- `id` (String) Placeholder identifier attribute.
|
||||
- `release` (String) The current Proxmox VE point release in `x.y` format.
|
||||
- `repository_id` (String) The short git revision from which this version was build.
|
||||
- `version` (String) The full pve-manager package version of this node.
|
||||
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
layout: page
|
||||
title: proxmox_virtual_environment_network_linux_bridge
|
||||
permalink: /resources/virtual_environment_network_linux_bridge
|
||||
nav_order: 13
|
||||
parent: Resources
|
||||
subcategory: Virtual Environment
|
||||
description: |-
|
||||
Manages a Linux Bridge network interface in a Proxmox VE node.
|
||||
---
|
||||
|
||||
# Resource: proxmox_virtual_environment_network_linux_bridge
|
||||
@ -14,33 +14,54 @@ Manages a Linux Bridge network interface in a Proxmox VE node.
|
||||
## Example Usage
|
||||
|
||||
```terraform
|
||||
resource "proxmox_virtual_environment_network_linux_bridge" "bridge99" {
|
||||
resource "proxmox_virtual_environment_network_linux_bridge" "vmbr99" {
|
||||
depends_on = [
|
||||
proxmox_virtual_environment_network_linux_vlan.vlan99
|
||||
]
|
||||
|
||||
node_name = "pve"
|
||||
iface = "vmbr99"
|
||||
address = "3.3.3.3/24"
|
||||
comment = "created by terraform"
|
||||
mtu = 1499
|
||||
name = "vmbr99"
|
||||
|
||||
address = "99.99.99.99/16"
|
||||
|
||||
comment = "vmbr99 comment"
|
||||
|
||||
ports = [
|
||||
"ens18.99"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
- `node_name` - (Required) The name of the node to manage the interface on.
|
||||
- `name` - (Required) The interface name. Must be "vmbrN", where N is a number
|
||||
between 0 and 9999.
|
||||
### Required
|
||||
|
||||
- `address` - (Optional) The interface IPv4/CIDR address.
|
||||
- `address6` - (Optional) The interface IPv6/CIDR address.
|
||||
- `autostart` - (Optional) Automatically start interface on boot (defaults
|
||||
to `true`).
|
||||
- `ports` - (Optional) Specify the list of the interface bridge ports.
|
||||
- `vlan_aware` - (Optional) Whether the interface bridge is VLAN aware (defaults
|
||||
to `true`).
|
||||
- `comment` - (Optional) Comment for the interface.
|
||||
- `gateway` - (Optional) Default gateway address.
|
||||
- `gateway6` - (Optional) Default IPv6 gateway address.
|
||||
- `mtu` - (Optional) The interface MTU.
|
||||
- `name` (String) The interface name. Must be `vmbrN`, where N is a number between 0 and 9999.
|
||||
- `node_name` (String) The name of the node.
|
||||
|
||||
### Optional
|
||||
|
||||
- `address` (String) The interface IPv4/CIDR address.
|
||||
- `address6` (String) The interface IPv6/CIDR address.
|
||||
- `autostart` (Boolean) Automatically start interface on boot (defaults to `true`).
|
||||
- `comment` (String) Comment for the interface.
|
||||
- `gateway` (String) Default gateway address.
|
||||
- `gateway6` (String) Default IPv6 gateway address.
|
||||
- `mtu` (Number) The interface MTU.
|
||||
- `ports` (List of String) The interface bridge ports.
|
||||
- `vlan_aware` (Boolean) Whether the interface bridge is VLAN aware (defaults to `true`).
|
||||
|
||||
### Read-Only
|
||||
|
||||
- `id` (String) A unique identifier with format '<node name>:<iface>'
|
||||
|
||||
## Import
|
||||
|
||||
Import is supported using the following syntax:
|
||||
|
||||
```shell
|
||||
# Interfaces can be imported using the `node_name:iface` format, e.g.,
|
||||
|
||||
terraform import proxmox_virtual_environment_network_linux_bridge.vmbr99 pve:vmbr99
|
||||
```
|
||||
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
layout: page
|
||||
title: proxmox_virtual_environment_network_linux_vlan
|
||||
permalink: /resources/virtual_environment_network_linux_vlan
|
||||
nav_order: 13
|
||||
parent: Resources
|
||||
subcategory: Virtual Environment
|
||||
description: |-
|
||||
Manages a Linux VLAN network interface in a Proxmox VE node.
|
||||
---
|
||||
|
||||
# Resource: proxmox_virtual_environment_network_linux_vlan
|
||||
@ -14,30 +14,44 @@ Manages a Linux VLAN network interface in a Proxmox VE node.
|
||||
## Example Usage
|
||||
|
||||
```terraform
|
||||
resource "proxmox_virtual_environment_network_linux_vlan" "vlan21" {
|
||||
resource "proxmox_virtual_environment_network_linux_vlan" "vlan99" {
|
||||
node_name = "pve"
|
||||
iface = "ens18.21"
|
||||
comment = "created by terraform"
|
||||
name = "eno0.99"
|
||||
|
||||
comment = "VLAN 99"
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
- `node_name` - (Required) The name of the node to manage the interface on.
|
||||
- `name` - (Required) The interface name. Add the VLAN tag number to an
|
||||
existing interface name, e.g. "ens18.21".
|
||||
### Required
|
||||
|
||||
- `address` - (Optional) The interface IPv4/CIDR address.
|
||||
- `address6` - (Optional) The interface IPv6/CIDR address.
|
||||
- `autostart` - (Optional) Automatically start interface on boot (defaults
|
||||
to `true`).
|
||||
- `comment` - (Optional) Comment for the interface.
|
||||
- `gateway` - (Optional) Default gateway address.
|
||||
- `gateway6` - (Optional) Default IPv6 gateway address.
|
||||
- `mtu` - (Optional) The interface MTU.
|
||||
- `name` (String) The interface name. Add the VLAN tag number to an existing interface name, e.g. `ens18.21`
|
||||
- `node_name` (String) The name of the node.
|
||||
|
||||
### Optional
|
||||
|
||||
- `address` (String) The interface IPv4/CIDR address.
|
||||
- `address6` (String) The interface IPv6/CIDR address.
|
||||
- `autostart` (Boolean) Automatically start interface on boot (defaults to `true`).
|
||||
- `comment` (String) Comment for the interface.
|
||||
- `gateway` (String) Default gateway address.
|
||||
- `gateway6` (String) Default IPv6 gateway address.
|
||||
- `mtu` (Number) The interface MTU.
|
||||
|
||||
### Read-Only
|
||||
|
||||
- `id` (String) A unique identifier with format '<node name>:<iface>'
|
||||
- `interface` (String) The VLAN raw device.
|
||||
- `vlan` (Number) The VLAN tag
|
||||
|
||||
## Import
|
||||
|
||||
Import is supported using the following syntax:
|
||||
|
||||
```shell
|
||||
# Interfaces can be imported using the `node_name:iface` format, e.g.,
|
||||
|
||||
terraform import proxmox_virtual_environment_network_linux_vlan.vlan99 pve:vlan99
|
||||
```
|
||||
|
@ -1,10 +0,0 @@
|
||||
data "proxmox_virtual_environment_version" "example" {}
|
||||
|
||||
output "data_proxmox_virtual_environment_version" {
|
||||
value = {
|
||||
keyboard_layout = data.proxmox_virtual_environment_version.example.keyboard_layout
|
||||
release = data.proxmox_virtual_environment_version.example.release
|
||||
repository_id = data.proxmox_virtual_environment_version.example.repository_id
|
||||
version = data.proxmox_virtual_environment_version.example.version
|
||||
}
|
||||
}
|
6
examples/README.md
Normal file
6
examples/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
`/examples` contain a set of examples that can be used to test the provider as
|
||||
well as documentation examples. The examples are not meant to be used in
|
||||
production.
|
||||
|
||||
NOTE: during migration to TF plugin framework, examples of migrated resources /
|
||||
data sources will be moving from `/example` to `/examples` folder
|
@ -0,0 +1,9 @@
|
||||
data "proxmox_virtual_environment_version" "example" {}
|
||||
|
||||
output "data_proxmox_virtual_environment_version" {
|
||||
value = {
|
||||
release = data.proxmox_virtual_environment_version.example.release
|
||||
repository_id = data.proxmox_virtual_environment_version.example.repository_id
|
||||
version = data.proxmox_virtual_environment_version.example.version
|
||||
}
|
||||
}
|
17
examples/provider/provider.tf
Normal file
17
examples/provider/provider.tf
Normal file
@ -0,0 +1,17 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
datadog = {
|
||||
source = "bpg/proxmox"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "proxmox" {
|
||||
endpoint = var.virtual_environment_endpoint
|
||||
username = var.virtual_environment_username
|
||||
password = var.virtual_environment_password
|
||||
insecure = true
|
||||
ssh {
|
||||
agent = true
|
||||
}
|
||||
}
|
14
examples/provider/variables.tf
Normal file
14
examples/provider/variables.tf
Normal file
@ -0,0 +1,14 @@
|
||||
variable "virtual_environment_endpoint" {
|
||||
type = string
|
||||
description = "The endpoint for the Proxmox Virtual Environment API (example: https://host:port)"
|
||||
}
|
||||
|
||||
variable "virtual_environment_password" {
|
||||
type = string
|
||||
description = "The password for the Proxmox Virtual Environment API"
|
||||
}
|
||||
|
||||
variable "virtual_environment_username" {
|
||||
type = string
|
||||
description = "The username and realm for the Proxmox Virtual Environment API (example: root@pam)"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env sh
|
||||
#Interfaces can be imported using the `node_name:iface` format, e.g.
|
||||
terraform import proxmox_virtual_environment_network_linux_bridge.vmbr99 pve:vmbr99
|
@ -1,10 +1,3 @@
|
||||
resource "proxmox_virtual_environment_network_linux_vlan" "vlan99" {
|
||||
node_name = "pve"
|
||||
name = "eno0.99"
|
||||
|
||||
comment = "VLAN 99"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_network_linux_bridge" "vmbr99" {
|
||||
depends_on = [
|
||||
proxmox_virtual_environment_network_linux_vlan.vlan99
|
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env sh
|
||||
#Interfaces can be imported using the `node_name:iface` format, e.g.
|
||||
terraform import proxmox_virtual_environment_network_linux_vlan.vlan99 pve:vlan99
|
@ -0,0 +1,6 @@
|
||||
resource "proxmox_virtual_environment_network_linux_vlan" "vlan99" {
|
||||
node_name = "pve"
|
||||
name = "eno0.99"
|
||||
|
||||
comment = "VLAN 99"
|
||||
}
|
@ -175,8 +175,9 @@ func (r *linuxBridgeResource) Schema(
|
||||
Required: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Description: "The interface name.",
|
||||
Required: true,
|
||||
Description: "The interface name.",
|
||||
MarkdownDescription: "The interface name. Must be `vmbrN`, where N is a number between 0 and 9999.",
|
||||
Required: true,
|
||||
Validators: []validator.String{
|
||||
stringvalidator.RegexMatches(
|
||||
regexp.MustCompile(`^vmbr(\d{1,4})$`),
|
||||
@ -208,7 +209,7 @@ func (r *linuxBridgeResource) Schema(
|
||||
Optional: true,
|
||||
},
|
||||
"autostart": schema.BoolAttribute{
|
||||
Description: "Automatically start interface on boot.",
|
||||
Description: "Automatically start interface on boot (defaults to `true`).",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Default: booldefault.StaticBool(true),
|
||||
@ -229,7 +230,7 @@ func (r *linuxBridgeResource) Schema(
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"vlan_aware": schema.BoolAttribute{
|
||||
Description: "Whether the interface bridge is VLAN aware.",
|
||||
Description: "Whether the interface bridge is VLAN aware (defaults to `true`).",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
@ -463,7 +464,7 @@ func (r *linuxBridgeResource) ImportState(
|
||||
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Import Identifier",
|
||||
fmt.Sprintf("Expected import identifier with format: node_name:iface. Got: %q", req.ID),
|
||||
fmt.Sprintf("Expected import identifier with format: `node_name:iface`. Got: %q", req.ID),
|
||||
)
|
||||
|
||||
return
|
||||
|
@ -155,8 +155,9 @@ func (r *linuxVLANResource) Schema(
|
||||
Required: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Description: "The interface name.",
|
||||
Required: true,
|
||||
Description: "The interface name.",
|
||||
MarkdownDescription: "The interface name. Add the VLAN tag number to an existing interface name, e.g. `ens18.21`",
|
||||
Required: true,
|
||||
Validators: []validator.String{
|
||||
stringvalidator.LengthAtLeast(3),
|
||||
},
|
||||
@ -185,7 +186,7 @@ func (r *linuxVLANResource) Schema(
|
||||
Optional: true,
|
||||
},
|
||||
"autostart": schema.BoolAttribute{
|
||||
Description: "Automatically start interface on boot.",
|
||||
Description: "Automatically start interface on boot (defaults to `true`).",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Default: booldefault.StaticBool(true),
|
||||
|
126
internal/provider/datasource_version.go
Normal file
126
internal/provider/datasource_version.go
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"github.com/bpg/terraform-provider-proxmox/proxmox"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &versionDatasource{}
|
||||
_ datasource.DataSourceWithConfigure = &versionDatasource{}
|
||||
)
|
||||
|
||||
// NewVersionDataSource is a helper function to simplify the provider implementation.
|
||||
func NewVersionDataSource() datasource.DataSource {
|
||||
return &versionDatasource{}
|
||||
}
|
||||
|
||||
// versionDatasource is the data source implementation.
|
||||
type versionDatasource struct {
|
||||
client proxmox.Client
|
||||
}
|
||||
|
||||
// versionDataSourceModel maps the data source schema data.
|
||||
type versionDataSourceModel struct {
|
||||
Release types.String `tfsdk:"release"`
|
||||
RepositoryID types.String `tfsdk:"repository_id"`
|
||||
Version types.String `tfsdk:"version"`
|
||||
ID types.String `tfsdk:"id"`
|
||||
}
|
||||
|
||||
// Metadata returns the data source type name.
|
||||
func (d *versionDatasource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_version"
|
||||
}
|
||||
|
||||
// Schema defines the schema for the data source.
|
||||
func (d *versionDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Description: "Retrieves API version details.",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{
|
||||
Description: "Placeholder identifier attribute.",
|
||||
Computed: true,
|
||||
},
|
||||
"release": schema.StringAttribute{
|
||||
Description: "The current Proxmox VE point release in `x.y` format.",
|
||||
Computed: true,
|
||||
},
|
||||
"repository_id": schema.StringAttribute{
|
||||
Description: "The short git revision from which this version was build.",
|
||||
Computed: true,
|
||||
},
|
||||
"version": schema.StringAttribute{
|
||||
Description: "The full pve-manager package version of this node.",
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *versionDatasource) Configure(
|
||||
_ context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
}
|
||||
|
||||
client, ok := req.ProviderData.(proxmox.Client)
|
||||
|
||||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Resource Configure Type",
|
||||
fmt.Sprintf("Expected *proxmox.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
d.client = client
|
||||
}
|
||||
|
||||
// Read refreshes the Terraform state with the latest data.
|
||||
func (d *versionDatasource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
var state versionDataSourceModel
|
||||
|
||||
version, err := d.client.Version().Version(ctx)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unable to Read Version",
|
||||
err.Error(),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
state.Release = types.StringValue(version.Release)
|
||||
state.RepositoryID = types.StringValue(version.RepositoryID)
|
||||
state.Version = types.StringValue(version.Version)
|
||||
|
||||
state.ID = types.StringValue("version")
|
||||
|
||||
// Set state
|
||||
diags := resp.State.Set(ctx, &state)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
}
|
@ -354,7 +354,9 @@ func (p *proxmoxProvider) Resources(_ context.Context) []func() resource.Resourc
|
||||
}
|
||||
|
||||
func (p *proxmoxProvider) DataSources(_ context.Context) []func() datasource.DataSource {
|
||||
return []func() datasource.DataSource{}
|
||||
return []func() datasource.DataSource{
|
||||
NewVersionDataSource,
|
||||
}
|
||||
}
|
||||
|
||||
type apiResolver struct {
|
||||
|
45
internal/test/datasource_version_test.go
Normal file
45
internal/test/datasource_version_test.go
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
||||
)
|
||||
|
||||
func Test_VersionDatasource(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
accProviders := AccMuxProviders(context.Background(), t)
|
||||
|
||||
datasourceName := "data.proxmox_virtual_environment_version.test"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
ProtoV6ProviderFactories: accProviders,
|
||||
Steps: []resource.TestStep{
|
||||
// Read testing
|
||||
{
|
||||
Config: ProviderConfig + `data "proxmox_virtual_environment_version" "test" {}`,
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(datasourceName, "release", "8.0"),
|
||||
resource.TestCheckResourceAttrSet(datasourceName, "repository_id"),
|
||||
resource.TestCheckResourceAttrWith(datasourceName, "version", func(value string) error {
|
||||
if strings.HasPrefix(value, "8.0") {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("version %s does not start with 8.0", value)
|
||||
}),
|
||||
resource.TestCheckResourceAttrSet(datasourceName, "id"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
@ -4,25 +4,30 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package test
|
||||
package network
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
||||
|
||||
"github.com/bpg/terraform-provider-proxmox/internal/test"
|
||||
)
|
||||
|
||||
func Test_LinuxBridgeResource(t *testing.T) {
|
||||
func TestLinuxBridgeResource(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
accProviders := test.AccMuxProviders(context.Background(), t)
|
||||
|
||||
resourceName := "proxmox_virtual_environment_network_linux_bridge.test"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
ProtoV6ProviderFactories: AccTestProtoV6ProviderFactories,
|
||||
ProtoV6ProviderFactories: accProviders,
|
||||
Steps: []resource.TestStep{
|
||||
// Create and Read testing
|
||||
{
|
||||
Config: ProviderConfig + `
|
||||
Config: test.ProviderConfig + `
|
||||
resource "proxmox_virtual_environment_network_linux_bridge" "test" {
|
||||
node_name = "pve"
|
||||
name = "vmbr99"
|
||||
@ -48,7 +53,7 @@ resource "proxmox_virtual_environment_network_linux_bridge" "test" {
|
||||
},
|
||||
// Update testing
|
||||
{
|
||||
Config: ProviderConfig + `
|
||||
Config: test.ProviderConfig + `
|
||||
resource "proxmox_virtual_environment_network_linux_bridge" "test" {
|
||||
node_name = "pve"
|
||||
name = "vmbr99"
|
@ -4,37 +4,42 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package test
|
||||
package network
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
||||
|
||||
"github.com/bpg/terraform-provider-proxmox/internal/test"
|
||||
)
|
||||
|
||||
func Test_LinuxVLANResource(t *testing.T) {
|
||||
func TestLinuxVLANResource(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
accProviders := test.AccMuxProviders(context.Background(), t)
|
||||
|
||||
resourceName := "proxmox_virtual_environment_network_linux_vlan.test"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
ProtoV6ProviderFactories: AccTestProtoV6ProviderFactories,
|
||||
ProtoV6ProviderFactories: accProviders,
|
||||
Steps: []resource.TestStep{
|
||||
// Create and Read testing
|
||||
{
|
||||
Config: ProviderConfig + `
|
||||
Config: test.ProviderConfig + `
|
||||
resource "proxmox_virtual_environment_network_linux_vlan" "test" {
|
||||
node_name = "pve"
|
||||
name = "ens18.33"
|
||||
name = "eno0.33"
|
||||
comment = "created by terraform"
|
||||
mtu = 1499
|
||||
}
|
||||
`,
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(resourceName, "name", "ens18.33"),
|
||||
resource.TestCheckResourceAttr(resourceName, "name", "eno0.33"),
|
||||
resource.TestCheckResourceAttr(resourceName, "comment", "created by terraform"),
|
||||
resource.TestCheckResourceAttr(resourceName, "vlan", "33"),
|
||||
resource.TestCheckResourceAttr(resourceName, "interface", "ens18"),
|
||||
resource.TestCheckResourceAttr(resourceName, "interface", "eno0"),
|
||||
resource.TestCheckResourceAttrSet(resourceName, "id"),
|
||||
),
|
||||
},
|
||||
@ -46,10 +51,10 @@ resource "proxmox_virtual_environment_network_linux_vlan" "test" {
|
||||
},
|
||||
// Update testing
|
||||
{
|
||||
Config: ProviderConfig + `
|
||||
Config: test.ProviderConfig + `
|
||||
resource "proxmox_virtual_environment_network_linux_vlan" "test" {
|
||||
node_name = "pve"
|
||||
name = "ens18.33"
|
||||
name = "eno0.33"
|
||||
address = "1.1.1.1/24"
|
||||
address6 = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64"
|
||||
comment = "updated by terraform"
|
||||
@ -57,12 +62,12 @@ resource "proxmox_virtual_environment_network_linux_vlan" "test" {
|
||||
}
|
||||
`,
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(resourceName, "name", "ens18.33"),
|
||||
resource.TestCheckResourceAttr(resourceName, "name", "eno0.33"),
|
||||
resource.TestCheckResourceAttr(resourceName, "address", "1.1.1.1/24"),
|
||||
resource.TestCheckResourceAttr(resourceName, "address6", "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64"),
|
||||
resource.TestCheckResourceAttr(resourceName, "comment", "updated by terraform"),
|
||||
resource.TestCheckResourceAttr(resourceName, "vlan", "33"),
|
||||
resource.TestCheckResourceAttr(resourceName, "interface", "ens18"),
|
||||
resource.TestCheckResourceAttr(resourceName, "interface", "eno0"),
|
||||
resource.TestCheckNoResourceAttr(resourceName, "mtu"),
|
||||
resource.TestCheckResourceAttrSet(resourceName, "id"),
|
||||
),
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
||||
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
|
||||
|
||||
"github.com/bpg/terraform-provider-proxmox/internal/provider"
|
||||
)
|
||||
|
||||
const (
|
||||
// ProviderConfig is a shared configuration to combine with the actual
|
||||
// test configuration so the Proxmox VE client is properly configured.
|
||||
// It is also possible to use the PROXMOX_VE_ environment variables instead,.
|
||||
ProviderConfig = `
|
||||
provider "proxmox" {
|
||||
username = "root@pam"
|
||||
password = "password"
|
||||
insecure = true
|
||||
ssh {
|
||||
agent = true
|
||||
}
|
||||
}
|
||||
`
|
||||
// such as updating the Makefile and running the testing through that tool.
|
||||
)
|
||||
|
||||
// AccTestProtoV6ProviderFactories are used to instantiate a provider during
|
||||
// acceptance testing. The factory function will be invoked for every Terraform
|
||||
// CLI command executed to create a provider server to which the CLI can
|
||||
// reattach.
|
||||
//
|
||||
//nolint:gochecknoglobals
|
||||
var AccTestProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
||||
"proxmox": providerserver.NewProtocol6WithError(provider.New("test")()),
|
||||
}
|
79
internal/test/test_support.go
Normal file
79
internal/test/test_support.go
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
||||
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
|
||||
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
|
||||
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
|
||||
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
fwprovider "github.com/bpg/terraform-provider-proxmox/internal/provider"
|
||||
sdkV2provider "github.com/bpg/terraform-provider-proxmox/proxmoxtf/provider"
|
||||
)
|
||||
|
||||
const (
|
||||
// ProviderConfig is a shared configuration to combine with the actual
|
||||
// test configuration so the Proxmox VE client is properly configured.
|
||||
// It is also possible to use the PROXMOX_VE_ environment variables instead.
|
||||
ProviderConfig = `
|
||||
provider "proxmox" {
|
||||
username = "root@pam"
|
||||
password = "password"
|
||||
insecure = true
|
||||
ssh {
|
||||
agent = true
|
||||
}
|
||||
}
|
||||
`
|
||||
)
|
||||
|
||||
// AccMuxProviders returns a map of mux servers for the acceptance tests.
|
||||
func AccMuxProviders(ctx context.Context, t *testing.T) map[string]func() (tfprotov6.ProviderServer, error) {
|
||||
t.Helper()
|
||||
|
||||
// Init sdkV2 provider
|
||||
sdkV2Provider, err := tf5to6server.UpgradeServer(
|
||||
ctx,
|
||||
func() tfprotov5.ProviderServer {
|
||||
return schema.NewGRPCProviderServer(
|
||||
sdkV2provider.ProxmoxVirtualEnvironment(),
|
||||
)
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Init framework provider
|
||||
frameworkProvider := fwprovider.New("test")()
|
||||
|
||||
providers := []func() tfprotov6.ProviderServer{
|
||||
providerserver.NewProtocol6(frameworkProvider),
|
||||
func() tfprotov6.ProviderServer {
|
||||
return sdkV2Provider
|
||||
},
|
||||
}
|
||||
|
||||
// Init mux servers
|
||||
muxServers := map[string]func() (tfprotov6.ProviderServer, error){
|
||||
"proxmox": func() (tfprotov6.ProviderServer, error) {
|
||||
muxServer, e := tf6muxserver.NewMuxServer(ctx, providers...)
|
||||
if e != nil {
|
||||
return nil, fmt.Errorf("failed to create mux server: %w", e)
|
||||
}
|
||||
return muxServer, nil
|
||||
},
|
||||
}
|
||||
|
||||
return muxServers
|
||||
}
|
12
main.go
12
main.go
@ -23,13 +23,9 @@ import (
|
||||
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/provider"
|
||||
)
|
||||
|
||||
// If you do not have terraform installed, you can remove the formatting command, but it's suggested to
|
||||
// ensure the documentation is formatted properly.
|
||||
//go:generate terraform fmt -recursive ./example/
|
||||
|
||||
// Run the docs generation tool, check its repository for more information on how it works and how docs
|
||||
// can be customized.
|
||||
//go:generate go run -modfile=tools/go.mod github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
|
||||
// these will be set by the goreleaser configuration
|
||||
// to appropriate values for the compiled binary.
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
@ -52,7 +48,7 @@ func main() {
|
||||
}
|
||||
|
||||
providers := []func() tfprotov6.ProviderServer{
|
||||
providerserver.NewProtocol6(newProvider.New("dev")()),
|
||||
providerserver.NewProtocol6(newProvider.New(version)()),
|
||||
func() tfprotov6.ProviderServer {
|
||||
return upgradedSdkServer
|
||||
},
|
||||
|
@ -13,7 +13,7 @@ type ResponseBody struct {
|
||||
|
||||
// ResponseData contains the data from a version response.
|
||||
type ResponseData struct {
|
||||
Keyboard string `json:"keyboard"`
|
||||
Console string `json:"console"`
|
||||
Release string `json:"release"`
|
||||
RepositoryID string `json:"repoid"`
|
||||
Version string `json:"version"`
|
||||
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package datasource
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
"github.com/bpg/terraform-provider-proxmox/proxmoxtf"
|
||||
)
|
||||
|
||||
const (
|
||||
mkDataSourceVirtualEnvironmentVersionKeyboardLayout = "keyboard_layout"
|
||||
mkDataSourceVirtualEnvironmentVersionRelease = "release"
|
||||
mkDataSourceVirtualEnvironmentVersionRepositoryID = "repository_id"
|
||||
mkDataSourceVirtualEnvironmentVersionVersion = "version"
|
||||
)
|
||||
|
||||
// Version returns a resource for the Proxmox version.
|
||||
func Version() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
mkDataSourceVirtualEnvironmentVersionKeyboardLayout: {
|
||||
Type: schema.TypeString,
|
||||
Description: "The keyboard layout",
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
mkDataSourceVirtualEnvironmentVersionRelease: {
|
||||
Type: schema.TypeString,
|
||||
Description: "The release information",
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
mkDataSourceVirtualEnvironmentVersionRepositoryID: {
|
||||
Type: schema.TypeString,
|
||||
Description: "The repository id",
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
mkDataSourceVirtualEnvironmentVersionVersion: {
|
||||
Type: schema.TypeString,
|
||||
Description: "The version information",
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
ReadContext: versionRead,
|
||||
}
|
||||
}
|
||||
|
||||
func versionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
var diags diag.Diagnostics
|
||||
|
||||
config := m.(proxmoxtf.ProviderConfiguration)
|
||||
api, err := config.GetClient()
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
version, err := api.Version().Version(ctx)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("version")
|
||||
|
||||
err = d.Set(mkDataSourceVirtualEnvironmentVersionKeyboardLayout, version.Keyboard)
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
err = d.Set(mkDataSourceVirtualEnvironmentVersionRelease, version.Release)
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
err = d.Set(mkDataSourceVirtualEnvironmentVersionRepositoryID, version.RepositoryID)
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
err = d.Set(mkDataSourceVirtualEnvironmentVersionVersion, version.Version)
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
|
||||
return diags
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package datasource
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
"github.com/bpg/terraform-provider-proxmox/proxmoxtf/test"
|
||||
)
|
||||
|
||||
// TestVersionInstantiation tests whether the Version instance can be instantiated.
|
||||
func TestVersionInstantiation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := Version()
|
||||
if s == nil {
|
||||
t.Fatalf("Cannot instantiate Version")
|
||||
}
|
||||
}
|
||||
|
||||
// TestVersionSchema tests the Version schema.
|
||||
func TestVersionSchema(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := Version()
|
||||
|
||||
test.AssertComputedAttributes(t, s, []string{
|
||||
mkDataSourceVirtualEnvironmentVersionKeyboardLayout,
|
||||
mkDataSourceVirtualEnvironmentVersionRelease,
|
||||
mkDataSourceVirtualEnvironmentVersionRepositoryID,
|
||||
mkDataSourceVirtualEnvironmentVersionVersion,
|
||||
})
|
||||
|
||||
test.AssertValueTypes(t, s, map[string]schema.ValueType{
|
||||
mkDataSourceVirtualEnvironmentVersionKeyboardLayout: schema.TypeString,
|
||||
mkDataSourceVirtualEnvironmentVersionRelease: schema.TypeString,
|
||||
mkDataSourceVirtualEnvironmentVersionRepositoryID: schema.TypeString,
|
||||
mkDataSourceVirtualEnvironmentVersionVersion: schema.TypeString,
|
||||
})
|
||||
}
|
@ -27,7 +27,6 @@ func createDatasourceMap() map[string]*schema.Resource {
|
||||
"proxmox_virtual_environment_time": datasource.Time(),
|
||||
"proxmox_virtual_environment_user": datasource.User(),
|
||||
"proxmox_virtual_environment_users": datasource.Users(),
|
||||
"proxmox_virtual_environment_version": datasource.Version(),
|
||||
"proxmox_virtual_environment_vm": datasource.VM(),
|
||||
"proxmox_virtual_environment_vms": datasource.VMs(),
|
||||
}
|
||||
|
20
templates/data-sources.md.tmpl
Normal file
20
templates/data-sources.md.tmpl
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
layout: page
|
||||
title: {{.Name}}
|
||||
parent: Data Sources
|
||||
subcategory: Virtual Environment
|
||||
description: |-
|
||||
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
|
||||
---
|
||||
|
||||
# {{.Type}}: {{.Name}}
|
||||
|
||||
{{ .Description | trimspace }}
|
||||
|
||||
{{ if .HasExample -}}
|
||||
## Example Usage
|
||||
|
||||
{{ printf "{{tffile %q}}" .ExampleFile }}
|
||||
{{- end }}
|
||||
|
||||
{{ .SchemaMarkdown | trimspace }}
|
28
templates/resources.md.tmpl
Normal file
28
templates/resources.md.tmpl
Normal file
@ -0,0 +1,28 @@
|
||||
---
|
||||
layout: page
|
||||
title: {{.Name}}
|
||||
parent: Resources
|
||||
subcategory: Virtual Environment
|
||||
description: |-
|
||||
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
|
||||
---
|
||||
|
||||
# {{.Type}}: {{.Name}}
|
||||
|
||||
{{ .Description | trimspace }}
|
||||
|
||||
{{ if .HasExample -}}
|
||||
## Example Usage
|
||||
|
||||
{{ printf "{{tffile %q}}" .ExampleFile }}
|
||||
{{- end }}
|
||||
|
||||
{{ .SchemaMarkdown | trimspace }}
|
||||
{{- if .HasImport }}
|
||||
|
||||
## Import
|
||||
|
||||
Import is supported using the following syntax:
|
||||
|
||||
{{ printf "{{codefile \"shell\" %q}}" .ImportFile }}
|
||||
{{- end }}
|
@ -18,3 +18,16 @@ import (
|
||||
_ "github.com/goreleaser/goreleaser"
|
||||
_ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs"
|
||||
)
|
||||
|
||||
// Format Terraform code for use in documentation.
|
||||
// If you do not have Terraform installed, you can remove the formatting command, but it is suggested
|
||||
// to ensure the documentation is formatted properly.
|
||||
//go:generate terraform fmt -recursive ../examples/
|
||||
// Generate documentation.
|
||||
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate --provider-dir ../ --rendered-website-dir ./docs-gen
|
||||
|
||||
// Temporary: while migrating to the TF framework, we need to copy the generated docs to the right place
|
||||
// for the resources / data sources that have been migrated.
|
||||
//go:generate cp ../docs-gen/data-sources/virtual_environment_version.md ../docs/data-sources/
|
||||
//go:generate cp ../docs-gen/resources/virtual_environment_network_linux_bridge.md ../docs/resources/
|
||||
//go:generate cp ../docs-gen/resources/virtual_environment_network_linux_vlan.md ../docs/resources/
|
||||
|
Loading…
Reference in New Issue
Block a user