Skip to content

Commit 408bf85

Browse files
Terraform Team Automationvsin12
authored andcommitted
Added - Support for Automatic Primary Key Handling and Delayed Replication in MDS Channels
1 parent 01f7632 commit 408bf85

File tree

10 files changed

+119
-63
lines changed

10 files changed

+119
-63
lines changed

examples/mysql/channel/main.tf

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ resource "oci_core_vcn" "test_vcn" {
3737
compartment_id = var.compartment_ocid
3838
}
3939

40+
data "oci_mysql_mysql_configurations" "test_mysql_configurations" {
41+
compartment_id = var.compartment_ocid
42+
43+
#Optional
44+
state = "ACTIVE"
45+
shape_name = "VM.Standard.E2.4"
46+
}
47+
48+
data "oci_identity_availability_domains" "test_availability_domains" {
49+
compartment_id = var.tenancy_ocid
50+
}
51+
4052
resource "oci_mysql_mysql_db_system" "test_mysql_db_system" {
4153
#Required
4254
admin_password = "BEstrO0ng_#11"
@@ -73,26 +85,6 @@ resource "oci_mysql_mysql_db_system" "test_mysql_db_system" {
7385

7486
}
7587

76-
data "oci_mysql_mysql_configurations" "test_mysql_configurations" {
77-
compartment_id = var.compartment_ocid
78-
79-
#Optional
80-
state = "ACTIVE"
81-
shape_name = "VM.Standard.E2.4"
82-
}
83-
84-
data "oci_mysql_shapes" "test_shapes" {
85-
compartment_id = var.compartment_ocid
86-
}
87-
88-
data "oci_identity_availability_domains" "test_availability_domains" {
89-
compartment_id = var.tenancy_ocid
90-
}
91-
92-
output "configuration_id" {
93-
value = data.oci_mysql_mysql_configurations.test_mysql_configurations.configurations[0].id
94-
}
95-
9688
resource "oci_mysql_channel" "test_channel" {
9789
#Required
9890
source {
@@ -122,6 +114,8 @@ resource "oci_mysql_channel" "test_channel" {
122114
type = "REPLICATE_DO_DB"
123115
value = "value"
124116
}
117+
delay_in_seconds = "60"
118+
tables_without_primary_key_handling = "GENERATE_IMPLICIT_PRIMARY_KEY"
125119
}
126120
}
127121

@@ -139,6 +133,6 @@ data "oci_mysql_channel" "test_channel" {
139133
channel_id = oci_mysql_channel.test_channel.id
140134
}
141135

142-
//data "oci_mysql_mysql_db_system" "test_mysql_db_system" {
143-
// db_system_id = oci_mysql_mysql_db_system.test_mysql_backup_db_system.id
144-
//}
136+
output "channel_id" {
137+
value = data.oci_mysql_channel.test_channel.id
138+
}

internal/integrationtest/mysql_channel_test.go

Lines changed: 48 additions & 40 deletions
Large diffs are not rendered by default.

internal/service/mysql/mysql_channel_resource.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ func MysqlChannelResource() *schema.Resource {
184184
Optional: true,
185185
Computed: true,
186186
},
187+
"delay_in_seconds": {
188+
Type: schema.TypeInt,
189+
Optional: true,
190+
Computed: true,
191+
},
187192
"filters": {
188193
Type: schema.TypeList,
189194
Optional: true,
@@ -206,6 +211,11 @@ func MysqlChannelResource() *schema.Resource {
206211
},
207212
},
208213
},
214+
"tables_without_primary_key_handling": {
215+
Type: schema.TypeString,
216+
Optional: true,
217+
Computed: true,
218+
},
209219

