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

Fix migration error #473

Merged
merged 3 commits into from
Sep 11, 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ terraformStatePull.json
/tests/old.py
/tests/tmp.txt
/tests/qa_provider_oapi/terraform.d/
outscale/certificate.key
outscale/certificate.pem
outscale/gen-cert-test.tf
terraform-provider-outscale_v0.5.32
tests/qa_provider_oapi/data/cert_example/

# docs
docs/generation_log.txt
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.21.0
github.com/outscale/osc-sdk-go/v2 v2.23.0
github.com/spf13/cast v1.6.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
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.21.0 h1:8MqhexV+ALG76CvY8EpuQlr0+hC5VFrWQY4fHqdT358=
github.com/outscale/osc-sdk-go/v2 v2.21.0/go.mod h1:kzhtUErCzKYl87bZ+kDMphDafmnwbsyFJY9iHF7NgNE=
github.com/outscale/osc-sdk-go/v2 v2.23.0 h1:Ib134+ThQHmMtURcMTD9eTiAKeF1gSufbH3RdYa9+bY=
github.com/outscale/osc-sdk-go/v2 v2.23.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
30 changes: 7 additions & 23 deletions outscale/data_source_outscale_nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func DataSourceOutscaleNic() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"public_ip": {
Type: schema.TypeString,
Computed: true,
},
"public_ip_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -309,31 +313,11 @@ func DataSourceOutscaleNicRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("private_dns_name", eni.GetPrivateDnsName()); err != nil {
return err
}

y := make([]map[string]interface{}, len(eni.GetPrivateIps()))
if eni.PrivateIps != nil {
for k, v := range eni.GetPrivateIps() {
b := make(map[string]interface{})
if assoc, ok := v.GetLinkPublicIpOk(); ok {
d := make(map[string]interface{})
d["public_ip_id"] = assoc.GetPublicIpId()
d["link_public_ip_id"] = assoc.GetLinkPublicIpId()
d["public_ip_account_id"] = assoc.GetPublicIpAccountId()
d["public_dns_name"] = assoc.GetPublicDnsName()
d["public_ip"] = assoc.GetPublicIp()
b["link_public_ip"] = d
}
b["private_dns_name"] = v.GetPrivateDnsName()
b["private_ip"] = v.GetPrivateIp()
b["is_primary"] = v.GetIsPrimary()
y[k] = b
if privIps, ok := eni.GetPrivateIpsOk(); ok {
if err := d.Set("private_ips", getOAPIPrivateIPsForNic(*privIps)); err != nil {
return err
}
}

if err := d.Set("private_ips", y); err != nil {
return err
}

if err := d.Set("is_source_dest_checked", eni.GetIsSourceDestChecked()); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions outscale/data_source_outscale_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ func buildOutscaleOapiSnapshootDataSourceFilters(set *schema.Set, filter *oscgo.
if err != nil {
return err
}
filter.SetToCreationDate(valDate)
filter.SetToCreationDate(valDate.UTC().Format("2006-01-02T15:04:05.999Z"))

case "from_creation_date":
valDate, err := utils.ParsingfilterToDateFormat("from_creation_date", values[0])
if err != nil {
return err
}
filter.SetFromCreationDate(valDate)
filter.SetFromCreationDate(valDate.UTC().Format("2006-01-02T15:04:05.999Z"))

case "permissions_to_create_volume_account_ids":
filter.SetPermissionsToCreateVolumeAccountIds(values)
Expand Down
4 changes: 1 addition & 3 deletions outscale/data_source_outscale_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestAccOthers_VolumeDataSource_multipleVIdsFilters(t *testing.T) {
}

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

Expand All @@ -59,8 +58,7 @@ func TestAccVM_withVolumesDataSource(t *testing.T) {
Config: testAccCheckOutscaleVolumesDataSourceConfigWithVM(utils.GetRegion(), omi, keypair),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleVolumeDataSourceID("data.outscale_volumes.outscale_volumes"),
// resource.TestCheckResourceAttr("data.outscale_volumes.outscale_volumes", "volumes.0.size", "1"),
// resource.TestCheckResourceAttr("data.outscale_volumes.outscale_volumes", "volumes.0.volume_type", "standard"),
resource.TestCheckResourceAttrSet("data.outscale_volumes.outscale_volumes", "volumes.#"),
),
},
},
Expand Down
16 changes: 8 additions & 8 deletions outscale/data_source_outscale_vpn_connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ func testAccOutscaleVPNConnectionsDataSourceConfigBasic(publicIP string) string
}

