Skip to content

Commit 2b26068

Browse files
committed
autonomous vm cluster resource and data source
1 parent bfdc400 commit 2b26068

File tree

7 files changed

+2252
-0
lines changed

7 files changed

+2252
-0
lines changed

internal/service/odb/cloud_autonomous_vm_cluster.go

Lines changed: 866 additions & 0 deletions
Large diffs are not rendered by default.

internal/service/odb/cloud_autonomous_vm_cluster_data_source.go

Lines changed: 433 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
//Copyright © 2025, Oracle and/or its affiliates. All rights reserved.
2+
3+
package odb_test
4+
5+
import (
6+
"context"
7+
"errors"
8+
"fmt"
9+
"github.com/aws/aws-sdk-go-v2/aws"
10+
"github.com/aws/aws-sdk-go-v2/service/odb"
11+
odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
13+
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
14+
"github.com/hashicorp/terraform-plugin-testing/terraform"
15+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
16+
"github.com/hashicorp/terraform-provider-aws/internal/create"
17+
"github.com/hashicorp/terraform-provider-aws/internal/errs"
18+
tfodb "github.com/hashicorp/terraform-provider-aws/internal/service/odb"
19+
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
20+
"testing"
21+
22+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
23+
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
24+
"github.com/hashicorp/terraform-provider-aws/names"
25+
)
26+
27+
type autonomousVMClusterDSTest struct {
28+
exaInfraDisplayNamePrefix string
29+
odbNetDisplayNamePrefix string
30+
autonomousVmClusterDisplayNamePrefix string
31+
}
32+
33+
var autonomousVMClusterDSTestEntity = autonomousVMClusterDSTest{
34+
exaInfraDisplayNamePrefix: "Ofake-exa",
35+
odbNetDisplayNamePrefix: "odb-net",
36+
autonomousVmClusterDisplayNamePrefix: "Ofake-avmc",
37+
}
38+
39+
func TestAccODBCloudAutonomousVmClusterDataSource_basic(t *testing.T) {
40+
ctx := acctest.Context(t)
41+
42+
if testing.Short() {
43+
t.Skip("skipping long-running test in short mode")
44+
}
45+
var avmc1 odbtypes.CloudAutonomousVmCluster
46+
dataSourceName := "data.aws_odb_cloud_autonomous_vm_cluster.test"
47+
48+
resource.ParallelTest(t, resource.TestCase{
49+
PreCheck: func() {
50+
acctest.PreCheck(ctx, t)
51+
autonomousVMClusterDSTestEntity.testAccPreCheck(ctx, t)
52+
},
53+
ErrorCheck: acctest.ErrorCheck(t, names.ODBServiceID),
54+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
55+
CheckDestroy: autonomousVMClusterDSTestEntity.testAccCheckCloudAutonomousVmClusterDestroy(ctx),
56+
Steps: []resource.TestStep{
57+
{
58+
Config: autonomousVMClusterDSTestEntity.avmcBasic(),
59+
Check: resource.ComposeAggregateTestCheckFunc(
60+
resource.TestCheckResourceAttr(dataSourceName, "display_name", *avmc1.DisplayName),
61+
),
62+
},
63+
},
64+
})
65+
}
66+
func (autonomousVMClusterDSTest) checkCloudAutonomousVmClusterExists(ctx context.Context, name string, cloudAutonomousVMCluster *odbtypes.CloudAutonomousVmCluster) resource.TestCheckFunc {
67+
return func(s *terraform.State) error {
68+
rs, ok := s.RootModule().Resources[name]
69+
if !ok {
70+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudAutonomousVmCluster, name, errors.New("not found"))
71+
}
72+
73+
if rs.Primary.ID == "" {
74+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudAutonomousVmCluster, name, errors.New("not set"))
75+
}
76+
77+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
78+
resp, err := autonomousVMClusterDSTestEntity.findAVMC(ctx, conn, rs.Primary.ID)
79+
if err != nil {
80+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudAutonomousVmCluster, rs.Primary.ID, err)
81+
}
82+
83+
*cloudAutonomousVMCluster = *resp
84+
85+
return nil
86+
}
87+
}
88+
89+
func (autonomousVMClusterDSTest) findAVMC(ctx context.Context, conn *odb.Client, id string) (*odbtypes.CloudAutonomousVmCluster, error) {
90+
input := odb.GetCloudAutonomousVmClusterInput{
91+
CloudAutonomousVmClusterId: aws.String(id),
92+
}
93+
out, err := conn.GetCloudAutonomousVmCluster(ctx, &input)
94+
if err != nil {
95+
if errs.IsA[*odbtypes.ResourceNotFoundException](err) {
96+
return nil, &retry.NotFoundError{
97+
LastError: err,
98+
LastRequest: &input,
99+
}
100+
}
101+
return nil, err
102+
}
103+
104+
if out == nil || out.CloudAutonomousVmCluster == nil {
105+
return nil, tfresource.NewEmptyResultError(&input)
106+
}
107+
108+
return out.CloudAutonomousVmCluster, nil
109+
}
110+
111+
func (autonomousVMClusterDSTest) testAccCheckCloudAutonomousVmClusterDestroy(ctx context.Context) resource.TestCheckFunc {
112+
return func(s *terraform.State) error {
113+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
114+
115+
for _, rs := range s.RootModule().Resources {
116+
if rs.Type != "aws_odb_cloud_autonomous_vm_cluster" {
117+
continue
118+
}
119+
120+
_, err := tfodb.FindCloudAutonomousVmClusterByID(ctx, conn, rs.Primary.ID)
121+
if tfresource.NotFound(err) {
122+
return nil
123+
}
124+
if err != nil {
125+
return create.Error(names.ODB, create.ErrActionCheckingDestroyed, tfodb.ResNameCloudAutonomousVmCluster, rs.Primary.ID, err)
126+
}
127+
128+
return create.Error(names.ODB, create.ErrActionCheckingDestroyed, tfodb.ResNameCloudAutonomousVmCluster, rs.Primary.ID, errors.New("not destroyed"))
129+
}
130+
131+
return nil
132+
}
133+
}
134+
func (autonomousVMClusterDSTest) testAccPreCheck(ctx context.Context, t *testing.T) {
135+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
136+
137+
input := &odb.ListCloudAutonomousVmClustersInput{}
138+
139+
_, err := conn.ListCloudAutonomousVmClusters(ctx, input)
140+
141+
if acctest.PreCheckSkipError(err) {
142+
t.Skipf("skipping acceptance testing: %s", err)
143+
}
144+
if err != nil {
145+
t.Fatalf("unexpected PreCheck error: %s", err)
146+
}
147+
}
148+
149+
func (autonomousVMClusterDSTest) avmcBasic() string {
150+
151+
exaInfraDisplayName := sdkacctest.RandomWithPrefix(autonomousVMClusterDSTestEntity.exaInfraDisplayNamePrefix)
152+
odbNetworkDisplayName := sdkacctest.RandomWithPrefix(autonomousVMClusterDSTestEntity.odbNetDisplayNamePrefix)
153+
avmcDisplayName := sdkacctest.RandomWithPrefix(autonomousVMClusterDSTestEntity.autonomousVmClusterDisplayNamePrefix)
154+
155+
exaInfraRes := autonomousVMClusterDSTestEntity.exaInfra(exaInfraDisplayName)
156+
odbNetRes := autonomousVMClusterDSTestEntity.odbNet(odbNetworkDisplayName)
157+
res := fmt.Sprintf(`
158+
%s
159+
160+
%s
161+
162+
data "aws_odb_db_servers_list" "test" {
163+
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
164+
}
165+
166+
resource "aws_odb_cloud_autonomous_vm_cluster" "test" {
167+
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
168+
odb_network_id =aws_odb_network.test.id
169+
display_name = %[3]q
170+
autonomous_data_storage_size_in_tbs = 5
171+
memory_per_oracle_compute_unit_in_gbs = 2
172+
total_container_databases = 1
173+
cpu_core_count_per_node = 40
174+
license_model = "LICENSE_INCLUDED"
175+
db_servers = [ for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
176+
scan_listener_port_tls = 8561
177+
scan_listener_port_non_tls = 1024
178+
maintenance_window = {
179+
preference = "NO_PREFERENCE"
180+
days_of_week = []
181+
hours_of_day = []
182+
months = []
183+
weeks_of_month =[]
184+
lead_time_in_weeks = 0
185+
}
186+
187+
}
188+
189+
190+
data "aws_odb_cloud_autonomous_vm_cluster" "test" {
191+
id = aws_odb_cloud_autonomous_vm_cluster.test.id
192+
193+
}
194+
`, exaInfraRes, odbNetRes, avmcDisplayName)
195+
196+
return res
197+
}
198+
199+
func (autonomousVMClusterDSTest) odbNet(odbNetName string) string {
200+
networkRes := fmt.Sprintf(`
201+
202+
203+
resource "aws_odb_network" "test" {
204+
display_name = %[1]q
205+
availability_zone_id = "use1-az6"
206+
client_subnet_cidr = "10.2.0.0/24"
207+
backup_subnet_cidr = "10.2.1.0/24"
208+
s3_access = "DISABLED"
209+
zero_etl_access = "DISABLED"
210+
}
211+
212+
`, odbNetName)
213+
return networkRes
214+
}
215+
216+
func (autonomousVMClusterDSTest) exaInfra(exaInfraName string) string {
217+
exaInfraRes := fmt.Sprintf(`
218+
219+
220+
resource "aws_odb_cloud_exadata_infrastructure" "test" {
221+
display_name = %[1]q
222+
shape = "Exadata.X9M"
223+
storage_count = 3
224+
compute_count = 2
225+
availability_zone_id = "use1-az6"
226+
customer_contacts_to_send_to_oci = ["[email protected]"]
227+
maintenance_window = {
228+
custom_action_timeout_in_mins = 16
229+
days_of_week = []
230+
hours_of_day = []
231+
is_custom_action_timeout_enabled = true
232+
lead_time_in_weeks = 0
233+
months = []
234+
patching_mode = "ROLLING"
235+
preference = "NO_PREFERENCE"
236+
weeks_of_month =[]
237+
}
238+
}
239+
240+
`, exaInfraName)
241+
return exaInfraRes
242+
}

0 commit comments

Comments
 (0)