Skip to content

Commit

Permalink
chore: bump tf protocol to version 6 (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
villevsv-upcloud authored Oct 28, 2024
1 parent ca18244 commit fdb3a6f
Show file tree
Hide file tree
Showing 41 changed files with 118 additions and 178 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Changed

- Terraform: Introduce support for Terraform protocol version 6. Protocol version 6 requires Terraform CLI version 1.0 and later.

## [5.13.2] - 2024-10-25

### Fixed
Expand Down
74 changes: 2 additions & 72 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Developing the Provider
## Requirements

* [Terraform](https://www.terraform.io/downloads.html) 0.12.x or later
* [Terraform](https://www.terraform.io/downloads.html) 1.0.0 or later
* [Go](https://golang.org/doc/install) > 1.14

Get the provider source code:
Expand Down Expand Up @@ -184,74 +184,4 @@ docker start -ai <container ID here>
UpCloud provider can be run in debug mode using a debugger such as Delve.
For more information, see [Terraform docs](https://www.terraform.io/docs/extend/debugging.html#starting-a-provider-in-debug-mode)

Environment variables `UPCLOUD_DEBUG_API_BASE_URL` and `UPCLOUD_DEBUG_SKIP_CERTIFICATE_VERIFY` can be used for HTTP client debugging purposes. More information can be found in the client's [README](https://github.com/UpCloudLtd/upcloud-go-api/blob/986ca6da9ca85ff51ecacc588215641e2e384cfa/README.md#debugging) file.

## Consuming local provider with Terraform 0.12.0

With the release of Terraform 0.13.0 the discovery of a locally built provider
binary has changed. These changes have been made to allow all providers to be
discovered from public and provider registries.

The UpCloud makefile supports the old, Terraform 0.12 style where plugin
directory structure is not relevant and only the binary name matters.

The following make command can be executed to build and place the provider in
the Go binary directory. Make sure your PATH includes the Go binary directory.

```sh
make build_0_12
```

After the provider has been built and can be executed, you can then use
standard terraform commands as normal.

### Using local provider with Terraform 0.12 or earlier

```terraform
# configure the provider
provider "upcloud" {
# Your UpCloud credentials are read from the environment variables:
# export UPCLOUD_USERNAME="Username of your UpCloud API user"
# export UPCLOUD_PASSWORD="Password of your UpCloud API user"
}
# create a server
resource "upcloud_server" "example" {
hostname = "terraform.example.tld"
zone = "de-fra1"
plan = "1xCPU-1GB"
# Declare network interfaces
network_interface {
type = "public"
}
network_interface {
type = "utility"
}
# Include at least one public SSH key
login {
user = "terraform"
keys = [
"<YOUR SSH PUBLIC KEY>",
]
create_password = false
}
# Provision the server with Ubuntu
template {
storage = "Ubuntu Server 20.04 LTS (Focal Fossa)"
# Use all the space allotted by the selected simple plan
size = 25
# Enable backups
backup_rule {
interval = "daily"
time = "0100"
retention = 8
}
}
}
```
Environment variables `UPCLOUD_DEBUG_API_BASE_URL` and `UPCLOUD_DEBUG_SKIP_CERTIFICATE_VERIFY` can be used for HTTP client debugging purposes. More information can be found in the client's [README](https://github.com/UpCloudLtd/upcloud-go-api/blob/986ca6da9ca85ff51ecacc588215641e2e384cfa/README.md#debugging) file.
3 changes: 0 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ build: fmtcheck
generate:
go generate ./...

build_0_12: fmtcheck
go install

test: fmtcheck
go test $(TEST) || exit 1
echo $(TEST) | \
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ provider "upcloud" {

### Requirements

* [Terraform](https://www.terraform.io/downloads.html) 0.12.x or later
* [Terraform](https://www.terraform.io/downloads.html) 1.0.0 or later


It's recommended to configure your credentials using environment variable:
Expand All @@ -90,7 +90,7 @@ permissions for increased security:
create the sub-account

Below is an example configuration on how to create a server using the Terraform
provider with Terraform 0.13 or later:
provider with Terraform 1.0.0 or later:

```terraform
# set the provider version
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"

"github.com/UpCloudLtd/terraform-provider-upcloud/upcloud"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server"
"github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server"
)

func main() {
Expand All @@ -19,13 +19,13 @@ func main() {
log.Fatal(err)
}

var serveOpts []tf5server.ServeOpt
var serveOpts []tf6server.ServeOpt

if debug {
serveOpts = append(serveOpts, tf5server.WithManagedDebug())
serveOpts = append(serveOpts, tf6server.WithManagedDebug())
}

err = tf5server.Serve(
err = tf6server.Serve(
"registry.terraform.io/upcloudltd/upcloud",
factory,
serveOpts...,
Expand Down
2 changes: 1 addition & 1 deletion upcloud/datasource_upcloud_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAccUpCloudHosts_basic(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceUpCloudHostsConfigEmpty(),
Expand Down
2 changes: 1 addition & 1 deletion upcloud/datasource_upcloud_ip_addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestAccDataSourceUpCloudIPAddresses_basic(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceUpCloudIPAddressesConfigEmpty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestAccDataSourceUpcloudManagedDatabaseMySQLSessions(t *testing.T) {
name := "data.upcloud_managed_database_mysql_sessions.mysql_sessions"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataS1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccDataSourceUpcloudManagedDatabaseOpenSearchIndices(t *testing.T) {
}
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataS1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestAccDataSourceUpcloudManagedDatabasePostgreSQLSessions(t *testing.T) {
name := "data.upcloud_managed_database_postgresql_sessions.postgresql_sessions"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataS1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestAccDataSourceUpcloudManagedDatabaseRedisSessions(t *testing.T) {
name := "data.upcloud_managed_database_redis_sessions.redis_sessions"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataS1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestAccDataSourceUpcloudManagedObjectStoragePolicies(t *testing.T) {
name := "data.upcloud_managed_object_storage_policies.this"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataS1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestAccDataSourceUpcloudManagedObjectStorageRegions(t *testing.T) {
name := "data.upcloud_managed_object_storage_regions.this"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataS1,
Expand Down
6 changes: 3 additions & 3 deletions upcloud/datasource_upcloud_networks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestAccUpCloudNetworksNoZone(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccNetworksConfig("", ""),
Expand All @@ -29,7 +29,7 @@ func TestAccUpCloudNetworksNoZone(t *testing.T) {
func TestAccUpCloudNetworksWithZone(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccNetworksConfig("fi-hel1", ""),
Expand All @@ -42,7 +42,7 @@ func TestAccUpCloudNetworksWithZone(t *testing.T) {
func TestAccUpCloudNetworksWithFilter(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccNetworksConfig("", "^Public.*"),
Expand Down
2 changes: 1 addition & 1 deletion upcloud/datasource_upcloud_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestAccDataSourceUpCloudStorage(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: dataSourceUpCloudStorageTestTemplateConfig(),
Expand Down
2 changes: 1 addition & 1 deletion upcloud/datasource_upcloud_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccDataSourceUpCloudTags_basic(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceUpCloudTagsConfigEmpty(tagName),
Expand Down
2 changes: 1 addition & 1 deletion upcloud/datasource_upcloud_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestAccDataSourceUpCloudZone_basic(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: steps,
})
}
8 changes: 4 additions & 4 deletions upcloud/datasource_upcloud_zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccDataSourceUpCloudZones_default(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceUpCloudZonesConfigEmpty(),
Expand All @@ -39,7 +39,7 @@ func TestAccDataSourceUpCloudZones_public(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceUpCloudZonesConfigFilter(filterType),
Expand All @@ -59,7 +59,7 @@ func TestAccDataSourceUpCloudZones_private(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceUpCloudZonesConfigFilter(filterType),
Expand All @@ -78,7 +78,7 @@ func TestAccDataSourceUpCloudZones_all(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
ProtoV6ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceUpCloudZonesConfigFilter(filterType),
Expand Down
25 changes: 17 additions & 8 deletions upcloud/muxserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-mux/tf5muxserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
)

func NewProviderServerFactory() (func() tfprotov5.ProviderServer, error) {
providers := []func() tfprotov5.ProviderServer{
providerserver.NewProtocol5(New()),
Provider().GRPCProvider,
func NewProviderServerFactory() (func() tfprotov6.ProviderServer, error) {
ctx := context.Background()

s, err := tf5to6server.UpgradeServer(ctx, Provider().GRPCProvider)
if err != nil {
return nil, err
}

ctx := context.Background()
muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...)
providers := []func() tfprotov6.ProviderServer{
providerserver.NewProtocol6(New()),
func() tfprotov6.ProviderServer {
return s
},
}

muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions upcloud/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

const debianTemplateUUID = "01000000-0000-4000-8000-000020070100"

var (
testAccProviderFactories map[string]func() (tfprotov5.ProviderServer, error)
testAccProviderFactories map[string]func() (tfprotov6.ProviderServer, error)
testAccProvider *schema.Provider
)

func init() {
testAccProvider = Provider()
testAccProviderFactories = make(map[string]func() (tfprotov5.ProviderServer, error))
testAccProviderFactories = make(map[string]func() (tfprotov6.ProviderServer, error))

testAccProviderFactories["upcloud"] = func() (tfprotov5.ProviderServer, error) {
testAccProviderFactories["upcloud"] = func() (tfprotov6.ProviderServer, error) {
factory, err := NewProviderServerFactory()
return factory(), err
}
Expand Down
Loading

0 comments on commit fdb3a6f

Please sign in to comment.