resource "outscale_vpn_connection" "foo" {
client_gateway_id = "${outscale_client_gateway.customer_gateway.id}"
virtual_gateway_id = "${outscale_virtual_gateway.virtual_gateway.id}"
client_gateway_id = outscale_client_gateway.customer_gateway.id
virtual_gateway_id = outscale_virtual_gateway.virtual_gateway.id
connection_type = "ipsec.1"
static_routes_only = true

tags {
key = "Name"
value = "test-VPN"
key = "Name"
value = "test-VPN"
}
}

data "outscale_vpn_connections" "test" {
vpn_connection_ids = ["${outscale_vpn_connection.foo.id}"]
vpn_connection_ids = [outscale_vpn_connection.foo.id]
}
`, publicIP)
}
Expand All @@ -81,15 +81,15 @@ func testAccOutscaleVPNConnectionsDataSourceConfigWithFilters(publicIP string) s
}

resource "outscale_vpn_connection" "foo" {
client_gateway_id = "${outscale_client_gateway.customer_gateway.id}"
virtual_gateway_id = "${outscale_virtual_gateway.virtual_gateway.id}"
client_gateway_id = outscale_client_gateway.customer_gateway.id
virtual_gateway_id = outscale_virtual_gateway.virtual_gateway.id
connection_type = "ipsec.1"
}

data "outscale_vpn_connections" "test" {
filter {
name = "vpn_connection_ids"
values = ["${outscale_vpn_connection.foo.id}"]
values = [outscale_vpn_connection.foo.id]
}
}
`, publicIP)
Expand Down
28 changes: 23 additions & 5 deletions outscale/instance_set_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ func getOAPILinkNic(l oscgo.LinkNic) []map[string]interface{} {
}}
}

func getOAPILinkPublicIPsForNic(l oscgo.LinkPublicIp) []map[string]interface{} {
return []map[string]interface{}{{
"link_public_ip_id": l.GetLinkPublicIpId(),
"public_dns_name": l.GetPublicDnsName(),
"public_ip": l.GetPublicIp(),
"public_ip_account_id": l.GetPublicIpAccountId(),
"public_ip_id": l.GetPublicIpId(),
}}
}

