Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Jan 25, 2024
1 parent e4751de commit 8b7a4ce
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 134 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/others_testacc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ jobs:
access_key: ${{ secrets.OSC_ACCESS_KEY }}
secret_key: ${{ secrets.OSC_SECRET_KEY }}
region: ${{ secrets.OSC_REGION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.6.5
terraform_wrapper: false
- name: Set up Go
uses: actions/setup-go@v4
with:
Expand Down
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/hashicorp/terraform v0.14.0
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/nav-inc/datetime v0.1.3
github.com/openlyinc/pointy v1.1.2
github.com/outscale/osc-sdk-go/v2 v2.18.2
github.com/spf13/cast v1.3.1
)
Expand Down Expand Up @@ -60,7 +59,6 @@ require (
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.5 // indirect
Expand All @@ -82,14 +80,11 @@ require (
github.com/zclconf/go-cty-yaml v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.147.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
37 changes: 4 additions & 33 deletions go.sum

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions outscale/resource_outscale_ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/openlyinc/pointy"
oscgo "github.com/outscale/osc-sdk-go/v2"
"github.com/spf13/cast"
"github.com/terraform-providers/terraform-provider-outscale/utils"
Expand Down Expand Up @@ -58,8 +57,8 @@ func resourceOutscaleOAPICaCreate(d *schema.ResourceData, meta interface{}) erro
req := oscgo.CreateCaRequest{
CaPem: d.Get("ca_pem").(string),
}
if v, ok := d.GetOk("description"); ok {
req.Description = pointy.String(v.(string))
if _, ok := d.GetOk("description"); ok {
req.SetDescription(d.Get("description").(string))
}

var resp oscgo.CreateCaResponse
Expand Down Expand Up @@ -130,8 +129,7 @@ func resourceOutscaleOAPICaUpdate(d *schema.ResourceData, meta interface{}) erro
}

if d.HasChange("description") {
_, des := d.GetChange("description")
req.Description = pointy.String(des.(string))
req.SetDescription(d.Get("description").(string))
}

var err error
Expand Down
8 changes: 3 additions & 5 deletions outscale/resource_outscale_dhcp_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"
"time"

"github.com/openlyinc/pointy"
"github.com/terraform-providers/terraform-provider-outscale/utils"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -122,10 +121,9 @@ func TestAccNet_withDhcpOptional(t *testing.T) {
domainName := fmt.Sprintf("%s.compute%s.internal", utils.GetRegion(), acctest.RandString(3))
domainServers := []string{"192.168.12.12", "192.168.12.132"}

tags := &oscgo.Tag{
Key: pointy.String(acctest.RandomWithPrefix("name")),
Value: pointy.String(acctest.RandomWithPrefix("test-MZI")),
}
tags := &oscgo.Tag{}
tags.SetKey(acctest.RandomWithPrefix("name"))
tags.SetValue(acctest.RandomWithPrefix("test-MZI"))

domainNameUpdated := fmt.Sprintf("%s.compute%s.internal", utils.GetRegion(), acctest.RandString(3))

Expand Down
7 changes: 2 additions & 5 deletions outscale/resource_outscale_image_export_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/terraform-providers/terraform-provider-outscale/utils"

"github.com/openlyinc/pointy"
oscgo "github.com/outscale/osc-sdk-go/v2"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -146,10 +145,8 @@ func resourceOAPIImageExportTaskCreate(d *schema.ResourceData, meta interface{})
a := v.([]interface{})
if len(a) > 0 {
w := a[0].(map[string]interface{})
et.OsuApiKey = &oscgo.OsuApiKey{
ApiKeyId: pointy.String(w["api_key_id"].(string)),
SecretKey: pointy.String(w["secret_key"].(string)),
}
et.OsuApiKey.SetApiKeyId(w["api_key_id"].(string))
et.OsuApiKey.SetSecretKey(w["secret_key"].(string))
}
}
if v, ok := e["osu_manifest_url"]; ok {
Expand Down
16 changes: 6 additions & 10 deletions outscale/resource_outscale_nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/openlyinc/pointy"
"github.com/terraform-providers/terraform-provider-outscale/utils"
)

Expand Down Expand Up @@ -607,6 +606,9 @@ func resourceOutscaleOAPINicUpdate(d *schema.ResourceData, meta interface{}) err
pips := d.Get("pips").(*schema.Set).List()
prips := pips[:0]
pip := d.Get("private_ip")
input := oscgo.LinkPrivateIpsRequest{
NicId: d.Id(),
}

for _, ip := range pips {
if ip != pip {
Expand All @@ -619,12 +621,7 @@ func resourceOutscaleOAPINicUpdate(d *schema.ResourceData, meta interface{}) err

// Surplus of IPs, add the diff
if diff > 0 {
dif := int32(diff)
input := oscgo.LinkPrivateIpsRequest{
NicId: d.Id(),
SecondaryPrivateIpCount: pointy.Int32(dif),
}
// _, err := conn.VM.AssignPrivateIpAddresses(input)
input.SetSecondaryPrivateIpCount(int32(diff))

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
Expand Down Expand Up @@ -682,10 +679,9 @@ func resourceOutscaleOAPINicUpdate(d *schema.ResourceData, meta interface{}) err

if d.HasChange("description") {
request := oscgo.UpdateNicRequest{
NicId: d.Id(),
Description: pointy.String(d.Get("description").(string)),
NicId: d.Id(),
}

request.SetDescription(d.Get("description").(string))
var err error
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
_, httpResp, err := conn.NicApi.UpdateNic(context.Background()).UpdateNicRequest(request).Execute()
Expand Down
36 changes: 9 additions & 27 deletions outscale/resource_outscale_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

"github.com/openlyinc/pointy"
oscgo "github.com/outscale/osc-sdk-go/v2"
"github.com/terraform-providers/terraform-provider-outscale/utils"

Expand Down Expand Up @@ -286,39 +285,22 @@ func resourceOutscaleOAPIRouteUpdate(d *schema.ResourceData, meta interface{}) e
return errors.New("no target found for the update")
}

replaceOpts := oscgo.UpdateRouteRequest{}
replaceOpts := oscgo.UpdateRouteRequest{
RouteTableId: d.Get("route_table_id").(string),
DestinationIpRange: d.Get("destination_ip_range").(string),
}

switch target {
case "gateway_id":
replaceOpts = oscgo.UpdateRouteRequest{
RouteTableId: d.Get("route_table_id").(string),
DestinationIpRange: d.Get("destination_ip_range").(string),
GatewayId: pointy.String(d.Get("gateway_id").(string)),
}
replaceOpts.SetGatewayId(d.Get("gateway_id").(string))
case "nat_service_id":
replaceOpts = oscgo.UpdateRouteRequest{
RouteTableId: d.Get("route_table_id").(string),
DestinationIpRange: d.Get("destination_ip_range").(string),
NatServiceId: pointy.String(d.Get("nat_service_id").(string)),
}
replaceOpts.SetNatServiceId(d.Get("nat_service_id").(string))
case "vm_id":
replaceOpts = oscgo.UpdateRouteRequest{
RouteTableId: d.Get("route_table_id").(string),
DestinationIpRange: d.Get("destination_ip_range").(string),
VmId: pointy.String(d.Get("vm_id").(string)),
}
replaceOpts.SetVmId(d.Get("vm_id").(string))
case "nic_id":
replaceOpts = oscgo.UpdateRouteRequest{
RouteTableId: d.Get("route_table_id").(string),
DestinationIpRange: d.Get("destination_ip_range").(string),
NicId: pointy.String(d.Get("nic_id").(string)),
}
replaceOpts.SetNicId(d.Get("nic_id").(string))
case "net_peering_id":
replaceOpts = oscgo.UpdateRouteRequest{
RouteTableId: d.Get("route_table_id").(string),
DestinationIpRange: d.Get("destination_ip_range").(string),
NetPeeringId: pointy.String(d.Get("net_peering_id").(string)),
}
replaceOpts.SetNetPeeringId(d.Get("net_peering_id").(string))
default:
return fmt.Errorf("An invalid target type specified: %s", target)
}
Expand Down
35 changes: 17 additions & 18 deletions outscale/resource_outscale_security_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

"github.com/openlyinc/pointy"
oscgo "github.com/outscale/osc-sdk-go/v2"
"github.com/spf13/cast"
"github.com/terraform-providers/terraform-provider-outscale/utils"
Expand Down Expand Up @@ -98,22 +97,22 @@ func resourceOutscaleOAPIOutboundRuleCreate(d *schema.ResourceData, meta interfa
}

if v, ok := d.GetOkExists("from_port_range"); ok {
req.FromPortRange = pointy.Int32(cast.ToInt32(v))
req.SetFromPortRange(cast.ToInt32(v))
}
if v, ok := d.GetOkExists("to_port_range"); ok {
req.ToPortRange = pointy.Int32(cast.ToInt32(v))
req.SetToPortRange(cast.ToInt32(v))
}
if v, ok := d.GetOk("ip_protocol"); ok {
req.IpProtocol = pointy.String(v.(string))
req.SetIpProtocol(v.(string))
}
if v, ok := d.GetOk("ip_range"); ok {
req.IpRange = pointy.String(v.(string))
req.SetIpRange(v.(string))
}
if v, ok := d.GetOk("security_group_account_id_to_link"); ok {
req.SecurityGroupAccountIdToLink = pointy.String(v.(string))
req.SetSecurityGroupAccountIdToLink(v.(string))
}
if v, ok := d.GetOk("security_group_name_to_link"); ok {
req.SecurityGroupNameToLink = pointy.String(v.(string))
req.SetSecurityGroupNameToLink(v.(string))
}

var err error
Expand Down Expand Up @@ -170,16 +169,16 @@ func resourceOutscaleOAPIOutboundRuleDelete(d *schema.ResourceData, meta interfa
}

if v, ok := d.GetOkExists("from_port_range"); ok {
req.FromPortRange = pointy.Int32(cast.ToInt32(v))
req.SetFromPortRange(cast.ToInt32(v))
}
if v, ok := d.GetOkExists("to_port_range"); ok {
req.ToPortRange = pointy.Int32(cast.ToInt32(v))
req.SetToPortRange(cast.ToInt32(v))
}
if v, ok := d.GetOk("ip_protocol"); ok {
req.IpProtocol = pointy.String(v.(string))
req.SetIpProtocol(v.(string))
}
if v, ok := d.GetOk("ip_range"); ok {
req.IpRange = pointy.String(v.(string))
req.SetIpRange(v.(string))
}

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
Expand Down Expand Up @@ -215,13 +214,13 @@ func expandRules(d *schema.ResourceData, conn *oscgo.APIClient) *[]oscgo.Securit
rules[i].ServiceIds = utils.InterfaceSliceToStringSlicePtr(r["service_ids"].([]interface{}))
}
if v, ok := r["from_port_range"]; ok {
rules[i].FromPortRange = pointy.Int32(cast.ToInt32(v))
rules[i].SetFromPortRange(cast.ToInt32(v))
}
if v, ok := r["ip_protocol"]; ok && v != "" {
rules[i].IpProtocol = pointy.String(cast.ToString(v))
rules[i].SetIpProtocol(cast.ToString(v))
}
if v, ok := r["to_port_range"]; ok {
rules[i].ToPortRange = pointy.Int32(cast.ToInt32(v))
rules[i].SetToPortRange(cast.ToInt32(v))
}
}
return &rules
Expand Down Expand Up @@ -266,16 +265,16 @@ func expandSecurityGroupsMembers(gps []interface{}, conn *oscgo.APIClient) *[]os
groups[i] = oscgo.SecurityGroupsMember{}

if v, ok := g["account_id"]; ok && v != "" {
groups[i].AccountId = pointy.String(cast.ToString(v))
groups[i].SetAccountId(cast.ToString(v))
}
if v, ok := g["security_group_name"]; ok && v != "" {
groups[i].SecurityGroupName = pointy.String(cast.ToString(v))
groups[i].SetSecurityGroupName(cast.ToString(v))
if sgID := getSgIdinVPC(conn, cast.ToString(v)); sgID != "" {
groups[i].SecurityGroupId = pointy.String(cast.ToString(sgID))
groups[i].SetSecurityGroupId(cast.ToString(sgID))
}
}
if v, ok := g["security_group_id"]; ok && v != "" {
groups[i].SecurityGroupId = pointy.String(cast.ToString(v))
groups[i].SetSecurityGroupId(cast.ToString(v))
}
}
return &groups
Expand Down
19 changes: 9 additions & 10 deletions outscale/resource_outscale_server_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/openlyinc/pointy"
oscgo "github.com/outscale/osc-sdk-go/v2"
"github.com/spf13/cast"
"github.com/terraform-providers/terraform-provider-outscale/utils"
Expand Down Expand Up @@ -88,14 +87,14 @@ func resourceOutscaleOAPIServerCertificateCreate(d *schema.ResourceData, meta in
return fmt.Errorf("[DEBUG] Error 'private_key' field is require for server certificate creation")
}

if v, ok := d.GetOk("chain"); ok {
req.Chain = pointy.String(v.(string))
if _, ok := d.GetOk("chain"); ok {
req.SetChain(d.Get("chain").(string))
}
if v, ok := d.GetOk("dry_run"); ok {
req.DryRun = pointy.Bool(v.(bool))
if _, ok := d.GetOk("dry_run"); ok {
req.SetDryRun(d.Get("dry_run").(bool))
}
if v, ok := d.GetOk("path"); ok {
req.Path = pointy.String(v.(string))
if _, ok := d.GetOk("path"); ok {
req.SetPath(d.Get("path").(string))
}
var resp oscgo.CreateServerCertificateResponse
var err error
Expand Down Expand Up @@ -168,16 +167,16 @@ func resourceOutscaleOAPIServerCertificateRead(d *schema.ResourceData, meta inte
func resourceOutscaleOAPIServerCertificateUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*OutscaleClient).OSCAPI

oldName, newName := d.GetChange("name")
oldName, _ := d.GetChange("name")
req := oscgo.UpdateServerCertificateRequest{
Name: oldName.(string),
}

if d.HasChange("name") {
req.NewName = pointy.String(newName.(string))
req.SetNewName(d.Get("name").(string))
}
if d.HasChange("path") {
req.NewPath = pointy.String(d.Get("path").(string))
req.SetNewPath(d.Get("path").(string))
}

var err error
Expand Down
7 changes: 2 additions & 5 deletions outscale/resource_outscale_snapshot_export_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"time"

"github.com/openlyinc/pointy"
oscgo "github.com/outscale/osc-sdk-go/v2"
"github.com/terraform-providers/terraform-provider-outscale/utils"

Expand Down Expand Up @@ -142,10 +141,8 @@ func resourceOAPISnapshotExportTaskCreate(d *schema.ResourceData, meta interface

if len(a) > 0 {
w := a[0].(map[string]interface{})
et.OsuApiKey = &oscgo.OsuApiKey{
ApiKeyId: pointy.String(w["api_key_id"].(string)),
SecretKey: pointy.String(w["secret_key"].(string)),
}
et.OsuApiKey.SetApiKeyId(w["api_key_id"].(string))
et.OsuApiKey.SetSecretKey(w["secret_key"].(string))
}
}
request.SetOsuExport(et)
Expand Down
Loading

0 comments on commit 8b7a4ce

Please sign in to comment.