Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for plugin framework #5573

Open
wants to merge 32 commits into
base: tfplugin
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b307de5
initial changes
uibm Jul 25, 2024
8210473
fixed provider mismatch issue.
uibm Jul 26, 2024
bfc68f6
fixed ssh key issue
uibm Jul 27, 2024
31429bb
Merge branch 'master' into tfplugin-ujjwal
uibm Aug 22, 2024
788b54b
updated go.mod
uibm Aug 22, 2024
975a322
accepted changes
uibm Aug 22, 2024
975957d
Merge branch 'master' into tfplugin-ujjwal
uibm Aug 22, 2024
51a4994
go mod changes
uibm Aug 22, 2024
5316673
updated go mod
uibm Sep 2, 2024
d58663e
Merge branch 'master' into tfplugin-ujjwal
uibm Sep 2, 2024
8b2ba19
updated go mod
uibm Sep 2, 2024
3caf3ae
Update resource_ibm_is_ssh_keys_new.go
uibm Sep 2, 2024
1639180
cleaned extra code
uibm Sep 2, 2024
8314806
Merge branch 'master' into tfplugin-ujjwal
uibm Nov 12, 2024
1db70a6
Update structures.go
uibm Nov 12, 2024
569cfd2
Update resource_ibm_is_ssh_keys_new.go
uibm Nov 12, 2024
9edecaa
test updates
uibm Nov 12, 2024
7e15f9c
Create resource_ibm_is_ssh_keys_new_test.go
uibm Nov 12, 2024
ebe2fc1
added datasource support
uibm Nov 25, 2024
110f38e
Update data_source_ibm_is_ssh_key_new.go
uibm Nov 26, 2024
bfd9583
some changes
uibm Nov 26, 2024
396f1ad
import fix
uibm Nov 27, 2024
a11225a
go mod update
uibm Nov 27, 2024
01847fa
resolved import issue
uibm Dec 10, 2024
dd72725
updated the imports
uibm Dec 11, 2024
65a7ce9
Update resource_ibm_is_instance.go
uibm Dec 11, 2024
ec07fe3
Update structures.go
uibm Dec 11, 2024
2e38a80
Merge branch 'master' into tfplugin-ujjwal
uibm Dec 16, 2024
f215dad
updated
uibm Dec 16, 2024
afb1636
updated all migration imports
uibm Dec 16, 2024
70ed1f6
fixed errors
uibm Dec 16, 2024
f2b98dc
fixed go sum
uibm Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some changes
uibm committed Nov 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit bfd958362c643fb6b4b3f6de61cd32bdf602bde1
92 changes: 0 additions & 92 deletions ibm/acctest/accframeworktest.go

This file was deleted.

59 changes: 59 additions & 0 deletions ibm/acctest/acctestframework.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package acctest

import (
"context"
"os"
"sync"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
)

func init() {
testlogger := os.Getenv("TF_LOG")
if testlogger != "" {
os.Setenv("IBMCLOUD_BLUEMIX_GO_TRACE", "true")
}
}

var (
// ProtoV6ProviderFactories 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.
ProtoV6ProviderFactories map[string]func() (tfprotov6.ProviderServer, error) = protoV6ProviderFactoriesInit(context.Background(), ProviderName)

// testAccProviderConfigure ensures Provider is only configured once
)

// testAccProviderConfigure ensures Provider is only configured once
//
// The PreCheck(t) function is invoked for every test and this prevents
// extraneous reconfiguration to the same values each time. However, this does
// not prevent reconfiguration that may happen should the address of
// Provider be errantly reused in ProviderFactories.
var testAccProviderFrameworkConfigure sync.Once

func protoV6ProviderFactoriesInit(ctx context.Context, providerNames ...string) map[string]func() (tfprotov6.ProviderServer, error) {
// Initialize logging
if testlogger := os.Getenv("TF_LOG"); testlogger != "" {
os.Setenv("IBMCLOUD_BLUEMIX_GO_TRACE", "true")
}
factories := make(map[string]func() (tfprotov6.ProviderServer, error), len(providerNames))

for _, name := range providerNames {
factories[name] = func() (tfprotov6.ProviderServer, error) {
providerServerFactory, _, err := provider.ProtoV6ProviderServerFactory(ctx)

if err != nil {
return nil, err
}

return providerServerFactory(), nil
}
}

return factories
}
41 changes: 41 additions & 0 deletions ibm/provider/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package provider

