Skip to content

Commit

Permalink
minor fixes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jseriff authored and jseriff-applied committed May 18, 2022
1 parent 405d5f1 commit 3d02824
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
1 change: 0 additions & 1 deletion mmv1/third_party/terraform/resources/resource_sql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func resourceSqlUser() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"disabled": {
Expand Down
55 changes: 47 additions & 8 deletions mmv1/third_party/terraform/tests/resource_sql_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ func TestAccSqlUser_mysql(t *testing.T) {
CheckDestroy: testAccSqlUserDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testGoogleSqlUser_mysql(instance, "password"),
Config: testGoogleSqlUser_mysql(instance, "password", false),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user1"),
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user2"),
),
},
{
// Update password
Config: testGoogleSqlUser_mysql(instance, "new_password"),
Config: testGoogleSqlUser_mysql(instance, "new_password", false),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user1"),
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user2"),
Expand All @@ -45,6 +45,45 @@ func TestAccSqlUser_mysql(t *testing.T) {
})
}

func TestAccSqlUser_mysqlDisabled(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
t.Parallel()

instance := fmt.Sprintf("i-%d", randInt(t))
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccSqlUserDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testGoogleSqlUser_mysql(instance, "password", true),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user1"),
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user2"),
resource.TestCheckResourceAttr("google_sql_user.user1", "sql_server_user_details.disabled", "true"),
),
},
{
// Update password
Config: testGoogleSqlUser_mysql(instance, "password", false),
Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user1"),
testAccCheckGoogleSqlUserExists(t, "google_sql_user.user2"),
resource.TestCheckResourceAttr("google_sql_user.user1", "sql_server_user_details.disabled", "false"),
),
},
{
ResourceName: "google_sql_user.user2",
ImportStateId: fmt.Sprintf("%s/%s/gmail.com/admin", getTestProjectFromEnv(), instance),
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"password"},
},
},
})
}

func TestAccSqlUser_iamUser(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
Expand Down Expand Up @@ -245,7 +284,7 @@ func testAccSqlUserDestroyProducer(t *testing.T) func(s *terraform.State) error
}
}

func testGoogleSqlUser_mysql(instance, password string) string {
func testGoogleSqlUser_mysql(instance, password string, disabled bool) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "instance" {
name = "%s"
Expand All @@ -262,10 +301,10 @@ resource "google_sql_user" "user1" {
instance = google_sql_database_instance.instance.name
host = "google.com"
password = "%s"
sql_server_user_details {
disabled = "false"
server_roles = [ "admin" ]
}
sql_server_user_details {
disabled = "%t"
server_roles = [ "admin" ]
}
}
resource "google_sql_user" "user2" {
Expand All @@ -274,7 +313,7 @@ resource "google_sql_user" "user2" {
host = "gmail.com"
password = "hunter2"
}
`, instance, password)
`, instance, password, disabled)
}

func testGoogleSqlUser_postgres(instance, password string) string {
Expand Down

0 comments on commit 3d02824

Please sign in to comment.