Skip to content

Commit

Permalink
flatten deregister info
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishekism9450 committed Dec 19, 2022
1 parent a3d8599 commit d11a90b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 8 deletions.
54 changes: 46 additions & 8 deletions nutanix/data_source_nutanix_ndb_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func flattenDBInstanceMetadata(pr *Era.DBInstanceMetadata) []map[string]interfac
pmeta := make(map[string]interface{})
pmeta["secure_info"] = pr.Secureinfo
pmeta["info"] = pr.Info
pmeta["deregister_info"] = pr.Deregisterinfo
pmeta["deregister_info"] = flattenDeRegiserInfo(pr.Deregisterinfo)
pmeta["tm_activate_operation_id"] = pr.Tmactivateoperationid
pmeta["created_dbservers"] = pr.Createddbservers
pmeta["registered_dbservers"] = pr.Registereddbservers
Expand Down Expand Up @@ -845,7 +845,7 @@ func flattenTimeMachineMetadata(pr *Era.TimeMachineMetadata) []map[string]interf

tm["secure_info"] = pr.SecureInfo
tm["info"] = pr.Info
tm["deregister_info"] = pr.DeregisterInfo
tm["deregister_info"] = flattenDeRegiserInfo(pr.DeregisterInfo)
tm["capability_reset_time"] = pr.CapabilityResetTime
tm["auto_heal"] = pr.AutoHeal
tm["auto_heal_snapshot_count"] = pr.AutoHealSnapshotCount
Expand Down Expand Up @@ -880,6 +880,20 @@ func flattenTimeMachineMetadata(pr *Era.TimeMachineMetadata) []map[string]interf
return nil
}

func flattenDeRegiserInfo(pr *Era.DeregisterInfo) []map[string]interface{} {
if pr != nil {
Deregis := make([]map[string]interface{}, 0)
regis := map[string]interface{}{}

regis["message"] = pr.Message
regis["operations"] = utils.StringValueSlice(pr.Operations)

Deregis = append(Deregis, regis)
return Deregis
}
return nil
}

func dataSourceEraDatabaseProperties() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -1569,10 +1583,22 @@ func dataSourceEraTimeMachine() *schema.Schema {
},
},
"deregister_info": {
Type: schema.TypeMap,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"message": {
Type: schema.TypeString,
Computed: true,
},
"operations": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"capability_reset_time": {
Expand Down Expand Up @@ -2016,10 +2042,22 @@ func dataSourceEraDBInstanceMetadata() *schema.Schema {
},
},
"deregister_info": {
Type: schema.TypeMap,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"message": {
Type: schema.TypeString,
Computed: true,
},
"operations": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"tm_activate_operation_id": {
Expand Down
27 changes: 27 additions & 0 deletions nutanix/data_source_nutanix_ndb_databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,35 @@ func TestAccEraDatabasesDataSource_basic(t *testing.T) {
})
}

func TestAccEraDatabasesDataSource_ByFilters(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccEraPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccEraDatabasesDataSourceConfigByFilters(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.nutanix_ndb_databases.test", "database_instances.0.metadata.#"),
resource.TestCheckResourceAttrSet("data.nutanix_ndb_databases.test", "database_instances.0.time_zone"),
resource.TestCheckResourceAttrSet("data.nutanix_ndb_databases.test", "database_instances.#"),
resource.TestCheckResourceAttrSet("data.nutanix_ndb_databases.test", "database_instances.0.id"),
resource.TestCheckResourceAttrSet("data.nutanix_ndb_databases.test", "database_instances.0.linked_databases.#"),
),
},
},
})
}

func testAccEraDatabasesDataSourceConfig() string {
return `
data "nutanix_ndb_databases" "test" {}
`
}

func testAccEraDatabasesDataSourceConfigByFilters() string {
return `
data "nutanix_ndb_databases" "test" {
database_type = "postgres_database"
}
`
}

0 comments on commit d11a90b

Please sign in to comment.