import (
"context"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/version"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"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"
)

// ProtoV6ProviderServerFactory returns a muxed terraform-plugin-go protocol v6 provider factory function.
// This factory function is suitable for use with the terraform-plugin-go Serve function.
// The primary (Plugin SDK) provider server is also returned (useful for testing).
func ProtoV6ProviderServerFactory(ctx context.Context) (func() tfprotov6.ProviderServer, *schema.Provider, error) {
primary := New(version.Version)()
upgradedSdkServer, err := tf5to6server.UpgradeServer(
ctx,
primary.GRPCProvider,
)
if err != nil {
log.Fatal(err)
}

frameworkServer := providerserver.NewProtocol6(NewFrameworkProvider(version.Version)())

muxServer, err := tf6muxserver.NewMuxServer(
ctx,
func() tfprotov6.ProviderServer { return upgradedSdkServer },
frameworkServer,
)
if err != nil {
log.Fatal(err)
}
return muxServer.ProviderServer, primary, nil
}
24 changes: 24 additions & 0 deletions ibm/provider/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package provider_test

import (
"context"
"testing"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider"
)

// go test -bench=BenchmarkProtoV6ProviderServerFactory -benchtime 1x -benchmem -run=Bench -v ./internal/provider
func BenchmarkProtoV6ProviderServerFactory(b *testing.B) {
_, p, err := provider.ProtoV6ProviderServerFactory(context.Background())

if err != nil {
b.Fatal(err)
}

if b.N == 1 {
b.Logf("%d resources, %d data sources", len(p.ResourcesMap), len(p.DataSourcesMap))
}
}
2 changes: 2 additions & 0 deletions ibm/provider/helpers.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package provider

import (
2 changes: 2 additions & 0 deletions ibm/provider/provider_framework.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright IBM Corp. 2024 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package provider

import (
52 changes: 52 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_ssh_key_new_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package vpc_test

import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

// Test SSH Key data
const (
rsaPublicKey = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR \n`
ed25519PublicKey = `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILw6jUMh6BHClr2dUV1LHHKBQQKyTDZvY/0BSPDQmzWo \n`
)

func TestAccVPCIsSshKeyNewDatasource(t *testing.T) {
dataSourceAddress := "data.ibm_is_ssh_key_new.this"
name1 := fmt.Sprintf("tfssh-name-%d", 10)
// publicKey := strings.TrimSpace(`
// ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
// `)
keytype := "ed25519"
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.ProtoV6ProviderFactories,
// PreCheck: func() { acc.TestAccPreCheck(t) },
// CheckDestroy: testAccCheckGroupDestroy(t, groupName),
Steps: []resource.TestStep{
{
Config: testAccVPCIsSshKeyDatasourceConfig(name1, ed25519PublicKey, keytype),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceAddress, "id"),
resource.TestCheckResourceAttrSet(dataSourceAddress, "href"),
resource.TestCheckResourceAttrSet(dataSourceAddress, "crn"),
),
},
},
})
}

func testAccVPCIsSshKeyDatasourceConfig(name, publickey, keytype string) string {
return fmt.Sprintf(`
resource ibm_is_ssh_key_new ed25519 {
name = "%s"
public_key = "%s"
type = "%s"
}
data ibm_is_ssh_key_new this {
name = ibm_is_ssh_key_new.ed25519.name
}
`, name, publickey, keytype)
}
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

@@ -20,8 +20,8 @@ func TestAccIBMIsSSHKey_RSA(t *testing.T) {
var sshKeyName = fmt.Sprintf("tf-acc-test-rsa-%d", time.Now().Unix())

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccFrameworkPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccFrameworkPreCheck(t) },
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccIBMIsSSHKeyConfigRSA(sshKeyName),
@@ -77,8 +77,8 @@ func TestAccIBMIsSSHKey_ED25519(t *testing.T) {

// Configuration generation functions
func testAccIBMIsSSHKeyConfigRSA(name string) string {
return acctest.ConfigCompose(
acctest.ConfigureProvider(acctest.Region()),
return acc.ConfigCompose(
acc.ConfigureProvider(acctest.Region()),
fmt.Sprintf(`
resource "ibm_is_ssh_key_new" "rsa" {
name = %q