func getOAPIBsuSet(bsu oscgo.BsuCreated) []map[string]interface{} {
return []map[string]interface{}{{
"delete_on_vm_deletion": bsu.GetDeleteOnVmDeletion(),
Expand All @@ -49,6 +59,14 @@ func getOAPIBsuSet(bsu oscgo.BsuCreated) []map[string]interface{} {
}}
}

func getOAPILinkPublicIpsForVm(l oscgo.LinkPublicIpLightForVm) []map[string]interface{} {
return []map[string]interface{}{{
"public_dns_name": l.GetPublicDnsName(),
"public_ip": l.GetPublicIp(),
"public_ip_account_id": l.GetPublicIpAccountId(),
}}
}

func getOAPILinkPublicIPLight(l oscgo.LinkPublicIpLightForVm) *schema.Set {
res := &schema.Set{
F: func(v interface{}) int {
Expand Down Expand Up @@ -105,15 +123,15 @@ func getOAPIPrivateIPsLight(privateIPs []oscgo.PrivateIpLightForVm) *schema.Set
return res
}

func getOAPIPrivateIPs(privateIPs []oscgo.PrivateIp) (res []map[string]interface{}) {
func getOAPIPrivateIPsForNic(privateIPs []oscgo.PrivateIp) (res []map[string]interface{}) {
for _, p := range privateIPs {
r := map[string]interface{}{
"is_primary": p.GetIsPrimary(),
"private_dns_name": p.GetPrivateDnsName(),
"private_ip": p.GetPrivateIp(),
}
if _, ok := p.GetLinkPublicIpOk(); ok {
r["link_public_ip"] = getOAPILinkPublicIP(p.GetLinkPublicIp())
r["link_public_ip"] = getOAPILinkPublicIPsForNic(p.GetLinkPublicIp())
}
res = append(res, r)
}
Expand Down Expand Up @@ -144,7 +162,7 @@ func getOAPIVMNetworkInterfaceLightSet(nics []oscgo.NicLight) (primaryNic []map[
}

if nic.HasLinkPublicIp() {
nicMap["link_public_ip"] = getOAPILinkPublicIPLight(nic.GetLinkPublicIp())
nicMap["link_public_ip"] = getOAPILinkPublicIpsForVm(nic.GetLinkPublicIp())
}

if nic.HasPrivateIps() {
Expand Down Expand Up @@ -174,7 +192,7 @@ func getOAPIVMNetworkInterfaceSet(nics []oscgo.Nic) (res []map[string]interface{
"net_id": nic.GetNetId(),
"nic_id": nic.GetNicId(),
"private_dns_name": nic.GetPrivateDnsName(),
"private_ips": getOAPIPrivateIPs(nic.GetPrivateIps()),
"private_ips": getOAPIPrivateIPsForNic(nic.GetPrivateIps()),
"security_groups": securityGroups,
"state": nic.GetState(),
"subnet_id": nic.GetSubnetId(),
Expand All @@ -185,7 +203,7 @@ func getOAPIVMNetworkInterfaceSet(nics []oscgo.Nic) (res []map[string]interface{
r["link_nic"] = getOAPILinkNic(nic.GetLinkNic())
}
if _, ok := nic.GetLinkPublicIpOk(); ok {
r["link_public_ip"] = getOAPILinkPublicIP(nic.GetLinkPublicIp())
r["link_public_ip"] = getOAPILinkPublicIPsForNic(nic.GetLinkPublicIp())
}
res = append(res, r)
}
Expand Down
2 changes: 1 addition & 1 deletion outscale/resource_outscale_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func ResourceOutscaleLoadBalancerUpdate(d *schema.ResourceData, meta interface{}
s := tag["key"].(string)
remove = append(remove,
oscgo.ResourceLoadBalancerTag{
Key: &s,
Key: s,
})
}
if len(remove) < 1 {
Expand Down
28 changes: 3 additions & 25 deletions outscale/resource_outscale_nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,33 +362,11 @@ func ResourceOutscaleNicRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("private_dns_name", eni.GetPrivateDnsName()); err != nil {
return err
}

privateIps := make([]map[string]interface{}, len(eni.GetPrivateIps()))
if eni.PrivateIps != nil {
for k, v := range eni.GetPrivateIps() {
privIp := make(map[string]interface{})

if assoc, ok := v.GetLinkPublicIpOk(); ok {
linkPubIp := []map[string]interface{}{{
"public_ip_id": assoc.GetPublicIpId(),
"link_public_ip_id": assoc.GetLinkPublicIpId(),
"public_ip_account_id": assoc.GetPublicIpAccountId(),
"public_dns_name": assoc.GetPublicDnsName(),
"public_ip": assoc.GetPublicIp(),
}}
privIp["link_public_ip"] = linkPubIp
}
privIp["private_dns_name"] = v.GetPrivateDnsName()
privIp["private_ip"] = v.GetPrivateIp()
privIp["is_primary"] = v.GetIsPrimary()

privateIps[k] = privIp
if privIps, ok := eni.GetPrivateIpsOk(); ok {
if err := d.Set("private_ips", getOAPIPrivateIPsForNic(*privIps)); err != nil {
return err
}
}
if err := d.Set("private_ips", privateIps); err != nil {
return err
}

if err := d.Set("is_source_dest_checked", eni.GetIsSourceDestChecked()); err != nil {
return err
}
Expand Down
Loading
Loading