Skip to content

Commit

Permalink
feat(cloud-keystore): Adds cloud keystore data source to provider map
Browse files Browse the repository at this point in the history
Adds logs to cloud keystore data source
  • Loading branch information
rvelaVenafi committed May 16, 2024
1 parent 07913f8 commit 5cc82ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
18 changes: 13 additions & 5 deletions venafi/data_source_cloudkeystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"context"
"fmt"

"github.com/Venafi/vcert/v5/pkg/endpoint"
"github.com/Venafi/vcert/v5/pkg/venafi/cloud"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/Venafi/vcert/v5/pkg/endpoint"
"github.com/Venafi/vcert/v5/pkg/venafi/cloud"
)

const (
cloudKeystoreProviderID = "provider_id"
cloudKeystoreProviderID = "cloud_provider_id"
cloudKeystoreName = "name"
cloudKeystoreType = "type"
cloudKeystoreMachineIdentitiesCount = "machine_identities_count"
Expand Down Expand Up @@ -59,16 +61,22 @@ func dataSourceCloudKeystoreRead(ctx context.Context, d *schema.ResourceData, me

providerID := d.Get(cloudKeystoreProviderID).(string)
keystoreName := d.Get(cloudKeystoreName).(string)

tflog.Info(ctx, "reading cloud keystore", map[string]interface{}{
cloudKeystoreProviderID: providerID,
cloudKeystoreName: keystoreName,
})
keystore, err := connector.(*cloud.Connector).GetCloudKeystoreByName(providerID, keystoreName)
if err != nil {
return diag.FromErr(err)
}

d.SetId(keystore.ID)

err = d.Set(cloudKeystoreType, keystore.Type)
err = d.Set(cloudKeystoreMachineIdentitiesCount, keystore.MachineIdentitiesCount)

tflog.Info(ctx, "cloud keystore found", map[string]interface{}{
cloudKeystoreProviderID: providerID,
cloudKeystoreName: keystoreName,
})
return nil
}
14 changes: 0 additions & 14 deletions venafi/data_source_cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,13 @@ func dataSourceCloudProviderRead(ctx context.Context, d *schema.ResourceData, me
}

cpName := d.Get(cloudProviderName)
if cpName == nil {
return buildStandardDiagError("cloud provider name not provided")
}

tflog.Info(ctx, "reading cloud provider", map[string]interface{}{"name": cpName})
cpObject, err := connector.(*cloud.Connector).GetCloudProviderByName(cpName.(string))
if err != nil {
return diag.FromErr(err)
}

tflog.Debug(ctx, "cloud provider details", map[string]interface{}{
"id": cpObject.ID,
"name": cpObject.Name,
"type": cpObject.Type,
"status": cpObject.Status,
"status_details": cpObject.StatusDetails,
"keystores_count": cpObject.KeystoresCount,
})

d.SetId(cpObject.ID)

err = d.Set(cloudProviderType, cpObject.Type)
if err != nil {
return diag.FromErr(err)
Expand Down
6 changes: 5 additions & 1 deletion venafi/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const (
providerTrustBundle = "trust_bundle"
providerClientID = "client_id"
providerSkipRetirement = "skip_retirement"

dataSourceCloudProvider = "venafi_cloud_provider"
dataSourceCloudKeystore = "venafi_cloud_keystore"
)

var (
Expand Down Expand Up @@ -183,7 +186,8 @@ Example:
"venafi_ssh_config": resourceVenafiSshConfig(),
},
DataSourcesMap: map[string]*schema.Resource{
"venafi_cloud_provider": DataSourceCloudProvider(),
dataSourceCloudProvider: DataSourceCloudProvider(),
dataSourceCloudKeystore: DataSourceCloudKeystore(),
},
ConfigureContextFunc: providerConfigure,
}
Expand Down

0 comments on commit 5cc82ed

Please sign in to comment.