From ed76b665fe3923ceb5f939a328f47535bac98f9d Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Fri, 14 Oct 2022 16:17:29 +0800 Subject: [PATCH 1/2] add keys attributes for fluid relay server --- .../fluid_relay_servers_resource.go | 23 +++++++++++++++++++ .../fluid_relay_servers_resource_test.go | 1 + .../docs/r/fluid_relay_servers.html.markdown | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/internal/services/fluidrelay/fluid_relay_servers_resource.go b/internal/services/fluidrelay/fluid_relay_servers_resource.go index a130c5aa70ed..ee0ca09a7208 100644 --- a/internal/services/fluidrelay/fluid_relay_servers_resource.go +++ b/internal/services/fluidrelay/fluid_relay_servers_resource.go @@ -24,6 +24,8 @@ type ServerModel struct { Location string `tfschema:"location"` StorageSKU string `tfschema:"storage_sku"` FrsTenantId string `tfschema:"frs_tenant_id"` + PrimaryKey string `tfschema:"primary_key"` + SecondaryKey string `tfschema:"secondary_key"` OrdererEndpoints []string `tfschema:"orderer_endpoints"` StorageEndpoints []string `tfschema:"storage_endpoints"` ServiceEndpoints []string `tfschema:"service_endpoints"` @@ -112,6 +114,16 @@ func (s Server) Attributes() map[string]*pluginsdk.Schema { Type: pluginsdk.TypeString, }, }, + + "primary_key": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "secondary_key": { + Type: pluginsdk.TypeString, + Computed: true, + }, } } @@ -256,6 +268,17 @@ func (s Server) Read() sdk.ResourceFunc { if val, ok := meta.ResourceData.GetOk("storage_sku"); ok { output.StorageSKU = val.(string) } + + keyRes, err := client.ListKeys(ctx, *id) + if err != nil { + // do not return if only list keys error + meta.Logger.Warnf("retrieving relay server keys err: %v", err) + } + if keys := keyRes.Model; model != nil { + output.PrimaryKey = utils.NormalizeNilableString(keys.Key1) + output.SecondaryKey = utils.NormalizeNilableString(keys.Key2) + } + return meta.Encode(output) }, } diff --git a/internal/services/fluidrelay/fluid_relay_servers_resource_test.go b/internal/services/fluidrelay/fluid_relay_servers_resource_test.go index b677ba243c32..18bc12717f71 100644 --- a/internal/services/fluidrelay/fluid_relay_servers_resource_test.go +++ b/internal/services/fluidrelay/fluid_relay_servers_resource_test.go @@ -48,6 +48,7 @@ func TestAccFluidRelay_basic(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(f), check.That(data.ResourceName).Key("frs_tenant_id").IsUUID(), + check.That(data.ResourceName).Key("primary_key").Exists(), check.That(data.ResourceName).Key("orderer_endpoints.0").Exists(), check.That(data.ResourceName).Key("service_endpoints.#").Exists(), ), diff --git a/website/docs/r/fluid_relay_servers.html.markdown b/website/docs/r/fluid_relay_servers.html.markdown index a49d77ec3bca..05a73ce8494a 100644 --- a/website/docs/r/fluid_relay_servers.html.markdown +++ b/website/docs/r/fluid_relay_servers.html.markdown @@ -61,6 +61,10 @@ In addition to the Arguments listed above - the following Attributes are exporte * `frs_tenant_id` - The Fluid tenantId for this server. +* `primary_key` - The primary key for this server. + +* `secondary_key` - The secondary key for this server. + * `orderer_endpoints` - An array of the Fluid Relay Orderer endpoints. * `storage_endpoints` - An array of storage endpoints for this Fluid Relay Server. From 4a038b9e8c5142b9724a8eec1cd7a2599001484b Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Fri, 14 Oct 2022 21:25:02 +0800 Subject: [PATCH 2/2] code formate and sensitive --- .../fluidrelay/fluid_relay_servers_resource.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/services/fluidrelay/fluid_relay_servers_resource.go b/internal/services/fluidrelay/fluid_relay_servers_resource.go index ee0ca09a7208..8f79da9fb615 100644 --- a/internal/services/fluidrelay/fluid_relay_servers_resource.go +++ b/internal/services/fluidrelay/fluid_relay_servers_resource.go @@ -116,13 +116,15 @@ func (s Server) Attributes() map[string]*pluginsdk.Schema { }, "primary_key": { - Type: pluginsdk.TypeString, - Computed: true, + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, }, "secondary_key": { - Type: pluginsdk.TypeString, - Computed: true, + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, }, } } @@ -272,7 +274,7 @@ func (s Server) Read() sdk.ResourceFunc { keyRes, err := client.ListKeys(ctx, *id) if err != nil { // do not return if only list keys error - meta.Logger.Warnf("retrieving relay server keys err: %v", err) + meta.Logger.Warnf("retrieving keys for %s: %v", *id, err) } if keys := keyRes.Model; model != nil { output.PrimaryKey = utils.NormalizeNilableString(keys.Key1)