210220
// Computed
211221
},
@@ -879,6 +889,10 @@ func (s *MysqlChannelResourceCrud) mapToCreateChannelTargetDetails(fieldKeyForma
879889
tmp := channelName.(string)
880890
details.ChannelName = &tmp
881891
}
892+
if delayInSeconds, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "delay_in_seconds")); ok {
893+
tmp := delayInSeconds.(int)
894+
details.DelayInSeconds = &tmp
895+
}
882896
if dbSystemId, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "db_system_id")); ok {
883897
tmp := dbSystemId.(string)
884898
details.DbSystemId = &tmp
@@ -899,6 +913,9 @@ func (s *MysqlChannelResourceCrud) mapToCreateChannelTargetDetails(fieldKeyForma
899913
details.Filters = tmp
900914
}
901915
}
916+
if tablesWithoutPrimaryKeyHandling, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "tables_without_primary_key_handling")); ok {
917+
details.TablesWithoutPrimaryKeyHandling = oci_mysql.ChannelTargetDbSystemTablesWithoutPrimaryKeyHandlingEnum(tablesWithoutPrimaryKeyHandling.(string))
918+
}
902919
baseObject = details
903920
default:
904921
return nil, fmt.Errorf("unknown target_type '%v' was specified", targetType)
@@ -927,6 +944,10 @@ func (s *MysqlChannelResourceCrud) mapToUpdateChannelTargetDetails(fieldKeyForma
927944
tmp := channelName.(string)
928945
details.ChannelName = &tmp
929946
}
947+
if delayInSeconds, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "delay_in_seconds")); ok {
948+
tmp := delayInSeconds.(int)
949+
details.DelayInSeconds = &tmp
950+
}
930951
if filters, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "filters")); ok {
931952
interfaces := filters.([]interface{})
932953
tmp := make([]oci_mysql.ChannelFilter, len(interfaces))
@@ -943,6 +964,9 @@ func (s *MysqlChannelResourceCrud) mapToUpdateChannelTargetDetails(fieldKeyForma
943964
details.Filters = tmp
944965
}
945966
}
967+
if tablesWithoutPrimaryKeyHandling, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "tables_without_primary_key_handling")); ok {
968+
details.TablesWithoutPrimaryKeyHandling = oci_mysql.ChannelTargetDbSystemTablesWithoutPrimaryKeyHandlingEnum(tablesWithoutPrimaryKeyHandling.(string))
969+
}
946970
baseObject = details
947971
default:
948972
return nil, fmt.Errorf("unknown target_type '%v' was specified", targetType)

internal/service/mysql/mysql_mysql_db_system_resource.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ func MysqlMysqlDbSystemResource() *schema.Resource {
519519
Type: schema.TypeString,
520520
Computed: true,
521521
},
522+
"delay_in_seconds": {
523+
Type: schema.TypeInt,
524+
Computed: true,
525+
},
522526
"filters": {
523527
Type: schema.TypeList,
524528
Computed: true,
@@ -540,6 +544,10 @@ func MysqlMysqlDbSystemResource() *schema.Resource {
540544
},
541545
},
542546
},
547+
"tables_without_primary_key_handling": {
548+
Type: schema.TypeString,
549+
Computed: true,
550+
},
543551
"target_type": {
544552
Type: schema.TypeString,
545553
Computed: true,
@@ -1590,11 +1598,17 @@ func ChannelTargetToMap(obj *oci_mysql.ChannelTarget) map[string]interface{} {
15901598
result["db_system_id"] = string(*v.DbSystemId)
15911599
}
15921600

1601+
if v.DelayInSeconds != nil {
1602+
result["delay_in_seconds"] = int(*v.DelayInSeconds)
1603+
}
1604+
15931605
filters := []interface{}{}
15941606
for _, item := range v.Filters {
15951607
filters = append(filters, ChannelFilterToMap(item))
15961608
}
15971609
result["filters"] = filters
1610+
1611+
result["tables_without_primary_key_handling"] = string(v.TablesWithoutPrimaryKeyHandling)
15981612
default:
15991613
log.Printf("[WARN] Received 'target_type' of unknown type %v", *obj)
16001614
return nil

website/docs/d/mysql_channel.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ The following attributes are exported:
6161
* `applier_username` - The username for the replication applier of the target MySQL DB System.
6262
* `channel_name` - The case-insensitive name that identifies the replication channel. Channel names must follow the rules defined for [MySQL identifiers](https://dev.mysql.com/doc/refman/8.0/en/identifiers.html). The names of non-Deleted Channels must be unique for each DB System.
6363
* `db_system_id` - The OCID of the source DB System.
64+
* `delay_in_seconds` - Specifies the amount of time, in seconds, that the channel waits before applying a transaction received from the source.
6465
* `filters` - Replication filter rules to be applied at the DB System Channel target.
6566
* `type` - The type of the filter rule.
6667

6768
For details on each type, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html)
6869
* `value` - The body of the filter rule. This can represent a database, a table, or a database pair (represented as "db1->db2"). For more information, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html).
70+
* `tables_without_primary_key_handling` - Specifies how a replication channel handles the creation and alteration of tables that do not have a primary key.
6971
* `target_type` - The specific target identifier.
7072
* `time_created` - The date and time the Channel was created, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
7173
* `time_updated` - The time the Channel was last updated, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).

