fix: remove identity from postgres-flex
[skip ci]
This commit is contained in:
parent
c1f463935b
commit
ba579760d5
20 changed files with 570 additions and 581 deletions
|
|
@ -37,7 +37,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
pfx = "stackitprivatepreview_postgresflexalpha"
|
||||
pfx = "stackitprivatepreview_postgresflexalpha"
|
||||
dataPfx = "data.stackitprivatepreview_postgresflexalpha"
|
||||
|
||||
singleFlavorID = "2.4"
|
||||
replicasFlavorID = "2.4-replica"
|
||||
|
|
@ -100,6 +101,7 @@ type resData struct {
|
|||
Version string
|
||||
Users []User
|
||||
Databases []Database
|
||||
DataSourceTest bool
|
||||
}
|
||||
|
||||
type User struct {
|
||||
|
|
@ -137,6 +139,7 @@ func getExample() resData {
|
|||
|
||||
func TestAccInstance(t *testing.T) {
|
||||
exData := getExample()
|
||||
exData.Version = "16"
|
||||
|
||||
updNameData := exData
|
||||
updNameData.Name = "name-updated"
|
||||
|
|
@ -151,6 +154,9 @@ func TestAccInstance(t *testing.T) {
|
|||
updNetACL := updBackupSched
|
||||
updNetACL.ACLStrings = append(updNetACL.ACLStrings, "192.168.0.0/24")
|
||||
|
||||
updVersion := updNetACL
|
||||
updVersion.Version = "17"
|
||||
|
||||
testItemID := testutils.ResStr(pfx, "instance", exData.TfName)
|
||||
compareValuesSame := statecheck.CompareValue(compare.ValuesSame())
|
||||
resource.ParallelTest(
|
||||
|
|
@ -299,19 +305,31 @@ func TestAccInstance(t *testing.T) {
|
|||
resource.TestCheckResourceAttr(testItemID, "network.acl.#", "2"),
|
||||
),
|
||||
},
|
||||
// Update version
|
||||
{
|
||||
Config: testutils.StringFromTemplateMust(
|
||||
"testdata/instance_template.gompl",
|
||||
updVersion,
|
||||
),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
testItemID,
|
||||
"version",
|
||||
updVersion.Version,
|
||||
),
|
||||
),
|
||||
},
|
||||
// Import test
|
||||
/*
|
||||
{
|
||||
ImportState: true,
|
||||
ImportStateKind: resource.ImportBlockWithResourceIdentity,
|
||||
ResourceName: testItemID,
|
||||
},
|
||||
{
|
||||
ImportState: true,
|
||||
ImportStateKind: resource.ImportCommandWithID,
|
||||
ResourceName: testItemID,
|
||||
},
|
||||
*/
|
||||
// test instance imports
|
||||
{
|
||||
ResourceName: testItemID,
|
||||
// ImportStateIdPrefix: "",
|
||||
// ImportStateVerifyIdentifierAttribute: "id",
|
||||
ImportStateIdFunc: getInstanceTestID(exData.TfName),
|
||||
ImportStateKind: resource.ImportCommandWithID,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
|
@ -410,6 +428,7 @@ func TestAccInstanceWithDatabases(t *testing.T) {
|
|||
Owner: userName,
|
||||
},
|
||||
}
|
||||
data.DataSourceTest = true
|
||||
|
||||
testItemID := testutils.ResStr(pfx, "instance", data.TfName)
|
||||
resource.ParallelTest(
|
||||
|
|
@ -432,11 +451,145 @@ func TestAccInstanceWithDatabases(t *testing.T) {
|
|||
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "user", userName), "name", userName),
|
||||
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "user", userName), "id"),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testItemID, "project_id",
|
||||
testutils.ResStr(pfx, "user", userName), "project_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testItemID, "instance_id",
|
||||
testutils.ResStr(pfx, "user", userName), "instance_id",
|
||||
),
|
||||
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "database", dbName), "name", dbName),
|
||||
resource.TestCheckResourceAttr(testutils.ResStr(pfx, "database", dbName), "owner", userName),
|
||||
resource.TestCheckResourceAttrSet(testutils.ResStr(pfx, "database", dbName), "id"),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testItemID, "project_id",
|
||||
testutils.ResStr(pfx, "database", dbName), "project_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testItemID, "instance_id",
|
||||
testutils.ResStr(pfx, "database", dbName), "instance_id",
|
||||
),
|
||||
),
|
||||
},
|
||||
// data source
|
||||
{
|
||||
Config: testutils.StringFromTemplateMust(
|
||||
"testdata/instance_template.gompl",
|
||||
data,
|
||||
),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Instance data
|
||||
resource.TestCheckResourceAttr(
|
||||
testutils.ResStr(dataPfx, "instance", data.TfName),
|
||||
"project_id",
|
||||
data.ProjectID,
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
testutils.ResStr(dataPfx, "instance", data.TfName),
|
||||
"name",
|
||||
data.Name,
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testutils.ResStr(dataPfx, "instance", data.TfName), "project_id",
|
||||
testutils.ResStr(pfx, "instance", data.TfName), "project_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testutils.ResStr(dataPfx, "database", dbName), "instance_id",
|
||||
testutils.ResStr(pfx, "instance", data.TfName), "instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testutils.ResStr(dataPfx, "user", userName), "instance_id",
|
||||
testutils.ResStr(pfx, "instance", data.TfName), "instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testutils.ResStr(dataPfx, "user", userName), "instance_id",
|
||||
testutils.ResStr(pfx, "user", userName), "instance_id",
|
||||
),
|
||||
|
||||
// User data
|
||||
resource.TestCheckResourceAttr(
|
||||
testutils.ResStr(dataPfx, "user", userName),
|
||||
"project_id",
|
||||
data.ProjectID,
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
testutils.ResStr(dataPfx, "user", userName),
|
||||
"user_id",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
testutils.ResStr(dataPfx, "user", userName),
|
||||
"name",
|
||||
data.Users[0].Name,
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
testutils.ResStr(dataPfx, "user", userName),
|
||||
"roles.#",
|
||||
"1",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
testutils.ResStr(dataPfx, "user", userName),
|
||||
"roles.0",
|
||||
data.Users[0].Roles[0],
|
||||
),
|
||||
|
||||
// Database data
|
||||
resource.TestCheckResourceAttr(
|
||||
testutils.ResStr(dataPfx, "database", dbName),
|
||||
"project_id",
|
||||
data.ProjectID,
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
testutils.ResStr(dataPfx, "database", dbName),
|
||||
"name",
|
||||
dbName,
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testutils.ResStr(dataPfx, "database", dbName),
|
||||
"instance_id",
|
||||
testutils.ResStr(pfx, "database", dbName),
|
||||
"instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
testutils.ResStr(dataPfx, "database", dbName),
|
||||
"owner",
|
||||
testutils.ResStr(dataPfx, "user", userName),
|
||||
"name",
|
||||
),
|
||||
),
|
||||
},
|
||||
// test instance imports
|
||||
{
|
||||
ResourceName: testItemID,
|
||||
// ImportStateIdPrefix: "",
|
||||
ImportStateVerifyIdentifierAttribute: "id",
|
||||
ImportStateIdFunc: getInstanceTestID(data.TfName),
|
||||
ImportStateKind: resource.ImportCommandWithID,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
// test database imports
|
||||
{
|
||||
ResourceName: testutils.ResStr(pfx, "database", dbName),
|
||||
// ImportStateIdPrefix: "",
|
||||
// ImportStateVerifyIdentifierAttribute: "id",
|
||||
ImportStateIdFunc: getDatabaseTestID(dbName),
|
||||
ImportStateKind: resource.ImportCommandWithID,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
// test user imports
|
||||
{
|
||||
ResourceName: testutils.ResStr(pfx, "user", userName),
|
||||
// ImportStateIdPrefix: "",
|
||||
// ImportStateVerifyIdentifierAttribute: "id",
|
||||
ImportStateIdFunc: getUserTestID(userName),
|
||||
ImportStateKind: resource.ImportCommandWithID,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
ImportStateVerifyIgnore: []string{"password"},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
|
@ -614,10 +767,6 @@ func defaultNoEncInstanceTestChecks(testItemID string, data resData) resource.Te
|
|||
return resource.ComposeAggregateTestCheckFunc(
|
||||
defaultInstanceTestChecks(testItemID, data),
|
||||
|
||||
// on unencrypted instances we expect this to be empty
|
||||
resource.TestCheckResourceAttr(testItemID, "network.instance_address", ""),
|
||||
resource.TestCheckResourceAttr(testItemID, "network.router_address", ""),
|
||||
|
||||
// check absent attr
|
||||
resource.TestCheckNoResourceAttr(testItemID, "encryption"),
|
||||
resource.TestCheckNoResourceAttr(testItemID, "encryption.kek_key_id"),
|
||||
|
|
@ -631,10 +780,6 @@ func defaultEncInstanceTestChecks(testItemID string, data resData) resource.Test
|
|||
return resource.ComposeAggregateTestCheckFunc(
|
||||
defaultInstanceTestChecks(testItemID, data),
|
||||
|
||||
// on unencrypted instances we expect this to be empty
|
||||
resource.TestCheckResourceAttrSet(testItemID, "network.instance_address"),
|
||||
resource.TestCheckResourceAttrSet(testItemID, "network.router_address"),
|
||||
|
||||
// check absent attr
|
||||
resource.TestCheckResourceAttr(testItemID, "encryption.%", "4"),
|
||||
resource.TestCheckResourceAttrSet(testItemID, "encryption.kek_key_id"),
|
||||
|
|
@ -649,6 +794,24 @@ func defaultEncInstanceTestChecks(testItemID string, data resData) resource.Test
|
|||
}
|
||||
|
||||
func defaultInstanceTestChecks(testItemID string, data resData) resource.TestCheckFunc {
|
||||
// if AccessScope == SNA these are set
|
||||
if data.AccessScope == "SNA" {
|
||||
return resource.ComposeAggregateTestCheckFunc(
|
||||
basicInstanceTestChecks(testItemID, data),
|
||||
resource.TestCheckResourceAttrSet(testItemID, "network.instance_address"),
|
||||
resource.TestCheckResourceAttrSet(testItemID, "network.router_address"),
|
||||
)
|
||||
}
|
||||
|
||||
// if AccessScope == PUBLIC these are empty - but they are set
|
||||
return resource.ComposeAggregateTestCheckFunc(
|
||||
basicInstanceTestChecks(testItemID, data),
|
||||
resource.TestCheckResourceAttr(testItemID, "network.instance_address", ""),
|
||||
resource.TestCheckResourceAttr(testItemID, "network.router_address", ""),
|
||||
)
|
||||
}
|
||||
|
||||
func basicInstanceTestChecks(testItemID string, data resData) resource.TestCheckFunc {
|
||||
return resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet(testItemID, "backup_schedule"),
|
||||
resource.TestCheckResourceAttr(testItemID, "backup_schedule", data.BackupSchedule),
|
||||
|
|
@ -704,3 +867,77 @@ func defaultInstanceTestChecks(testItemID string, data resData) resource.TestChe
|
|||
resource.TestCheckResourceAttr(testItemID, "version", data.Version),
|
||||
)
|
||||
}
|
||||
|
||||
func getInstanceTestID(name string) func(s *terraform.State) (string, error) {
|
||||
return func(s *terraform.State) (string, error) {
|
||||
r, ok := s.RootModule().Resources[testutils.ResStr(pfx, "instance", name)]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_instance.%s", name)
|
||||
}
|
||||
projectID, ok := r.Primary.Attributes["project_id"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute project_id")
|
||||
}
|
||||
region, ok := r.Primary.Attributes["region"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute region")
|
||||
}
|
||||
instanceID, ok := r.Primary.Attributes["instance_id"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute instance_id")
|
||||
}
|
||||
return fmt.Sprintf("%s,%s,%s", projectID, region, instanceID), nil
|
||||
}
|
||||
}
|
||||
|
||||
func getDatabaseTestID(name string) func(s *terraform.State) (string, error) {
|
||||
return func(s *terraform.State) (string, error) {
|
||||
r, ok := s.RootModule().Resources[testutils.ResStr(pfx, "database", name)]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_instance.%s", name)
|
||||
}
|
||||
projectID, ok := r.Primary.Attributes["project_id"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute project_id")
|
||||
}
|
||||
region, ok := r.Primary.Attributes["region"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute region")
|
||||
}
|
||||
instanceID, ok := r.Primary.Attributes["instance_id"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute instance_id")
|
||||
}
|
||||
databaseID, ok := r.Primary.Attributes["database_id"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute database_id")
|
||||
}
|
||||
return fmt.Sprintf("%s,%s,%s,%s", projectID, region, instanceID, databaseID), nil
|
||||
}
|
||||
}
|
||||
|
||||
func getUserTestID(name string) func(s *terraform.State) (string, error) {
|
||||
return func(s *terraform.State) (string, error) {
|
||||
r, ok := s.RootModule().Resources[testutils.ResStr(pfx, "user", name)]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_instance.%s", name)
|
||||
}
|
||||
projectID, ok := r.Primary.Attributes["project_id"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute project_id")
|
||||
}
|
||||
region, ok := r.Primary.Attributes["region"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute region")
|
||||
}
|
||||
instanceID, ok := r.Primary.Attributes["instance_id"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute instance_id")
|
||||
}
|
||||
userID, ok := r.Primary.Attributes["user_id"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute user_id")
|
||||
}
|
||||
return fmt.Sprintf("%s,%s,%s,%s", projectID, region, instanceID, userID), nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue