|
| 1 | +// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + |
| 3 | +package integrationtest |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 11 | + |
| 12 | + "github.com/oracle/terraform-provider-oci/httpreplay" |
| 13 | + "github.com/oracle/terraform-provider-oci/internal/acctest" |
| 14 | + "github.com/oracle/terraform-provider-oci/internal/utils" |
| 15 | +) |
| 16 | + |
| 17 | +var ( |
| 18 | + mysqlDbSystemRepresentationWithCustomerContacts = map[string]interface{}{ |
| 19 | + "admin_password": acctest.Representation{RepType: acctest.Required, Create: `BEstrO0ng_#11`}, |
| 20 | + "admin_username": acctest.Representation{RepType: acctest.Required, Create: `adminUser`}, |
| 21 | + "availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`}, |
| 22 | + "compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`}, |
| 23 | + "configuration_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.MysqlConfigurationOCID[var.region]}`}, |
| 24 | + "shape_name": acctest.Representation{RepType: acctest.Required, Create: `MySQL.VM.Standard.E3.1.8GB`}, |
| 25 | + "subnet_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_subnet.test_subnet.id}`}, |
| 26 | + "data_storage_size_in_gb": acctest.Representation{RepType: acctest.Required, Create: `50`}, |
| 27 | + "customer_contacts": acctest.RepresentationGroup{RepType: acctest.Optional, Group: MysqlMysqlDbSystemCustomerContacts}, |
| 28 | + } |
| 29 | + |
| 30 | + MysqlMysqlDbSystemCustomerContacts = map[string]interface{}{ |
| 31 | + "email": acctest. Representation{ RepType: acctest. Required, Create: `[email protected]`, Update: `[email protected]`}, |
| 32 | + } |
| 33 | +) |
| 34 | + |
| 35 | +// issue-routing-tag: mysql/default |
| 36 | +func TestMysqlMysqlDbSystemResource_customerContacts(t *testing.T) { |
| 37 | + httpreplay.SetScenario("TestMysqlMysqlDbSystemResource_customerContacts") |
| 38 | + defer httpreplay.SaveScenario() |
| 39 | + |
| 40 | + config := acctest.ProviderTestConfig() |
| 41 | + |
| 42 | + compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid") |
| 43 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 44 | + |
| 45 | + resourceName := "oci_mysql_mysql_db_system.test_mysql_db_system" |
| 46 | + |
| 47 | + var resId, resId2 string |
| 48 | + |
| 49 | + acctest.ResourceTest(t, nil, []resource.TestStep{ |
| 50 | + // verify Create with optional fields |
| 51 | + { |
| 52 | + Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies + |
| 53 | + acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Create, mysqlDbSystemRepresentationWithCustomerContacts), |
| 54 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 55 | + resource.TestCheckResourceAttr(resourceName, "customer_contacts.#", "1"), |
| 56 | + resource. TestCheckResourceAttr( resourceName, "customer_contacts.0.email", "[email protected]"), |
| 57 | + |
| 58 | + func(s *terraform.State) (err error) { |
| 59 | + resId, err = acctest.FromInstanceState(s, resourceName, "id") |
| 60 | + return err |
| 61 | + }, |
| 62 | + ), |
| 63 | + }, |
| 64 | + |
| 65 | + // verify it is possible to change the customer contacts |
| 66 | + { |
| 67 | + Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies + |
| 68 | + acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Update, mysqlDbSystemRepresentationWithCustomerContacts), |
| 69 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 70 | + resource.TestCheckResourceAttr(resourceName, "customer_contacts.#", "1"), |
| 71 | + resource. TestCheckResourceAttr( resourceName, "customer_contacts.0.email", "[email protected]"), |
| 72 | + |
| 73 | + func(s *terraform.State) (err error) { |
| 74 | + resId2, err = acctest.FromInstanceState(s, resourceName, "id") |
| 75 | + if resId != resId2 { |
| 76 | + return fmt.Errorf("Resource recreated when it was supposed to be updated.") |
| 77 | + } |
| 78 | + return err |
| 79 | + }, |
| 80 | + ), |
| 81 | + }, |
| 82 | + }) |
| 83 | +} |
0 commit comments