website/docs/d/mysql_channels.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ The following attributes are exported:
7777
* `applier_username` - The username for the replication applier of the target MySQL DB System.
7878
* `channel_name` - The case-insensitive name that identifies the replication channel. Channel names must follow the rules defined for [MySQL identifiers](https://dev.mysql.com/doc/refman/8.0/en/identifiers.html). The names of non-Deleted Channels must be unique for each DB System.
7979
* `db_system_id` - The OCID of the source DB System.
80+
* `delay_in_seconds` - Specifies the amount of time, in seconds, that the channel waits before applying a transaction received from the source.
8081
* `filters` - Replication filter rules to be applied at the DB System Channel target.
8182
* `type` - The type of the filter rule.
8283

8384
For details on each type, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html)
8485
* `value` - The body of the filter rule. This can represent a database, a table, or a database pair (represented as "db1->db2"). For more information, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html).
86+
* `tables_without_primary_key_handling` - Specifies how a replication channel handles the creation and alteration of tables that do not have a primary key.
8587
* `target_type` - The specific target identifier.
8688
* `time_created` - The date and time the Channel was created, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
8789
* `time_updated` - The time the Channel was last updated, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).

website/docs/d/mysql_mysql_db_system.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ The following attributes are exported:
9797
* `applier_username` - The username for the replication applier of the target MySQL DB System.
9898
* `channel_name` - The case-insensitive name that identifies the replication channel. Channel names must follow the rules defined for [MySQL identifiers](https://dev.mysql.com/doc/refman/8.0/en/identifiers.html). The names of non-Deleted Channels must be unique for each DB System.
9999
* `db_system_id` - The OCID of the source DB System.
100+
* `delay_in_seconds` - Specifies the amount of time, in seconds, that the channel waits before applying a transaction received from the source.
100101
* `filters` - Replication filter rules to be applied at the DB System Channel target.
101102
* `type` - The type of the filter rule.
102103

103104
For details on each type, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html)
104105
* `value` - The body of the filter rule. This can represent a database, a table, or a database pair (represented as "db1->db2"). For more information, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html).
106+
* `tables_without_primary_key_handling` - Specifies how a replication channel handles the creation and alteration of tables that do not have a primary key.
105107
* `target_type` - The specific target identifier.
106108
* `time_created` - The date and time the Channel was created, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
107109
* `time_updated` - The time the Channel was last updated, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).

website/docs/d/mysql_mysql_db_systems.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@ The following attributes are exported:
121121
* `applier_username` - The username for the replication applier of the target MySQL DB System.
122122
* `channel_name` - The case-insensitive name that identifies the replication channel. Channel names must follow the rules defined for [MySQL identifiers](https://dev.mysql.com/doc/refman/8.0/en/identifiers.html). The names of non-Deleted Channels must be unique for each DB System.
123123
* `db_system_id` - The OCID of the source DB System.
124+
* `delay_in_seconds` - Specifies the amount of time, in seconds, that the channel waits before applying a transaction received from the source.
124125
* `filters` - Replication filter rules to be applied at the DB System Channel target.
125126
* `type` - The type of the filter rule.
126127

127128
For details on each type, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html)
128129
* `value` - The body of the filter rule. This can represent a database, a table, or a database pair (represented as "db1->db2"). For more information, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html).
130+
* `tables_without_primary_key_handling` - Specifies how a replication channel handles the creation and alteration of tables that do not have a primary key.
129131
* `target_type` - The specific target identifier.
130132
* `time_created` - The date and time the Channel was created, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
131133
* `time_updated` - The time the Channel was last updated, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).

