Skip to content

Commit

Permalink
ReadAccessKey instead of ReadSecretAccessKey
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-rce committed Jul 30, 2024
1 parent 5cfbd16 commit d9338f8
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions outscale/resource_outscale_access_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func ResourceOutscaleAccessKeyCreate(d *schema.ResourceData, meta interface{}) e

d.SetId(*resp.GetAccessKey().AccessKeyId)

if err := d.Set("secret_key", *resp.GetAccessKey().SecretKey); err != nil {
return err
}

if d.Get("state").(string) != "ACTIVE" {
if err := updateAccessKey(conn, d.Id(), "INACTIVE"); err != nil {
return err
Expand All @@ -104,12 +108,17 @@ func ResourceOutscaleAccessKeyCreate(d *schema.ResourceData, meta interface{}) e
func ResourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*OutscaleClient).OSCAPI

filter := oscgo.ReadSecretAccessKeyRequest{
AccessKeyId: d.Id(),
filter := oscgo.FiltersAccessKeys{
AccessKeyIds: &[]string{d.Id()},
}

req := oscgo.ReadAccessKeysRequest{
Filters: &filter,
}
var resp oscgo.ReadSecretAccessKeyResponse

var resp oscgo.ReadAccessKeysResponse
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
rp, httpResp, err := conn.AccessKeyApi.ReadSecretAccessKey(context.Background()).ReadSecretAccessKeyRequest(filter).Execute()
rp, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(req).Execute()
if err != nil {
return utils.CheckThrottling(httpResp, err)
}
Expand All @@ -121,28 +130,26 @@ func ResourceOutscaleAccessKeyRead(d *schema.ResourceData, meta interface{}) err
return err
}

accessKey, ok := resp.GetAccessKeyOk()
if !ok {
accessKey := resp.GetAccessKeys()
if len(accessKey) == 0 {
d.SetId("")
return nil
}

if err := d.Set("access_key_id", accessKey.GetAccessKeyId()); err != nil {
if err := d.Set("access_key_id", accessKey[0].GetAccessKeyId()); err != nil {
return err
}
if err := d.Set("creation_date", accessKey.GetCreationDate()); err != nil {
if err := d.Set("creation_date", accessKey[0].GetCreationDate()); err != nil {
return err
}
if err := d.Set("expiration_date", accessKey.GetExpirationDate()); err != nil {
if err := d.Set("expiration_date", accessKey[0].GetExpirationDate()); err != nil {
return err
}
if err := d.Set("last_modification_date", accessKey.GetLastModificationDate()); err != nil {
if err := d.Set("last_modification_date", accessKey[0].GetLastModificationDate()); err != nil {
return err
}
if err := d.Set("secret_key", accessKey.GetSecretKey()); err != nil {
return err
}
if err := d.Set("state", accessKey.GetState()); err != nil {

if err := d.Set("state", accessKey[0].GetState()); err != nil {
return err
}

Expand Down

0 comments on commit d9338f8

Please sign in to comment.