Skip to content

Commit 8614ecf

Browse files
authored
Marks fields sensitive and use ForceNew (#106)
Hide sensitive fields Use Force New to allow users to replace a resource rather than erroring Add instance_name and token as readable values to match data source behaviour
1 parent 4986dac commit 8614ecf

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

cloud/data_source_apikey.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ import (
1818
"context"
1919
"encoding/base64"
2020
"fmt"
21+
"strings"
22+
2123
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
2224
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2325
"github.com/lestrrat-go/jwx/v2/jwa"
2426
"github.com/lestrrat-go/jwx/v2/jwe"
2527
"github.com/streamnative/terraform-provider-streamnative/cloud/util"
2628
apierrors "k8s.io/apimachinery/pkg/api/errors"
2729
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28-
"strings"
2930
)
3031

3132
func dataSourceApiKey() *schema.Resource {
@@ -60,6 +61,7 @@ func dataSourceApiKey() *schema.Resource {
6061
"private_key": {
6162
Type: schema.TypeString,
6263
Optional: true,
64+
Sensitive: true,
6365
Description: descriptions["private_key"],
6466
},
6567
"instance_name": {
@@ -80,6 +82,7 @@ func dataSourceApiKey() *schema.Resource {
8082
"token": {
8183
Type: schema.TypeString,
8284
Computed: true,
85+
Sensitive: true,
8386
Description: descriptions["token"],
8487
},
8588
"ready": {

cloud/data_source_pulsar_cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ func dataSourcePulsarCluster() *schema.Resource {
268268
func dataSourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
269269
namespace := d.Get("organization").(string)
270270
name := d.Get("name").(string)
271+
instanceName := d.Get("instance_name").(string)
271272
clientSet, err := getClientSet(getFactoryFromMeta(meta))
272273
if err != nil {
273274
return diag.FromErr(fmt.Errorf("ERROR_INIT_CLIENT_ON_READ_PULSAR_CLUSTER: %w", err))
@@ -366,6 +367,10 @@ func dataSourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, me
366367
if releaseChannel != "" {
367368
_ = d.Set("release_channel", releaseChannel)
368369
}
370+
371+
if instanceName != "" {
372+
_ = d.Set("instance_name", instanceName)
373+
}
369374
d.SetId(fmt.Sprintf("%s/%s", pulsarCluster.Namespace, pulsarCluster.Name))
370375
return nil
371376
}

cloud/resource_apikey.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ func resourceApiKey() *schema.Resource {
4545
// This is create event, so we don't need to check the diff.
4646
return nil
4747
}
48-
if diff.HasChange("name") ||
49-
diff.HasChange("organization") ||
50-
diff.HasChange("instance_name") ||
51-
diff.HasChange("service_account_name") ||
52-
diff.HasChange("expiration_time") {
53-
return fmt.Errorf("ERROR_UPDATE_API_KEY: " +
54-
"The api key does not support updates organization, " +
55-
"name, instance_name, service_account_name and expiration_time, please recreate it")
56-
}
5748
return nil
5849
},
5950
Importer: &schema.ResourceImporter{
@@ -76,28 +67,39 @@ func resourceApiKey() *schema.Resource {
7667
"organization": {
7768
Type: schema.TypeString,
7869
Required: true,
70+
ForceNew: true,
7971
Description: descriptions["organization"],
8072
ValidateFunc: validateNotBlank,
8173
},
8274
"name": {
8375
Type: schema.TypeString,
8476
Required: true,
77+
ForceNew: true,
8578
Description: descriptions["apikey_name"],
8679
ValidateFunc: validateNotBlank,
8780
},
8881
"instance_name": {
8982
Type: schema.TypeString,
9083
Required: true,
84+
ForceNew: true,
9185
Description: descriptions["instance_name"],
9286
},
87+
"token": {
88+
Type: schema.TypeString,
89+
Computed: true,
90+
Sensitive: true,
91+
Description: descriptions["token"],
92+
},
9393
"service_account_name": {
9494
Type: schema.TypeString,
9595
Required: true,
96+
ForceNew: true,
9697
Description: descriptions["service_account_name"],
9798
},
9899
"expiration_time": {
99100
Type: schema.TypeString,
100101
Optional: true,
102+
ForceNew: true,
101103
Description: descriptions["expiration_time"],
102104
},
103105
"revoke": {
@@ -128,6 +130,7 @@ func resourceApiKey() *schema.Resource {
128130
"private_key": {
129131
Type: schema.TypeString,
130132
Computed: true,
133+
Sensitive: true,
131134
Description: descriptions["private_key"],
132135
},
133136
"key_id": {

0 commit comments

Comments
 (0)