Skip to content

Commit 4e7ed9c

Browse files
ecabrersrinioci
authored andcommitted
Bug Fix - Fixing broken Integration & Example tests for DbSystem Patch Resource
1 parent 43937b6 commit 4e7ed9c

File tree

7 files changed

+256
-14
lines changed

7 files changed

+256
-14
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
# NAME
3+
# data.tf - Data Source file
4+
#
5+
# USAGE
6+
# Use the following path for Example Test & Backward-Compatibility-Test: database/db_systems/db_vm/patches
7+
# NOTES
8+
# Terraform Integration Test: TestDatabaseDbSystemPatchResource_basic
9+
# FILES
10+
#
11+
# DESCRIPTION
12+
#
13+
# MODIFIED MM/DD/YY
14+
# escabrer 05/23/2025 - Created
15+
16+
17+
data "oci_identity_availability_domains" "test_availability_domains" {
18+
compartment_id = var.compartment_id
19+
}
20+
21+
data "oci_database_db_system_patches" "test_db_system_patches" {
22+
#Required
23+
db_system_id = oci_database_db_system.test_db_system.id
24+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
# NAME
3+
# main.tf - Main file
4+
#
5+
# USAGE
6+
# Use the following path for Example Test & Backward-Compatibility-Test: database/db_systems/db_vm/patches
7+
# NOTES
8+
# Terraform Integration Test: TestDatabaseDbSystemPatchResource_basic
9+
# FILES
10+
#
11+
# DESCRIPTION
12+
#
13+
# MODIFIED MM/DD/YY
14+
# escabrer 06/05/2025 - Created
15+
16+
17+
resource "oci_database_db_system" "test_db_system" {
18+
display_name = "tfDbSystem"
19+
availability_domain = data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name
20+
compartment_id = var.compartment_id
21+
subnet_id = oci_core_subnet.test_subnet.id
22+
database_edition = "ENTERPRISE_EDITION"
23+
shape = "VM.Standard.E4.Flex"
24+
cpu_core_count = "4"
25+
ssh_public_keys = [var.ssh_public_key]
26+
domain = oci_core_subnet.test_subnet.subnet_domain_name
27+
hostname = "tfHost"
28+
data_storage_size_in_gb = "256"
29+
license_model = "LICENSE_INCLUDED"
30+
node_count = "1"
31+
db_system_options {
32+
storage_management = "LVM"
33+
}
34+
db_home {
35+
db_version = "19.0.0.0"
36+
display_name = "tfDbHome"
37+
database {
38+
admin_password = var.admin_password
39+
db_name = "tfDb"
40+
}
41+
}
42+
lifecycle {
43+
ignore_changes = [defined_tags["Oracle-Tags.CreatedBy"], defined_tags["Oracle-Tags.CreatedOn"]]
44+
}
45+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
# NAME
3+
# network.tf - Network Infra file
4+
#
5+
# USAGE
6+
# Use the following path for Example Test & Backward-Compatibility-Test: database/db_systems/db_vm/patches
7+
# NOTES
8+
# Terraform Integration Test: TestDatabaseDbSystemPatchResource_basic
9+
# FILES
10+
#
11+
# DESCRIPTION
12+
#
13+
# MODIFIED MM/DD/YY
14+
# escabrer 05/23/2025 - Created
15+
16+
17+
resource "oci_core_vcn" "test_vcn" {
18+
cidr_block = "10.1.0.0/16"
19+
compartment_id = var.compartment_id
20+
display_name = "tfVcn"
21+
dns_label = "tfvcn"
22+
}
23+
24+
resource "oci_core_route_table" "test_route_table" {
25+
compartment_id = var.compartment_id
26+
display_name = "tfRouteTable"
27+
route_rules {
28+
cidr_block = "0.0.0.0/0"
29+
description = "Internal traffic for OCI Services"
30+
network_entity_id = oci_core_internet_gateway.test_internet_gateway.id
31+
}
32+
vcn_id = oci_core_vcn.test_vcn.id
33+
}
34+
35+
resource "oci_core_internet_gateway" "test_internet_gateway" {
36+
compartment_id = var.compartment_id
37+
display_name = "tfInternetGateway"
38+
vcn_id = oci_core_vcn.test_vcn.id
39+
}
40+
41+
resource "oci_core_subnet" "test_subnet" {
42+
cidr_block = "10.1.20.0/24"
43+
compartment_id = var.compartment_id
44+
dhcp_options_id = oci_core_vcn.test_vcn.default_dhcp_options_id
45+
display_name = "tfSubnet"
46+
dns_label = "tfsubnet"
47+
route_table_id = oci_core_route_table.test_route_table.id
48+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
49+
vcn_id = oci_core_vcn.test_vcn.id
50+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
# NAME
3+
# provider.tf - provider file
4+
#
5+
# USAGE
6+
# Use the following path for Example Test & Backward-Compatibility-Test: database/db_systems/db_vm/patches
7+
# NOTES
8+
# Terraform Integration Test: TestDatabaseDbSystemPatchResource_basic
9+
# FILES
10+
#
11+
# DESCRIPTION
12+
#
13+
# MODIFIED MM/DD/YY
14+
# escabrer 05/23/2025 - Created
15+
16+
17+
18+
provider "oci" {
19+
auth = "SecurityToken"
20+
config_file_profile = "terraform-federation-test"
21+
region = var.region
22+
tenancy_ocid = var.compartment_id
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
# NAME
3+
# variables.tf - Variables file
4+
#
5+
# USAGE
6+
# Use the following path for Example Test & Backward-Compatibility-Test: database/db_systems/db_vm/patches
7+
# NOTES
8+
# Terraform Integration Test: TestDatabaseDbSystemPatchResource_basic
9+
# FILES
10+
#
11+
# DESCRIPTION
12+
#
13+
# MODIFIED MM/DD/YY
14+
# escabrer 05/23/2025 - Created
15+
16+
17+
18+
variable "tenancy_ocid" {
19+
}
20+
21+
variable "region" {
22+
}
23+
24+
variable "compartment_id" {
25+
}
26+
27+
variable "ssh_public_key" {
28+
}
29+
30+
variable "admin_password" {
31+
}

internal/acctest/test_helpers.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,47 @@ func CommonTestVariables() string {
724724
`
725725
}
726726

727+
func BaseDBCommonTestVariables() string {
728+
return `
729+
variable "tenancy_ocid" {
730+
default = "` + getEnvSettingWithBlankDefaultVar("tenancy_ocid") + `"
731+
}
732+
733+
variable "ssh_public_key" {
734+
default = "ssh-rsa KKKLK3NzaC1yc2EAAAADAQABAAABAQC+UC9MFNA55NIVtKPIBCNw7++ACXhD0hx+Zyj25JfHykjz/QU3Q5FAU3DxDbVXyubgXfb/GJnrKRY8O4QDdvnZZRvQFFEOaApThAmCAM5MuFUIHdFvlqP+0W+ZQnmtDhwVe2NCfcmOrMuaPEgOKO3DOW6I/qOOdO691Xe2S9NgT9HhN0ZfFtEODVgvYulgXuCCXsJs+NUqcHAOxxFUmwkbPvYi0P0e2DT8JKeiOOC8VKUEgvVx+GKmqasm+Y6zHFW7vv3g2GstE1aRs3mttHRoC/JPM86PRyIxeWXEMzyG5wHqUu4XZpDbnWNxi6ugxnAGiL3CrIFdCgRNgHz5qS1l MustWin"
735+
}
736+
737+
variable "region" {
738+
default = "` + getEnvSettingWithBlankDefaultVar("region") + `"
739+
}
740+
741+
variable "compartment_ocid" {
742+
default = "` + getEnvSettingWithBlankDefaultVar("compartment_ocid") + `"
743+
}
744+
745+
variable "compartment_id" {
746+
default = "` + getEnvSettingWithBlankDefaultVar("compartment_ocid") + `"
747+
}
748+
749+
variable "kms_key_id" {
750+
default = "` + getEnvSettingWithBlankDefaultVar("kms_key_id") + `"
751+
}
752+
753+
variable "kms_key_version_id" {
754+
default = "` + getEnvSettingWithBlankDefaultVar("kms_key_version_id") + `"
755+
}
756+
757+
variable "vault_id" {
758+
default = "` + getEnvSettingWithBlankDefaultVar("vault_id") + `"
759+
}
760+
761+
`
762+
}
763+
764+
func BaseDBProviderTestConfig() string {
765+
return BaseDBCommonTestVariables()
766+
}
767+
727768
func GetTestClients(data *schema.ResourceData) *tf_client.OracleClients {
728769
r := &schema.Resource{
729770
Schema: tf_provider.SchemaMap(),

internal/integrationtest/database_db_system_patch_test.go

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
package integrationtest
55

66
import (
7-
"fmt"
87
"testing"
98

10-
"github.com/oracle/terraform-provider-oci/internal/acctest"
11-
"github.com/oracle/terraform-provider-oci/internal/utils"
12-
139
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/oracle/terraform-provider-oci/internal/acctest"
1411

1512
"github.com/oracle/terraform-provider-oci/httpreplay"
1613
)
@@ -20,32 +17,63 @@ var (
2017
"db_system_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_db_system.test_db_system.id}`},
2118
}
2219

23-
DatabaseDbSystemPatchResourceConfig = DbSystemResourceConfig
20+
// 1. Main Db System Resource Representation: Start
21+
DbSystemResourceBaseRepresentation = map[string]interface{}{
22+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `tfDbSystem`},
23+
"database_edition": acctest.Representation{RepType: acctest.Optional, Create: `ENTERPRISE_EDITION`},
24+
"disk_redundancy": acctest.Representation{RepType: acctest.Optional, Create: `NORMAL`},
25+
"cpu_core_count": acctest.Representation{RepType: acctest.Optional, Create: `4`},
26+
"data_storage_size_in_gb": acctest.Representation{RepType: acctest.Optional, Create: `256`},
27+
"license_model": acctest.Representation{RepType: acctest.Optional, Create: `LICENSE_INCLUDED`, Update: `BRING_YOUR_OWN_LICENSE`},
28+
"node_count": acctest.Representation{RepType: acctest.Optional, Create: `1`},
29+
"fault_domains": acctest.Representation{RepType: acctest.Optional, Create: []string{`FAULT-DOMAIN-1`}},
30+
"domain": acctest.Representation{RepType: acctest.Optional, Create: `${oci_core_subnet.test_subnet.subnet_domain_name}`},
31+
"availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
32+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
33+
"subnet_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_subnet.test_subnet.id}`},
34+
"shape": acctest.Representation{RepType: acctest.Required, Create: `VM.Standard.E4.Flex`},
35+
"ssh_public_keys": acctest.Representation{RepType: acctest.Required, Create: []string{`ssh-rsa KKKLK3NzaC1yc2EAAAADAQABAAABAQC+UC9MFNA55NIVtKPIBCNw7++ACXhD0hx+Zyj25JfHykjz/QU3Q5FAU3DxDbVXyubgXfb/GJnrKRY8O4QDdvnZZRvQFFEOaApThAmCAM5MuFUIHdFvlqP+0W+ZQnmtDhwVe2NCfcmOrMuaPEgOKO3DOW6I/qOOdO691Xe2S9NgT9HhN0ZfFtEODVgvYulgXuCCXsJs+NUqcHAOxxFUmwkbPvYi0P0e2DT8JKeiOOC8VKUEgvVx+GKmqasm+Y6zHFW7vv3g2GstE1aRs3mttHRoC/JPM86PRyIxeWXEMzyG5wHqUu4XZpDbnWNxi6ugxnAGiL3CrIFdCgRNgHz5qS1l MustWin`}},
36+
"hostname": acctest.Representation{RepType: acctest.Required, Create: `tfOracleDb`},
37+
"db_home": acctest.RepresentationGroup{RepType: acctest.Required, Group: DbSystemBaseDbHomeGroup},
38+
}
39+
40+
DbSystemBaseDbHomeGroup = map[string]interface{}{
41+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `tfDbHome`},
42+
"db_version": acctest.Representation{RepType: acctest.Optional, Create: `19.0.0.0`},
43+
"database": acctest.RepresentationGroup{RepType: acctest.Required, Group: DbSystemBaseDatabaseGroup},
44+
}
45+
46+
DbSystemBaseDatabaseGroup = map[string]interface{}{
47+
"db_name": acctest.Representation{RepType: acctest.Optional, Create: `tfDb`},
48+
"pdb_name": acctest.Representation{RepType: acctest.Optional, Create: `tfPdb`},
49+
"character_set": acctest.Representation{RepType: acctest.Optional, Create: `AL32UTF8`},
50+
"ncharacter_set": acctest.Representation{RepType: acctest.Optional, Create: `AL16UTF16`},
51+
"db_workload": acctest.Representation{RepType: acctest.Optional, Create: `OLTP`},
52+
"kms_key_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.kms_key_id}`},
53+
"kms_key_version_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.kms_key_version_id}`},
54+
"vault_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.vault_id}`},
55+
"admin_password": acctest.Representation{RepType: acctest.Required, Create: `BEstrO0ng_#11`},
56+
}
2457
)
2558

