Skip to content

Commit

Permalink
updates for first-gen to second-gen upgrade sql_database_instance
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
megan07 authored and modular-magician committed Jan 14, 2020
1 parent de73a65 commit 84f0ac8
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 134 deletions.
26 changes: 15 additions & 11 deletions google-beta/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const privateNetworkLinkRegex = "projects/(" + ProjectRegex + ")/global/networks
var sqlDatabaseAuthorizedNetWorkSchemaElem *schema.Resource = &schema.Resource{
Schema: map[string]*schema.Schema{
"expiration_time": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
Deprecated: "This property is only applicable to First Generation instances, and First Generation instances are now deprecated.",
},
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -127,9 +128,10 @@ func resourceSqlDatabaseInstance() *schema.Resource {
Computed: true,
},
"authorized_gae_applications": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Deprecated: "This property is only applicable to First Generation instances, and First Generation instances are now deprecated.",
},
"availability_type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -174,9 +176,10 @@ func resourceSqlDatabaseInstance() *schema.Resource {
},
},
"crash_safe_replication": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Type: schema.TypeBool,
Optional: true,
Computed: true,
Deprecated: "This property is only applicable to First Generation instances, and First Generation instances are now deprecated.",
},
"database_flags": {
Type: schema.TypeList,
Expand Down Expand Up @@ -300,9 +303,10 @@ func resourceSqlDatabaseInstance() *schema.Resource {
Default: "PER_USE",
},
"replication_type": {
Type: schema.TypeString,
Optional: true,
Default: "SYNCHRONOUS",
Type: schema.TypeString,
Optional: true,
Deprecated: "This property is only applicable to First Generation instances, and First Generation instances are now deprecated.",
Default: "SYNCHRONOUS",
},
"user_labels": {
Type: schema.TypeMap,
Expand Down
95 changes: 20 additions & 75 deletions google-beta/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,42 +146,6 @@ func testSweepDatabases(region string) error {
return nil
}

func TestAccSqlDatabaseInstance_basicFirstGen(t *testing.T) {
t.Parallel()

instanceID := acctest.RandInt()
instanceName := fmt.Sprintf("tf-lw-%d", instanceID)
resourceName := "google_sql_database_instance.instance"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccSqlDatabaseInstanceDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testGoogleSqlDatabaseInstance_basic, instanceID),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
ResourceName: resourceName,
ImportStateId: fmt.Sprintf("projects/%s/instances/%s", getTestProjectFromEnv(), instanceName),
ImportState: true,
ImportStateVerify: true,
},
{
ResourceName: resourceName,
ImportStateId: fmt.Sprintf("%s/%s", getTestProjectFromEnv(), instanceName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccSqlDatabaseInstance_basicInferredName(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -302,7 +266,7 @@ func TestAccSqlDatabaseInstance_dontDeleteDefaultUserOnReplica(t *testing.T) {
func TestAccSqlDatabaseInstance_settings_basic(t *testing.T) {
t.Parallel()

databaseID := acctest.RandInt()
databaseName := "tf-test-" + acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -311,7 +275,7 @@ func TestAccSqlDatabaseInstance_settings_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_settings, databaseID),
testGoogleSqlDatabaseInstance_settings, databaseName),
},
{
ResourceName: "google_sql_database_instance.instance",
Expand Down Expand Up @@ -458,7 +422,7 @@ func TestAccSqlDatabaseInstance_maintenance(t *testing.T) {
func TestAccSqlDatabaseInstance_settings_upgrade(t *testing.T) {
t.Parallel()

databaseID := acctest.RandInt()
databaseName := "tf-test-" + acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -467,7 +431,7 @@ func TestAccSqlDatabaseInstance_settings_upgrade(t *testing.T) {
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_basic, databaseID),
testGoogleSqlDatabaseInstance_basic3, databaseName),
},
{
ResourceName: "google_sql_database_instance.instance",
Expand All @@ -476,7 +440,7 @@ func TestAccSqlDatabaseInstance_settings_upgrade(t *testing.T) {
},
{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_settings, databaseID),
testGoogleSqlDatabaseInstance_settings, databaseName),
},
{
ResourceName: "google_sql_database_instance.instance",
Expand All @@ -490,7 +454,7 @@ func TestAccSqlDatabaseInstance_settings_upgrade(t *testing.T) {
func TestAccSqlDatabaseInstance_settingsDowngrade(t *testing.T) {
t.Parallel()

databaseID := acctest.RandInt()
databaseName := "tf-test-" + acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -499,7 +463,7 @@ func TestAccSqlDatabaseInstance_settingsDowngrade(t *testing.T) {
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_settings, databaseID),
testGoogleSqlDatabaseInstance_settings, databaseName),
},
{
ResourceName: "google_sql_database_instance.instance",
Expand All @@ -508,7 +472,7 @@ func TestAccSqlDatabaseInstance_settingsDowngrade(t *testing.T) {
},
{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_basic, databaseID),
testGoogleSqlDatabaseInstance_basic3, databaseName),
},
{
ResourceName: "google_sql_database_instance.instance",
Expand Down Expand Up @@ -680,23 +644,11 @@ func testAccCheckGoogleSqlDatabaseRootUserDoesNotExist(instance string) resource
}
}

var testGoogleSqlDatabaseInstance_basic = `
resource "google_sql_database_instance" "instance" {
name = "tf-lw-%d"
region = "us-central"
settings {
tier = "D0"
crash_safe_replication = false
}
}
`

var testGoogleSqlDatabaseInstance_basic2 = `
resource "google_sql_database_instance" "instance" {
region = "us-central"
region = "us-central1"
settings {
tier = "D0"
crash_safe_replication = false
tier = "db-f1-micro"
}
}
`
Expand Down Expand Up @@ -814,12 +766,10 @@ resource "google_sql_database_instance" "instance" {

var testGoogleSqlDatabaseInstance_settings = `
resource "google_sql_database_instance" "instance" {
name = "tf-lw-%d"
region = "us-central"
name = "%s"
region = "us-central1"
settings {
tier = "D0"
crash_safe_replication = false
replication_type = "ASYNCHRONOUS"
tier = "db-f1-micro"
location_preference {
zone = "us-central1-f"
}
Expand All @@ -829,7 +779,6 @@ resource "google_sql_database_instance" "instance" {
authorized_networks {
value = "108.12.12.12"
name = "misc"
expiration_time = "2050-11-15T16:19:00.094Z"
}
}
Expand All @@ -838,7 +787,7 @@ resource "google_sql_database_instance" "instance" {
start_time = "19:19"
}
activation_policy = "ON_DEMAND"
activation_policy = "ALWAYS"
}
}
`
Expand Down Expand Up @@ -983,17 +932,15 @@ resource "google_sql_database_instance" "instance" {
var testGoogleSqlDatabaseInstance_authNets_step1 = `
resource "google_sql_database_instance" "instance" {
name = "tf-lw-%d"
region = "us-central"
region = "us-central1"
settings {
tier = "D0"
crash_safe_replication = false
tier = "db-f1-micro"
ip_configuration {
ipv4_enabled = "true"
authorized_networks {
value = "108.12.12.12"
name = "misc"
expiration_time = "2050-11-15T16:19:00.094Z"
}
}
}
Expand All @@ -1003,10 +950,9 @@ resource "google_sql_database_instance" "instance" {
var testGoogleSqlDatabaseInstance_authNets_step2 = `
resource "google_sql_database_instance" "instance" {
name = "tf-lw-%d"
region = "us-central"
region = "us-central1"
settings {
tier = "D0"
crash_safe_replication = false
tier = "db-f1-micro"
ip_configuration {
ipv4_enabled = "true"
Expand All @@ -1018,10 +964,9 @@ resource "google_sql_database_instance" "instance" {
var testGoogleSqlDatabaseInstance_multipleOperations = `
resource "google_sql_database_instance" "instance" {
name = "tf-test-%s"
region = "us-central"
region = "us-central1"
settings {
tier = "D0"
crash_safe_replication = false
tier = "db-f1-micro"
}
}
Expand Down
Loading

0 comments on commit 84f0ac8

Please sign in to comment.