terraform-provider-oci
terraform-provider-oci copied to clipboard
"panic: interface conversion: interface {} is string, not int" for oci_core_ipsec_connection_tunnel_management
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform Version and Provider Version
terraform: Terraform v1.1.7 provider 4.68 and 4.69
Affected Resource(s)
oci_core_ipsec_connection_tunnel_management
Terraform Configuration Files
resource "oci_core_ipsec_connection_tunnel_management" "tunnel_management" {
count = length(data.oci_core_ipsec_connection_tunnels.tunnels.ip_sec_connection_tunnels)
ipsec_id = var.ipsec_id
routing = var.ipsec_routing_type
tunnel_id = data.oci_core_ipsec_connection_tunnels.tunnels.ip_sec_connection_tunnels[count.index].id
display_name = "${var.customer}-tunnel-${count.index}"
shared_secret = base64decode(data.oci_kms_decrypted_data.data.plaintext)
ike_version = var.ike_version
dynamic "encryption_domain_config" {
for_each = var.ipsec_routing_policy
content {
cpe_traffic_selector = encryption_domain_config.value.cpe_traffic_selector
oracle_traffic_selector = encryption_domain_config.value.oracle_traffic_selector
}
}
}
Debug Output
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# oci_core_ipsec_connection_tunnel_management.tunnel_management[0] will be updated in-place
~ resource "oci_core_ipsec_connection_tunnel_management" "tunnel_management" {
id = "ocid1.ipsectunnel.oc1...."
# (19 unchanged attributes hidden)
~ encryption_domain_config {
~ oracle_traffic_selector = [
- "10.222.4.128/25",
+ "10.222.5.0/24",
]
# (1 unchanged attribute hidden)
}
}
# oci_core_ipsec_connection_tunnel_management.tunnel_management[1] will be updated in-place
~ resource "oci_core_ipsec_connection_tunnel_management" "tunnel_management" {
id = "ocid1.ipsectunnel.oc1...."
# (19 unchanged attributes hidden)
~ encryption_domain_config {
~ oracle_traffic_selector = [
- "10.222.4.128/25",
+ "10.222.5.0/24",
]
# (1 unchanged attribute hidden)
}
}
Plan: 0 to add, 2 to change, 0 to destroy.
oci_core_ipsec_connection_tunnel_management.tunnel_management[1]: Modifying... [id=ocid1.ipsectunnel.oc1....]
Error: Request cancelled
with oci_core_ipsec_connection_tunnel_management.tunnel_management[1],
on main.tf line 1, in resource "oci_core_ipsec_connection_tunnel_management" "tunnel_management":
1: resource "oci_core_ipsec_connection_tunnel_management" "tunnel_management" {
The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
Error: Request cancelled
with oci_core_ipsec_connection_tunnel_management.tunnel_management[0],
on main.tf line 1, in resource "oci_core_ipsec_connection_tunnel_management" "tunnel_management":
1: resource "oci_core_ipsec_connection_tunnel_management" "tunnel_management" {
The plugin.(*GRPCProvider).UpgradeResourceState request was cancelled.
Stack trace from the terraform-provider-oci_v4.69.0 plugin:
panic: interface conversion: interface {} is string, not int
goroutine 21 [running]:
github.com/terraform-providers/terraform-provider-oci/internal/service/core.(*CoreIpSecConnectionTunnelManagementResourceCrud).Update(0xc001b13aa0)
github.com/terraform-providers/terraform-provider-oci/internal/service/core/core_ipsec_connection_tunnel_management_resource.go:500 +0x3338
github.com/terraform-providers/terraform-provider-oci/internal/tfresource.UpdateResource({0x52d9e90, 0xc001a21600}, {0x51fdca8, 0xc001b13aa0})
github.com/terraform-providers/terraform-provider-oci/internal/tfresource/crud_helpers.go:297 +0x139
github.com/terraform-providers/terraform-provider-oci/internal/service/core.updateCoreIpSecConnectionTunnelManagement(0xc001a21600, {0x4b163c0, 0xc002fd42d0})
github.com/terraform-providers/terraform-provider-oci/internal/service/core/core_ipsec_connection_tunnel_management_resource.go:317 +0xe5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc001b13a70, {0x52cd9a8, 0xc00193c0c0}, 0x24, {0x4b163c0, 0xc002fd42d0})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:352 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0013167e0, {0x52cd9a8, 0xc00193c0c0}, 0xc0000df8f0, 0xc001ae6f40, {0x4b163c0, 0xc002fd42d0})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:464 +0x6ba
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00000c528, {0x52cd9a8, 0xc00193c0c0}, 0xc0017ecff0)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:955 +0x9aa
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0xc0004b65a0, {0x52cda50, 0xc001a934a0}, 0x8)
github.com/hashicorp/[email protected]/tfprotov5/server/server.go:332 +0x6c
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x48b32c0, 0xc0004b65a0}, {0x52cda50, 0xc001a934a0}, 0xc001a09080, 0x0)
github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00057e540, {0x52f8410, 0xc0016e0000}, 0xc000162300, 0xc001639f50, 0x7a55bc0, 0x0)
google.golang.org/[email protected]/server.go:1194 +0xc8f
google.golang.org/grpc.(*Server).handleStream(0xc00057e540, {0x52f8410, 0xc0016e0000}, 0xc000162300, 0x0)
google.golang.org/[email protected]/server.go:1517 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
google.golang.org/[email protected]/server.go:859 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/[email protected]/server.go:857 +0x294
Error: The terraform-provider-oci_v4.69.0 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
Steps to Reproduce
- Create tf manifests for IPSec connection and tunnels
-
terraform apply
- Change routes
-
terraform apply
I don't know the Terraform plugin schema, but the OCI API defines lifetime
as an integer, but the Terraform plugin defines it as a string: (phaseOneDetails, phaseTwoDetails).
This diff worked for me, but it's a breaking change to the state file:
diff --git a/internal/service/core/core_ipsec_connection_tunnel_management_resource.go b/internal/service/core/core_ipsec_connection_tunnel_management_resource.go
index 09014a06c0..0cd45102b3 100644
--- a/internal/service/core/core_ipsec_connection_tunnel_management_resource.go
+++ b/internal/service/core/core_ipsec_connection_tunnel_management_resource.go
@@ -170,7 +170,7 @@ func CoreIpSecConnectionTunnelManagementResource() *schema.Resource {
Computed: true,
},
"lifetime": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Computed: true,
},
"negotiated_authentication_algorithm": {
@@ -186,7 +186,7 @@ func CoreIpSecConnectionTunnelManagementResource() *schema.Resource {
Computed: true,
},
"remaining_lifetime": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Computed: true,
},
"remaining_lifetime_last_retrieved": {
@@ -231,7 +231,7 @@ func CoreIpSecConnectionTunnelManagementResource() *schema.Resource {
Computed: true,
},
"lifetime": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Computed: true,
},
"negotiated_authentication_algorithm": {
@@ -247,7 +247,7 @@ func CoreIpSecConnectionTunnelManagementResource() *schema.Resource {
Computed: true,
},
"remaining_lifetime": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Computed: true,
},
"remaining_lifetime_last_retrieved": {
diff --git a/internal/service/core/core_ipsec_connection_tunnels_data_source.go b/internal/service/core/core_ipsec_connection_tunnels_data_source.go
index 8736de00fd..42418ada18 100644
--- a/internal/service/core/core_ipsec_connection_tunnels_data_source.go
+++ b/internal/service/core/core_ipsec_connection_tunnels_data_source.go
@@ -5,7 +5,6 @@ package core
import (
"context"
- "strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
oci_core "github.com/oracle/oci-go-sdk/v65/core"
@@ -172,7 +171,7 @@ func CoreIpSecConnectionTunnelsDataSource() *schema.Resource {
Computed: true,
},
"lifetime": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Computed: true,
},
"negotiated_authentication_algorithm": {
@@ -188,7 +187,7 @@ func CoreIpSecConnectionTunnelsDataSource() *schema.Resource {
Computed: true,
},
"remaining_lifetime": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Computed: true,
},
"remaining_lifetime_last_retrieved": {
@@ -233,7 +232,7 @@ func CoreIpSecConnectionTunnelsDataSource() *schema.Resource {
Computed: true,
},
"lifetime": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Computed: true,
},
"negotiated_authentication_algorithm": {
@@ -249,7 +248,7 @@ func CoreIpSecConnectionTunnelsDataSource() *schema.Resource {
Computed: true,
},
"remaining_lifetime": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Computed: true,
},
"remaining_lifetime_last_retrieved": {
@@ -468,7 +467,7 @@ func TunnelPhaseOneDetailsToMap(obj *oci_core.TunnelPhaseOneDetails) map[string]
}
if obj.Lifetime != nil {
- result["lifetime"] = strconv.FormatInt(*obj.Lifetime, 10)
+ result["lifetime"] = obj.Lifetime
}
if obj.NegotiatedAuthenticationAlgorithm != nil {
@@ -484,7 +483,7 @@ func TunnelPhaseOneDetailsToMap(obj *oci_core.TunnelPhaseOneDetails) map[string]
}
if obj.RemainingLifetime != nil {
- result["remaining_lifetime"] = strconv.FormatInt(*obj.RemainingLifetime, 10)
+ result["remaining_lifetime"] = *obj.RemainingLifetime
}
if obj.RemainingLifetimeLastRetrieved != nil {
@@ -522,7 +521,7 @@ func TunnelPhaseTwoDetailsToMap(obj *oci_core.TunnelPhaseTwoDetails) map[string]
}
if obj.Lifetime != nil {
- result["lifetime"] = strconv.FormatInt(*obj.Lifetime, 10)
+ result["lifetime"] = obj.Lifetime
}
if obj.NegotiatedAuthenticationAlgorithm != nil {
@@ -538,7 +537,7 @@ func TunnelPhaseTwoDetailsToMap(obj *oci_core.TunnelPhaseTwoDetails) map[string]
}
if obj.RemainingLifetime != nil {
- result["remaining_lifetime"] = strconv.FormatInt(*obj.RemainingLifetime, 10)
+ result["remaining_lifetime"] = obj.RemainingLifetime
}
if obj.RemainingLifetimeLastRetrieved != nil {
Because this is a breaking change, it may be better to cast the type back to an int before making the API call.
This is a smaller diff that doesn't require a breaking change to state schema. I'm not sure which is the way to go since the resource doesn't currently work anyway.
diff --git a/internal/service/core/core_ipsec_connection_tunnel_management_resource.go b/internal/service/core/core_ipsec_connection_tunnel_management_resource.go
index 09014a06c0..b5a2472616 100644
--- a/internal/service/core/core_ipsec_connection_tunnel_management_resource.go
+++ b/internal/service/core/core_ipsec_connection_tunnel_management_resource.go
@@ -6,6 +6,7 @@ package core
import (
"context"
"fmt"
+ "strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -497,8 +498,11 @@ func (s *CoreIpSecConnectionTunnelManagementResourceCrud) Update() error {
}
if lifetime, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "lifetime")); ok {
- tmp := lifetime.(int)
- phaseOneDetails.LifetimeInSeconds = &tmp
+ if tmp, err := strconv.ParseInt(lifetime.(string), 10, 64); err == nil {
+ p := new(int)
+ *p = int(tmp)
+ phaseOneDetails.LifetimeInSeconds = p
+ }
}
request.PhaseOneConfig = phaseOneDetails
@@ -525,8 +529,11 @@ func (s *CoreIpSecConnectionTunnelManagementResourceCrud) Update() error {
}
if lifetime, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "lifetime")); ok {
- tmp := lifetime.(int)
- phaseTwoDetails.LifetimeInSeconds = &tmp
+ if tmp, err := strconv.ParseInt(lifetime.(string), 10, 64); err == nil {
+ p := new(int)
+ *p = int(tmp)
+ phaseTwoDetails.LifetimeInSeconds = p
+ }
}
if isPfsEnabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_pfs_enabled")); ok {
Thank you for reporting the issue. We have raised an internal ticket to track this. Our service engineers will get back to you.
Bug fix was released in 4.85.0 in July 2022 that corrected lifetime to be an integer, which solves panic: interface conversion: interface {} is string, not int
Suggested change of remaining lifetime from TypeString to TypeInt was not included because it is a breaking change
Version v5.21.0 adds a new field remaining_lifetime_int that is the remaining lifetime as an integer. remaining_lifetime field remains as a string for backwards compatibility.