|
8 | 8 | "fmt" |
9 | 9 | "regexp" |
10 | 10 | "strconv" |
| 11 | + "strings" |
11 | 12 | "testing" |
12 | 13 | "time" |
13 | 14 |
|
@@ -102,6 +103,17 @@ var ( |
102 | 103 | "requested_throughput": acctest.Representation{RepType: acctest.Optional, Create: `1`}, |
103 | 104 | "lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreDefinedTagsDifferencesRepresentation}, |
104 | 105 | } |
| 106 | + FileStorageIPV6MountTargetRepresentation = map[string]interface{}{ |
| 107 | + "availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`}, |
| 108 | + "compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`}, |
| 109 | + "subnet_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_subnet.test_subnet1.id}`}, |
| 110 | + //"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`}, |
| 111 | + "display_name": acctest.Representation{RepType: acctest.Optional, Create: `mount-target-ipv6`}, |
| 112 | + "hostname_label": acctest.Representation{RepType: acctest.Optional, Create: `hostnamelabel`}, |
| 113 | + "ip_address": acctest.Representation{RepType: acctest.Optional, Create: `${cidrhost(oci_core_vcn.test_vcn.ipv6cidr_blocks[0], 21)}`}, |
| 114 | + "requested_throughput": acctest.Representation{RepType: acctest.Optional, Create: `1`}, |
| 115 | + "lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreDefinedTagsDifferencesRepresentation}, |
| 116 | + } |
105 | 117 | FileStorageMountTargetKerberosRepresentation = map[string]interface{}{ |
106 | 118 | "kerberos_realm": acctest.Representation{RepType: acctest.Required, Create: `kerberosRealm`, Update: `kerberosRealm2`}, |
107 | 119 | "backup_key_tab_secret_version": acctest.Representation{RepType: acctest.Optional, Create: `0`, Update: `0`}, |
@@ -483,7 +495,53 @@ func TestFileStorageMountTargetResource_failedWorkRequest(t *testing.T) { |
483 | 495 | }, |
484 | 496 | }) |
485 | 497 | } |
| 498 | +func TestFileStorageMountTargetResource_ipv6(t *testing.T) { |
| 499 | + httpreplay.SetScenario("TestFileStorageMountTargetResource_ipv6") |
| 500 | + defer httpreplay.SaveScenario() |
| 501 | + config := acctest.ProviderTestConfig() |
| 502 | + |
| 503 | + compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid") |
| 504 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 505 | + |
| 506 | + resourceName := "oci_file_storage_mount_target.test_mount_target123" |
| 507 | + // Get subnet CIDR block based on its VCN CIDR Block |
| 508 | + // For example: VCN CIDR Block: 2607:9b80:9a0f:0100::/56, Subnet CIDR Block: 2607:9b80:9a0f:0100::/64 |
| 509 | + subnetCidrBlock := `${substr(oci_core_vcn.test_vcn.ipv6cidr_blocks[0], 0, length(oci_core_vcn.test_vcn.ipv6cidr_blocks[0]) - 2)}${64}` |
| 510 | + //subnetCidrBlock := `fd1b:392a:ffb6::/64` |
| 511 | + acctest.ResourceTest(t, testAccCheckFileStorageMountTargetDestroy, []resource.TestStep{ |
| 512 | + // verify resource creation fails for the second mount target with the same ip_address |
| 513 | + { |
| 514 | + Config: config + compartmentIdVariableStr + |
| 515 | + acctest.GenerateResourceFromRepresentationMap("oci_core_network_security_group", "test_network_security_group", acctest.Required, acctest.Create, CoreNetworkSecurityGroupRepresentation) + |
| 516 | + acctest.GenerateResourceFromRepresentationMap("oci_core_subnet", "test_subnet1", acctest.Required, acctest.Create, acctest.RepresentationCopyWithNewProperties(CoreSubnetRepresentation, map[string]interface{}{ |
| 517 | + "availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${lower("${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}")}`}, |
| 518 | + "dns_label": acctest.Representation{RepType: acctest.Required, Create: `dnslabel`}, |
| 519 | + "ipv6cidr_blocks": acctest.Representation{RepType: acctest.Required, Create: []string{subnetCidrBlock}}, |
| 520 | + })) + |
| 521 | + acctest.GenerateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", acctest.Required, acctest.Create, acctest.RepresentationCopyWithNewProperties(CoreVcnRepresentation, map[string]interface{}{ |
| 522 | + "dns_label": acctest.Representation{RepType: acctest.Required, Create: `dnslabel`}, |
| 523 | + "is_ipv6enabled": acctest.Representation{RepType: acctest.Required, Create: `true`}, |
| 524 | + })) + |
| 525 | + AvailabilityDomainConfig + |
| 526 | + acctest.GenerateResourceFromRepresentationMap("oci_file_storage_mount_target", "test_mount_target123", acctest.Optional, acctest.Update, acctest.RepresentationCopyWithRemovedProperties(FileStorageIPV6MountTargetRepresentation, []string{"idmap_type", "kerberos", "ldap_idmap"})), |
| 527 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 528 | + //resource.TestCheckResourceAttr(resourceName, "ip_address", "fd1b:392a:ffb6::20"), |
| 529 | + func(s *terraform.State) (err error) { |
| 530 | + // Get the IP address from the resource state |
| 531 | + ipAddress, err := acctest.FromInstanceState(s, resourceName, "ip_address") |
| 532 | + |
| 533 | + // Check if the IP address contains a colon (which is typical for IPv6) |
| 534 | + if !strings.Contains(ipAddress, ":") { |
| 535 | + return fmt.Errorf("IP address %s is not an IPv6 address (it does not contain a colon)", ipAddress) |
| 536 | + } |
486 | 537 |
|
| 538 | + // If it contains a colon, it's an IPv6 address, no error |
| 539 | + return nil |
| 540 | + }, |
| 541 | + ), |
| 542 | + }, |
| 543 | + }) |
| 544 | +} |
487 | 545 | func TestFileStorageMountTargetResource_hpmtTest(t *testing.T) { |
488 | 546 | httpreplay.SetScenario("TestFileStorageMountTargetResource_hpmtTest") |
489 | 547 | defer httpreplay.SaveScenario() |
|
0 commit comments