Skip to content

Commit eb1cffe

Browse files
Added support for Postgres in google_sql_source_representation_instance (#7840) (#14436)
* Updated validation for DatabaseVersion field of Source Representation Instance * Added tests for creating source representation instance with postgres Signed-off-by: Modular Magician <[email protected]>
1 parent f145715 commit eb1cffe

4 files changed

+66
-3
lines changed

.changelog/7840.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
sql: Added support for Postgres in `google_sql_source_representation_instance`
3+
```

google/resource_sql_source_representation_instance.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func ResourceSQLSourceRepresentationInstance() *schema.Resource {
4949
Type: schema.TypeString,
5050
Required: true,
5151
ForceNew: true,
52-
ValidateFunc: validateEnum([]string{"MYSQL_5_5", "MYSQL_5_6", "MYSQL_5_7", "MYSQL_8_0"}),
53-
Description: `The MySQL version running on your source database server. Possible values: ["MYSQL_5_5", "MYSQL_5_6", "MYSQL_5_7", "MYSQL_8_0"]`,
52+
ValidateFunc: validateEnum([]string{"MYSQL_5_6", "MYSQL_5_7", "MYSQL_8_0", "POSTGRES_9_6", "POSTGRES_10", "POSTGRES_11", "POSTGRES_12", "POSTGRES_13", "POSTGRES_14"}),
53+
Description: `The MySQL version running on your source database server. Possible values: ["MYSQL_5_6", "MYSQL_5_7", "MYSQL_8_0", "POSTGRES_9_6", "POSTGRES_10", "POSTGRES_11", "POSTGRES_12", "POSTGRES_13", "POSTGRES_14"]`,
5454
},
5555
"name": {
5656
Type: schema.TypeString,

google/resource_sql_source_representation_instance_generated_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,46 @@ resource "google_sql_source_representation_instance" "instance" {
6363
`, context)
6464
}
6565

66+
func TestAccSQLSourceRepresentationInstance_sqlSourceRepresentationInstancePostgresExample(t *testing.T) {
67+
t.Parallel()
68+
69+
context := map[string]interface{}{
70+
"random_suffix": RandString(t, 10),
71+
}
72+
73+
VcrTest(t, resource.TestCase{
74+
PreCheck: func() { AccTestPreCheck(t) },
75+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
76+
CheckDestroy: testAccCheckSQLSourceRepresentationInstanceDestroyProducer(t),
77+
Steps: []resource.TestStep{
78+
{
79+
Config: testAccSQLSourceRepresentationInstance_sqlSourceRepresentationInstancePostgresExample(context),
80+
},
81+
{
82+
ResourceName: "google_sql_source_representation_instance.instance",
83+
ImportState: true,
84+
ImportStateVerify: true,
85+
ImportStateVerifyIgnore: []string{"password"},
86+
},
87+
},
88+
})
89+
}
90+
91+
func testAccSQLSourceRepresentationInstance_sqlSourceRepresentationInstancePostgresExample(context map[string]interface{}) string {
92+
return Nprintf(`
93+
resource "google_sql_source_representation_instance" "instance" {
94+
name = "tf-test-my-instance%{random_suffix}"
95+
region = "us-central1"
96+
database_version = "POSTGRES_9_6"
97+
host = "10.20.30.40"
98+
port = 3306
99+
username = "some-user"
100+
password = "password-for-the-user"
101+
dump_file_path = "gs://replica-bucket/source-database.sql.gz"
102+
}
103+
`, context)
104+
}
105+
66106
func testAccCheckSQLSourceRepresentationInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error {
67107
return func(s *terraform.State) error {
68108
for name, rs := range s.RootModule().Resources {

website/docs/r/sql_source_representation_instance.html.markdown

+21-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ resource "google_sql_source_representation_instance" "instance" {
5252
dump_file_path = "gs://replica-bucket/source-database.sql.gz"
5353
}
5454
```
55+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
56+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=sql_source_representation_instance_postgres&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
57+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
58+
</a>
59+
</div>
60+
## Example Usage - Sql Source Representation Instance Postgres
61+
62+
63+
```hcl
64+
resource "google_sql_source_representation_instance" "instance" {
65+
name = "my-instance"
66+
region = "us-central1"
67+
database_version = "POSTGRES_9_6"
68+
host = "10.20.30.40"
69+
port = 3306
70+
username = "some-user"
71+
password = "password-for-the-user"
72+
dump_file_path = "gs://replica-bucket/source-database.sql.gz"
73+
}
74+
```
5575

5676
## Argument Reference
5777

@@ -65,7 +85,7 @@ The following arguments are supported:
6585
* `database_version` -
6686
(Required)
6787
The MySQL version running on your source database server.
68-
Possible values are: `MYSQL_5_5`, `MYSQL_5_6`, `MYSQL_5_7`, `MYSQL_8_0`.
88+
Possible values are: `MYSQL_5_6`, `MYSQL_5_7`, `MYSQL_8_0`, `POSTGRES_9_6`, `POSTGRES_10`, `POSTGRES_11`, `POSTGRES_12`, `POSTGRES_13`, `POSTGRES_14`.
6989

7090
* `host` -
7191
(Required)

0 commit comments

Comments
 (0)