website/docs/r/mysql_channel.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ resource "oci_mysql_channel" "test_channel" {
5151
#Optional
5252
applier_username = var.channel_target_applier_username
5353
channel_name = oci_mysql_channel.test_channel.name
54+
delay_in_seconds = var.channel_target_delay_in_seconds
5455
filters {
5556
#Required
5657
type = var.channel_target_filters_type
5758
value = var.channel_target_filters_value
5859
}
60+
tables_without_primary_key_handling = var.channel_target_tables_without_primary_key_handling
5961
}
6062
6163
#Optional
@@ -97,11 +99,13 @@ The following arguments are supported:
9799
* `applier_username` - (Optional) (Updatable) The username for the replication applier of the target MySQL DB System.
98100
* `channel_name` - (Optional) (Updatable) The case-insensitive name that identifies the replication channel. Channel names must follow the rules defined for [MySQL identifiers](https://dev.mysql.com/doc/refman/8.0/en/identifiers.html). The names of non-Deleted Channels must be unique for each DB System.
99101
* `db_system_id` - (Required) The OCID of the target DB System.
102+
* `delay_in_seconds` - (Optional) (Updatable) Specifies the amount of time, in seconds, that the channel waits before applying a transaction received from the source.
100103
* `filters` - (Optional) (Updatable) Replication filter rules to be applied at the DB System Channel target.
101104
* `type` - (Required) (Updatable) The type of the filter rule.
102105

103106
For details on each type, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html)
104107
* `value` - (Required) (Updatable) The body of the filter rule. This can represent a database, a table, or a database pair (represented as "db1->db2"). For more information, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html).
108+
* `tables_without_primary_key_handling` - (Optional) (Updatable) Specifies how a replication channel handles the creation and alteration of tables that do not have a primary key. The default value is set to ALLOW.
105109
* `target_type` - (Required) (Updatable) The specific target identifier.
106110

107111

@@ -138,11 +142,13 @@ The following attributes are exported:
138142
* `applier_username` - The username for the replication applier of the target MySQL DB System.
139143
* `channel_name` - The case-insensitive name that identifies the replication channel. Channel names must follow the rules defined for [MySQL identifiers](https://dev.mysql.com/doc/refman/8.0/en/identifiers.html). The names of non-Deleted Channels must be unique for each DB System.
140144
* `db_system_id` - The OCID of the source DB System.
145+
* `delay_in_seconds` - Specifies the amount of time, in seconds, that the channel waits before applying a transaction received from the source.
141146
* `filters` - Replication filter rules to be applied at the DB System Channel target.
142147
* `type` - The type of the filter rule.
143148

144149
For details on each type, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html)
145150
* `value` - The body of the filter rule. This can represent a database, a table, or a database pair (represented as "db1->db2"). For more information, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html).
151+
* `tables_without_primary_key_handling` - Specifies how a replication channel handles the creation and alteration of tables that do not have a primary key.
146152
* `target_type` - The specific target identifier.
147153
* `time_created` - The date and time the Channel was created, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
148154
* `time_updated` - The time the Channel was last updated, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).

website/docs/r/mysql_mysql_db_system.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,13 @@ The following attributes are exported:
228228
* `applier_username` - The username for the replication applier of the target MySQL DB System.
229229
* `channel_name` - The case-insensitive name that identifies the replication channel. Channel names must follow the rules defined for [MySQL identifiers](https://dev.mysql.com/doc/refman/8.0/en/identifiers.html). The names of non-Deleted Channels must be unique for each DB System.
230230
* `db_system_id` - The OCID of the source DB System.
231+
* `delay_in_seconds` - Specifies the amount of time, in seconds, that the channel waits before applying a transaction received from the source.
231232
* `filters` - Replication filter rules to be applied at the DB System Channel target.
232233
* `type` - The type of the filter rule.
233234

234235
For details on each type, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html)
235236
* `value` - The body of the filter rule. This can represent a database, a table, or a database pair (represented as "db1->db2"). For more information, see [Replication Filtering Rules](https://dev.mysql.com/doc/refman/8.0/en/replication-rules.html).
237+
* `tables_without_primary_key_handling` - Specifies how a replication channel handles the creation and alteration of tables that do not have a primary key.
236238
* `target_type` - The specific target identifier.
237239
* `time_created` - The date and time the Channel was created, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
238240
* `time_updated` - The time the Channel was last updated, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).

0 commit comments

Comments
 (0)