Skip to content

WIP: Update naming to reflect new apis #103

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/acctest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: Run acceptance tests
runs-on: ubuntu-latest
env:
ACC_TEST_SERVICE_ACCOUNT: ${{ secrets.ACC_TEST_SERVICE_ACCOUNT }}
E2E_TEST_ORG_OAUTH: ${{ secrets.E2E_TEST_ORG_OAUTH }}
GLOBAL_DEFAULT_API_SERVER: https://api.test.cloud.gcp.streamnative.dev
GLOBAL_DEFAULT_AUDIENCE: https://api.test.cloud.gcp.streamnative.dev
GLOBAL_DEFAULT_ISSUER: https://auth.test.cloud.gcp.streamnative.dev/
Expand Down Expand Up @@ -55,6 +55,6 @@ jobs:

- name: Run Acceptance Tests for the Provider
run: |
echo $ACC_TEST_SERVICE_ACCOUNT > $HOME/service_account.json
echo $E2E_TEST_ORG_OAUTH > $HOME/service_account.json
export KEY_FILE_PATH=$HOME/service_account.json
make testacc
12 changes: 5 additions & 7 deletions cloud/apikey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ func TestApiKey(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testResourceDataSourceApiKey(
"sndev",
orgId,
apiKeyGeneratedName,
"shared-gcp",
"streamnative",
cloudConnectionName,
"us-central1", "rapid"),
Check: resource.ComposeTestCheckFunc(
testCheckApiKeyExists("streamnative_apikey.test-terraform-api-key"),
Expand Down Expand Up @@ -111,16 +110,15 @@ func testCheckApiKeyExists(resourceName string) resource.TestCheckFunc {
}
}

func testResourceDataSourceApiKey(organization, name, poolName, poolNamespace, location, releaseChannel string) string {
func testResourceDataSourceApiKey(organization, name, cloudConnectionName, location, releaseChannel string) string {
return fmt.Sprintf(`
provider "streamnative" {
}
resource "streamnative_pulsar_instance" "test-api-key-pulsar-instance" {
organization = "%s"
name = "%s"
availability_mode = "zonal"
pool_name = "%s"
pool_namespace = "%s"
cloud_connection_name = "%s"
type = "dedicated"
}
resource "streamnative_pulsar_cluster" "test-api-key-pulsar-cluster" {
Expand Down Expand Up @@ -170,5 +168,5 @@ data "streamnative_apikey" "test-terraform-api-key" {
name = streamnative_apikey.test-terraform-api-key.name
private_key = streamnative_apikey.test-terraform-api-key.private_key
}
`, organization, name, poolName, poolNamespace, organization, name, name, location, releaseChannel, organization, name, name)
`, organization, name, cloudConnectionName, organization, name, name, location, releaseChannel, organization, name, name)
}
5 changes: 4 additions & 1 deletion cloud/data_source_apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import (
"context"
"encoding/base64"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/lestrrat-go/jwx/v2/jwa"
"github.com/lestrrat-go/jwx/v2/jwe"
"github.com/streamnative/terraform-provider-streamnative/cloud/util"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
)

func dataSourceApiKey() *schema.Resource {
Expand Down Expand Up @@ -60,6 +61,7 @@ func dataSourceApiKey() *schema.Resource {
"private_key": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: descriptions["private_key"],
},
"instance_name": {
Expand All @@ -80,6 +82,7 @@ func dataSourceApiKey() *schema.Resource {
"token": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: descriptions["token"],
},
"ready": {
Expand Down
5 changes: 5 additions & 0 deletions cloud/data_source_pulsar_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func dataSourcePulsarCluster() *schema.Resource {
func dataSourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
namespace := d.Get("organization").(string)
name := d.Get("name").(string)
instanceName := d.Get("instance_name").(string)
clientSet, err := getClientSet(getFactoryFromMeta(meta))
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_INIT_CLIENT_ON_READ_PULSAR_CLUSTER: %w", err))
Expand Down Expand Up @@ -366,6 +367,10 @@ func dataSourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, me
if releaseChannel != "" {
_ = d.Set("release_channel", releaseChannel)
}

if instanceName != "" {
_ = d.Set("instance_name", instanceName)
}
d.SetId(fmt.Sprintf("%s/%s", pulsarCluster.Namespace, pulsarCluster.Name))
return nil
}
2 changes: 2 additions & 0 deletions cloud/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var (
testAccProvider *schema.Provider
testAccProviderFactories map[string]func() (*schema.Provider, error)
)
var orgId = "o-q77cp"
var cloudConnectionName = "terraform-provider-test-gcp"

func init() {
testAccProvider = Provider()
Expand Down
44 changes: 18 additions & 26 deletions cloud/pulsar_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ func TestPulsarCluster(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testResourceDataSourcePulsarCluster(
"sndev",
orgId,
clusterGeneratedName,
"shared-gcp",
"streamnative",
cloudConnectionName,
"us-central1", "rapid"),
Check: resource.ComposeTestCheckFunc(
testCheckPulsarClusterExists("streamnative_pulsar_cluster.test-pulsar-cluster"),
Expand All @@ -64,10 +63,9 @@ func TestPulsarClusterNoConfig(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testResourceDataSourcePulsarClusterWithoutConfig(
"sndev",
orgId,
clusterGeneratedName,
"shared-gcp",
"streamnative",
cloudConnectionName,
"us-central1", "rapid"),
Check: resource.ComposeTestCheckFunc(
testCheckPulsarClusterExists("streamnative_pulsar_cluster.test-pulsar-cluster"),
Expand Down Expand Up @@ -150,21 +148,19 @@ func TestPulsarClusterConfigDrift(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testResourceDataSourcePulsarCluster(
"sndev",
orgId,
clusterGeneratedName,
"shared-gcp",
"streamnative",
cloudConnectionName,
"us-central1", "rapid"),
Check: resource.ComposeTestCheckFunc(
testCheckPulsarClusterExists("streamnative_pulsar_cluster.test-pulsar-cluster"),
),
},
{
Config: testResourceDataSourcePulsarCluster(
"sndev",
orgId,
clusterGeneratedName,
"shared-gcp",
"streamnative",
cloudConnectionName,
"us-central1", "rapid"),
PlanOnly: true,
ExpectNonEmptyPlan: false,
Expand All @@ -184,21 +180,19 @@ func TestPulsarClusterNoConfigConfigDrift(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testResourceDataSourcePulsarClusterWithoutConfig(
"sndev",
orgId,
clusterGeneratedName,
"shared-gcp",
"streamnative",
cloudConnectionName,
"us-central1", "rapid"),
Check: resource.ComposeTestCheckFunc(
testCheckPulsarClusterExists("streamnative_pulsar_cluster.test-pulsar-cluster"),
),
},
{
Config: testResourceDataSourcePulsarClusterWithoutConfig(
"sndev",
orgId,
clusterGeneratedName,
"shared-gcp",
"streamnative",
cloudConnectionName,
"us-central1", "rapid"),
PlanOnly: true,
ExpectNonEmptyPlan: false,
Expand All @@ -207,16 +201,15 @@ func TestPulsarClusterNoConfigConfigDrift(t *testing.T) {
})
}

func testResourceDataSourcePulsarCluster(organization, name, poolName, poolNamespace, location, releaseChannel string) string {
func testResourceDataSourcePulsarCluster(organization, name, cloudEnvironmentName, location, releaseChannel string) string {
return fmt.Sprintf(`
provider "streamnative" {
}
resource "streamnative_pulsar_instance" "test-pulsar-instance" {
organization = "%s"
name = "%s"
availability_mode = "zonal"
pool_name = "%s"
pool_namespace = "%s"
cloud_connection_name = "%s"
type = "dedicated"
}
resource "streamnative_pulsar_cluster" "test-pulsar-cluster" {
Expand Down Expand Up @@ -249,19 +242,18 @@ data "streamnative_pulsar_cluster" "test-pulsar-cluster" {
organization = streamnative_pulsar_cluster.test-pulsar-cluster.organization
name = streamnative_pulsar_cluster.test-pulsar-cluster.name
}
`, organization, name, poolName, poolNamespace, organization, name, name, location, releaseChannel)
`, organization, name, cloudEnvironmentName, organization, name, name, location, releaseChannel)
}

func testResourceDataSourcePulsarClusterWithoutConfig(organization, name, poolName, poolNamespace, location, releaseChannel string) string {
func testResourceDataSourcePulsarClusterWithoutConfig(organization, name, cloudEnvironmentName, location, releaseChannel string) string {
return fmt.Sprintf(`
provider "streamnative" {
}
resource "streamnative_pulsar_instance" "test-pulsar-instance" {
organization = "%s"
name = "%s"
availability_mode = "zonal"
pool_name = "%s"
pool_namespace = "%s"
cloud_connection_name = "%s"
type = "dedicated"
}
resource "streamnative_pulsar_cluster" "test-pulsar-cluster" {
Expand All @@ -277,5 +269,5 @@ data "streamnative_pulsar_cluster" "test-pulsar-cluster" {
organization = streamnative_pulsar_cluster.test-pulsar-cluster.organization
name = streamnative_pulsar_cluster.test-pulsar-cluster.name
}
`, organization, name, poolName, poolNamespace, organization, name, name, location, releaseChannel)
`, organization, name, cloudEnvironmentName, organization, name, name, location, releaseChannel)
}
12 changes: 5 additions & 7 deletions cloud/pulsar_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ func TestPulsarInstance(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testResourceDataSourcePulsarInstance(
"sndev",
orgId,
"terraform-test-pulsar-instance-b",
"zonal",
"shared-gcp",
"streamnative"),
cloudConnectionName),
Check: resource.ComposeTestCheckFunc(
testCheckPulsarInstanceExists("streamnative_pulsar_instance.test-pulsar-instance"),
),
Expand Down Expand Up @@ -116,21 +115,20 @@ func testCheckPulsarInstanceExists(name string) resource.TestCheckFunc {
}

func testResourceDataSourcePulsarInstance(
organization string, name string, availabilityMode string, poolName string, poolNamespace string) string {
organization string, name string, availabilityMode string, cloudConnectionName string) string {
return fmt.Sprintf(`
provider "streamnative" {
}
resource "streamnative_pulsar_instance" "test-pulsar-instance" {
organization = "%s"
name = "%s"
availability_mode = "%s"
pool_name = "%s"
pool_namespace = "%s"
cloud_connection_name = "%s"
}
data "streamnative_pulsar_instance" "test-pulsar-instance" {
depends_on = [streamnative_pulsar_instance.test-pulsar-instance]
name = streamnative_pulsar_instance.test-pulsar-instance.name
organization = streamnative_pulsar_instance.test-pulsar-instance.organization
}
`, organization, name, availabilityMode, poolName, poolNamespace)
`, organization, name, availabilityMode, cloudConnectionName)
}
5 changes: 5 additions & 0 deletions cloud/resource_cloud_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func resourceCloudEnvironment() *schema.Resource {
Description: descriptions["organization"],
ValidateFunc: validateNotBlank,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: descriptions["cloud_environment_name"],
},
"environment_type": {
Type: schema.TypeString,
Required: true,
Expand Down
26 changes: 13 additions & 13 deletions cloud/resource_pulsar_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func resourcePulsarCluster() *schema.Resource {
// Auto generate the name, so we don't need to check the diff.
return nil
}
if diff.HasChanges([]string{"organization", "name", "instance_name", "location", "pool_member_name", "release_channel"}...) {
if diff.HasChanges([]string{"organization", "name", "instance_name", "location", "cloud_environment_name", "release_channel"}...) {
return fmt.Errorf("ERROR_UPDATE_PULSAR_CLUSTER: " +
"The pulsar cluster organization, name, instance_name, location, pool_member_name does not support updates, please recreate it")
"The pulsar cluster organization, name, instance_name, location, cloud_environment_name does not support updates, please recreate it")
}
return nil
},
Expand Down Expand Up @@ -93,10 +93,10 @@ func resourcePulsarCluster() *schema.Resource {
Description: descriptions["location"],
ValidateFunc: validateNotBlank,
},
"pool_member_name": {
"cloud_environment_name": {
Type: schema.TypeString,
Optional: true,
Description: descriptions["pool_member_name"],
Description: descriptions["cloud_environment_name"],
ValidateFunc: validateNotBlank,
},
"release_channel": {
Expand Down Expand Up @@ -358,11 +358,11 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me
name := d.Get("name").(string)
displayName := d.Get("display_name").(string)
instanceName := d.Get("instance_name").(string)
pool_member_name := d.Get("pool_member_name").(string)
cloudEnvironmentName := d.Get("cloud_environment_name").(string)
location := d.Get("location").(string)
if pool_member_name == "" && location == "" {
if cloudEnvironmentName == "" && location == "" {
return diag.FromErr(fmt.Errorf("ERROR_CREATE_PULSAR_CLUSTER: " +
"either pool_member_name or location must be provided"))
"either cloud_environment_name or location must be provided"))
}
releaseChannel := d.Get("release_channel").(string)
bookieReplicas := int32(d.Get("bookie_replicas").(int))
Expand Down Expand Up @@ -391,17 +391,17 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me
brokerMem := resource.NewQuantity(int64(computeUnit*8*1024*1024*1024), resource.DecimalSI)
bookieMem := resource.NewQuantity(int64(storageUnit*8*1024*1024*1024), resource.DecimalSI)

if pool_member_name != "" {
if cloudEnvironmentName != "" {
// only allow BYOC user to select specific pool member
poolMember, err := clientSet.CloudV1alpha1().
PoolMembers(namespace).
Get(ctx, pool_member_name, metav1.GetOptions{})
Get(ctx, cloudEnvironmentName, metav1.GetOptions{})
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_GET_POOL_MEMBER_ON_CREATE_PULSAR_CLUSTER: %w", err))
return diag.FromErr(fmt.Errorf("ERROR_GET_CLOUD_ENVIRONMENT_ON_CREATE_PULSAR_CLUSTER: %w", err))
}
if poolMember.Spec.PoolName != pulsarInstance.Spec.PoolRef.Name {
return diag.FromErr(fmt.Errorf("ERROR_CREATE_PULSAR_CLUSTER: " +
"the pool member does not belong to the pool which pulsar instance is attached"))
"the cloud environment does not belong to the cloud connection that pulsar instance is attached to"))
}
}

Expand Down Expand Up @@ -466,9 +466,9 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me
if !ursaEnabled && !pulsarInstance.IsServerless() {
pulsarCluster.Spec.BookKeeper = bookkeeper
}
if pool_member_name != "" {
if cloudEnvironmentName != "" {
pulsarCluster.Spec.PoolMemberRef = cloudv1alpha1.PoolMemberReference{
Name: pool_member_name,
Name: cloudEnvironmentName,
Namespace: namespace,
}
} else {
Expand Down
Loading
Loading