Skip to content
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

Read secrets access key #466

Merged
merged 3 commits into from
Aug 12, 2024
Merged
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
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/outscale/terraform-provider-outscale
go 1.22.0

require (
github.com/aws/aws-sdk-go v1.53.1
github.com/aws/aws-sdk-go v1.55.1
github.com/davecgh/go-spew v1.1.1
github.com/go-test/deep v1.0.6
github.com/hashicorp/errwrap v1.1.0
Expand All @@ -13,7 +13,7 @@ require (
github.com/hashicorp/terraform-plugin-mux v0.12.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/nav-inc/datetime v0.1.3
github.com/outscale/osc-sdk-go/v2 v2.19.0
github.com/outscale/osc-sdk-go/v2 v2.21.0
github.com/spf13/cast v1.6.0
)

Expand Down Expand Up @@ -58,11 +58,11 @@ require (
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJE
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/aws/aws-sdk-go v1.44.103/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go v1.53.1 h1:15/i0m9rE8r1q3P4ooHCfZTJtkxwG2Dwqp9JhPaVbs0=
github.com/aws/aws-sdk-go v1.53.1/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.55.1 h1:ZTNPmbRMxaK5RlTJrBullX9r/rF1MPf3yAJOLlwDiT8=
github.com/aws/aws-sdk-go v1.55.1/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
Expand Down Expand Up @@ -142,8 +142,8 @@ github.com/nav-inc/datetime v0.1.3 h1:PaybPUsScX+Cd3TEa1tYpfwU61deCEhMTlCO2hONm1
github.com/nav-inc/datetime v0.1.3/go.mod h1:gKGf5G+cW7qkTo5TC/sieNyz6lYdrA9cf1PNV+pXIOE=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/outscale/osc-sdk-go/v2 v2.19.0 h1:lunUeIB0AfklKztI4LH9yTIvG5t/fnRXVzSAZLX9EjY=
github.com/outscale/osc-sdk-go/v2 v2.19.0/go.mod h1:kzhtUErCzKYl87bZ+kDMphDafmnwbsyFJY9iHF7NgNE=
github.com/outscale/osc-sdk-go/v2 v2.21.0 h1:8MqhexV+ALG76CvY8EpuQlr0+hC5VFrWQY4fHqdT358=
github.com/outscale/osc-sdk-go/v2 v2.21.0/go.mod h1:kzhtUErCzKYl87bZ+kDMphDafmnwbsyFJY9iHF7NgNE=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -197,8 +197,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ=
golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA=
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -256,8 +256,8 @@ google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
7 changes: 1 addition & 6 deletions outscale/data_source_outscale_net_peerings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,12 @@ const testAccDataSourceOutscaleLinPeeringsConnectionConfig = `
accepter_net_id = outscale_net.outscale_net.net_id
source_net_id = outscale_net.outscale_net2.net_id
tags {
key = "okht"
key = "name"
value = "testacc-peerings-ds"
}

}

resource "outscale_net_peering" "outscale_net_peering2" {
accepter_net_id = outscale_net.outscale_net.net_id
source_net_id = outscale_net.outscale_net2.net_id
}

data "outscale_net_peerings" "outscale_net_peerings" {
filter {
name = "net_peering_ids"
Expand Down
1 change: 0 additions & 1 deletion outscale/data_source_outscale_vm_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func TestAccVM_StatesDataSource(t *testing.T) {
t.Parallel()
omi := os.Getenv("OUTSCALE_IMAGEID")

resource.Test(t, resource.TestCase{
Expand Down
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
8 changes: 4 additions & 4 deletions outscale/resource_outscale_image_launch_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,17 @@ func ResourceOutscaleImageLaunchPermissionCreate(d *schema.ResourceData, meta in
}
log.Printf("Creating Outscale Image Launch Permission, image_id (%+v)", imageID.(string))

permissionLunch := oscgo.PermissionsOnResourceCreation{}
permissionLaunch := oscgo.PermissionsOnResourceCreation{}
if permissionAdditions, ok := d.GetOk("permission_additions"); ok {
permissionLunch.SetAdditions(expandOAPIImagePermission(permissionAdditions))
permissionLaunch.SetAdditions(expandOAPIImagePermission(permissionAdditions))
}
if permissionRemovals, ok := d.GetOk("permission_removals"); ok {
permissionLunch.SetRemovals(expandOAPIImagePermission(permissionRemovals))
permissionLaunch.SetRemovals(expandOAPIImagePermission(permissionRemovals))
}

request := oscgo.UpdateImageRequest{
ImageId: imageID.(string),
PermissionsToLaunch: permissionLunch,
PermissionsToLaunch: &permissionLaunch,
}

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
Expand Down
1 change: 0 additions & 1 deletion outscale/resource_outscale_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestAccOthers_PublicIP_basic(t *testing.T) {
}

func TestAccVM_PublicIP_instance(t *testing.T) {
t.Parallel()
var conf oscgo.PublicIp
omi := os.Getenv("OUTSCALE_IMAGEID")
region := utils.GetRegion()
Expand Down
8 changes: 8 additions & 0 deletions outscale/resource_outscale_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -267,11 +268,18 @@ func ResourceOutscaleSecurityGroupDelete(d *schema.ResourceData, meta interface{

log.Printf("[DEBUG] Security Group destroy: %v", d.Id())
securityGroupID := d.Id()
sg, _, err := readSecurityGroups(conn, securityGroupID)
if err != nil {
return err
}
return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, httpResp, err := conn.SecurityGroupApi.DeleteSecurityGroup(context.Background()).DeleteSecurityGroupRequest(oscgo.DeleteSecurityGroupRequest{
SecurityGroupId: &securityGroupID,
}).Execute()
if err != nil {
if sg.GetNetId() != "" && httpResp.StatusCode == http.StatusConflict {
return utils.CheckThrottling(httpResp, err)
}
if strings.Contains(err.Error(), "DependencyProblem") {
return resource.RetryableError(err)
}
Expand Down
Loading