2659
// issue-routing-tag: database/default
2760
func TestDatabaseDbSystemPatchResource_basic(t *testing.T) {
2861
httpreplay.SetScenario("TestDatabaseDbSystemPatchResource_basic")
2962
defer httpreplay.SaveScenario()
3063

31-
config := acctest.ProviderTestConfig()
32-
33-
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
34-
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
64+
config := acctest.BaseDBProviderTestConfig()
3565

3666
datasourceName := "data.oci_database_db_system_patches.test_db_system_patches"
3767

38-
acctest.SaveConfigContent("", "", "", t)
39-
4068
acctest.ResourceTest(t, nil, []resource.TestStep{
4169
// verify datasource
4270
{
4371
Config: config +
44-
acctest.GenerateDataSourceFromRepresentationMap("oci_database_db_system_patches", "test_db_system_patches", acctest.Required, acctest.Create, DatabaseDatabaseDbSystemPatchDataSourceRepresentation) +
45-
compartmentIdVariableStr + DatabaseDbSystemPatchResourceConfig,
72+
acctest.GenerateDataSourceFromRepresentationMap("oci_database_db_system_patches", "test_db_system_patches", acctest.Optional, acctest.Create, DatabaseDatabaseDbSystemPatchDataSourceRepresentation) +
73+
DbSystemBaseConfig +
74+
acctest.GenerateResourceFromRepresentationMap("oci_database_db_system", "test_db_system", acctest.Optional, acctest.Create, DbSystemResourceBaseRepresentation),
4675
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
4776
resource.TestCheckResourceAttrSet(datasourceName, "db_system_id"),
48-
4977
resource.TestCheckResourceAttrSet(datasourceName, "patches.#"),
5078
resource.TestCheckResourceAttrSet(datasourceName, "patches.0.description"),
5179
resource.TestCheckResourceAttrSet(datasourceName, "patches.0.id"),

0 commit comments

Comments
 (0)