diff --git a/ibm/acctest/acctest.go b/ibm/acctest/acctest.go index 03f2d507f4..3ba7a0968f 100644 --- a/ibm/acctest/acctest.go +++ b/ibm/acctest/acctest.go @@ -187,6 +187,8 @@ var Pi_capture_storage_image_path string var Pi_capture_cloud_storage_access_key string var Pi_capture_cloud_storage_secret_key string +var ISDelegegatedVPC string + // For Image var IsImageName string @@ -1042,6 +1044,11 @@ func init() { fmt.Println("[WARN] Set the environment variable IMAGE_COS_URL with a VALID COS Image SQL URL for testing ibm_is_image resources on staging/test") } + ISDelegegatedVPC = os.Getenv("IS_DELEGATED_VPC") + if ISDelegegatedVPC == "" { + ISDelegegatedVPC = "tfp-test-vpc-hub-false-del" + fmt.Println("[WARN] Set the environment variable IS_DELEGATED_VPC with a VALID created vpc name for testing ibm_is_vpc data source on staging/test") + } // Added for resource image testing Image_cos_url_encrypted = os.Getenv("IMAGE_COS_URL_ENCRYPTED") if Image_cos_url_encrypted == "" { diff --git a/ibm/service/vpc/data_source_ibm_is_vpc.go b/ibm/service/vpc/data_source_ibm_is_vpc.go index 93fac8e2a7..b10b86ea24 100644 --- a/ibm/service/vpc/data_source_ibm_is_vpc.go +++ b/ibm/service/vpc/data_source_ibm_is_vpc.go @@ -831,7 +831,10 @@ func dataSourceIBMIsVPCVpcdnsToMap(model *vpcv1.Vpcdns) (map[string]interface{}, if err != nil { return modelMap, err } - modelMap["resolver"] = []map[string]interface{}{resolverMap} + // modelMap["resolver"] = []map[string]interface{}{resolverMap} + log.Printf("[INFO] UJJK map is %v", []map[string]interface{}{resolverMap}) + log.Printf("[INFO] UJJK map is %+v", []map[string]interface{}{resolverMap}) + log.Printf("[INFO] UJJK map is %#v", []map[string]interface{}{resolverMap}) return modelMap, nil } @@ -839,9 +842,9 @@ func dataSourceIBMIsVPCVpcdnsResolverToMap(model vpcv1.VpcdnsResolverIntf) (map[ if _, ok := model.(*vpcv1.VpcdnsResolverTypeDelegated); ok { return dataSourceIBMIsVPCVpcdnsResolverTypeDelegatedToMap(model.(*vpcv1.VpcdnsResolverTypeDelegated)) } else if _, ok := model.(*vpcv1.VpcdnsResolverTypeManual); ok { - return resourceIBMIsVPCVpcdnsResolverTypeManualToMap(model.(*vpcv1.VpcdnsResolverTypeManual), "", "") + return dataSourceIBMIsVPCVpcdnsResolverTypeManualToMap(model.(*vpcv1.VpcdnsResolverTypeManual)) } else if _, ok := model.(*vpcv1.VpcdnsResolverTypeSystem); ok { - return resourceIBMIsVPCVpcdnsResolverTypeSystemToMap(model.(*vpcv1.VpcdnsResolverTypeSystem), "", "") + return dataSourceIBMIsVPCVpcdnsResolverTypeSystemToMap(model.(*vpcv1.VpcdnsResolverTypeSystem)) } else if _, ok := model.(*vpcv1.VpcdnsResolver); ok { modelMap := make(map[string]interface{}) model := model.(*vpcv1.VpcdnsResolver) @@ -856,18 +859,11 @@ func dataSourceIBMIsVPCVpcdnsResolverToMap(model vpcv1.VpcdnsResolverIntf) (map[ modelMap["servers"] = servers modelMap["type"] = model.Type if model.VPC != nil { - modelMap["vpc_id"] = *model.VPC.ID - modelMap["vpc_crn"] = *model.VPC.CRN - modelMap["vpc_name"] = *model.VPC.Name - if model.VPC.Remote != nil { - if model.VPC.Remote.Account != nil { - modelMap["vpc_remote_account_id"] = *model.VPC.Remote.Account.ID - } - if model.VPC.Remote.Region != nil { - modelMap["vpc_remote_region"] = *model.VPC.Remote.Region.Name - } + vpcMap, err := dataSourceIBMIsVPCVPCReferenceDnsResolverContextToMap(model.VPC) + if err != nil { + return modelMap, err } - + modelMap["vpc"] = []map[string]interface{}{vpcMap} } if model.ManualServers != nil { @@ -890,6 +886,30 @@ func dataSourceIBMIsVPCVpcdnsResolverToMap(model vpcv1.VpcdnsResolverIntf) (map[ } } +func dataSourceIBMIsVPCVpcdnsResolverTypeManualToMap(model *vpcv1.VpcdnsResolverTypeManual) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + servers := []map[string]interface{}{} + for _, serversItem := range model.Servers { + serversItemMap, err := resourceIBMIsVPCDnsServerToMap(&serversItem) + if err != nil { + return modelMap, err + } + servers = append(servers, serversItemMap) + } + modelMap["servers"] = servers + manualServers := []map[string]interface{}{} + for _, manualServersItem := range model.ManualServers { + manualServersItemMap, err := resourceIBMIsVPCDnsServerToMap(&manualServersItem) + if err != nil { + return modelMap, err + } + manualServers = append(manualServers, manualServersItemMap) + } + modelMap["manual_servers"] = manualServers + modelMap["type"] = model.Type + return modelMap, nil +} + func dataSourceIBMIsVPCVpcdnsResolverTypeDelegatedToMap(model *vpcv1.VpcdnsResolverTypeDelegated) (map[string]interface{}, error) { modelMap := make(map[string]interface{}) servers := []map[string]interface{}{} @@ -903,17 +923,11 @@ func dataSourceIBMIsVPCVpcdnsResolverTypeDelegatedToMap(model *vpcv1.VpcdnsResol modelMap["servers"] = servers modelMap["type"] = model.Type if model.VPC != nil { - modelMap["vpc_id"] = *model.VPC.ID - modelMap["vpc_crn"] = *model.VPC.CRN - modelMap["vpc_name"] = *model.VPC.Name - if model.VPC.Remote != nil { - if model.VPC.Remote.Account != nil { - modelMap["vpc_remote_account_id"] = *model.VPC.Remote.Account.ID - } - if model.VPC.Remote.Region != nil { - modelMap["vpc_remote_region"] = *model.VPC.Remote.Region.Name - } + vpcMap, err := dataSourceIBMIsVPCVPCReferenceDnsResolverContextToMap(model.VPC) + if err != nil { + return modelMap, err } + modelMap["vpc"] = []map[string]interface{}{vpcMap} } return modelMap, nil } @@ -926,3 +940,82 @@ func dataSourceIBMIsVPCVPCHealthReasonToMap(model *vpcv1.VPCHealthReason) (map[s } return modelMap, nil } + +func dataSourceIBMIsVPCVpcdnsResolverTypeSystemToMap(model *vpcv1.VpcdnsResolverTypeSystem) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + servers := []map[string]interface{}{} + for _, serversItem := range model.Servers { + serversItemMap, err := resourceIBMIsVPCDnsServerToMap(&serversItem) + if err != nil { + return modelMap, err + } + servers = append(servers, serversItemMap) + } + modelMap["servers"] = servers + modelMap["configuration"] = model.Configuration + modelMap["type"] = model.Type + return modelMap, nil +} + +func dataSourceIBMIsVPCVPCReferenceDnsResolverContextToMap(model *vpcv1.VPCReferenceDnsResolverContext) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["crn"] = model.CRN + if model.Deleted != nil { + deletedMap, err := dataSourceIBMIsVPCVPCReferenceDnsResolverContextDeletedToMap(model.Deleted) + if err != nil { + return modelMap, err + } + modelMap["deleted"] = []map[string]interface{}{deletedMap} + } + modelMap["href"] = model.Href + modelMap["id"] = model.ID + modelMap["name"] = model.Name + if model.Remote != nil { + remoteMap, err := dataSourceIBMIsVPCVPCRemoteToMap(model.Remote) + if err != nil { + return modelMap, err + } + modelMap["remote"] = []map[string]interface{}{remoteMap} + } + modelMap["resource_type"] = model.ResourceType + return modelMap, nil +} + +func dataSourceIBMIsVPCVPCReferenceDnsResolverContextDeletedToMap(model *vpcv1.VPCReferenceDnsResolverContextDeleted) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["more_info"] = model.MoreInfo + return modelMap, nil +} + +func dataSourceIBMIsVPCVPCRemoteToMap(model *vpcv1.VPCRemote) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Account != nil { + accountMap, err := dataSourceIBMIsVPCAccountReferenceToMap(model.Account) + if err != nil { + return modelMap, err + } + modelMap["account"] = []map[string]interface{}{accountMap} + } + if model.Region != nil { + regionMap, err := dataSourceIBMIsVPCRegionReferenceToMap(model.Region) + if err != nil { + return modelMap, err + } + modelMap["region"] = []map[string]interface{}{regionMap} + } + return modelMap, nil +} + +func dataSourceIBMIsVPCAccountReferenceToMap(model *vpcv1.AccountReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["id"] = model.ID + modelMap["resource_type"] = model.ResourceType + return modelMap, nil +} + +func dataSourceIBMIsVPCRegionReferenceToMap(model *vpcv1.RegionReference) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["href"] = model.Href + modelMap["name"] = model.Name + return modelMap, nil +} diff --git a/ibm/service/vpc/data_source_ibm_is_vpc_test.go b/ibm/service/vpc/data_source_ibm_is_vpc_test.go index 3eeee7d166..1846215df0 100644 --- a/ibm/service/vpc/data_source_ibm_is_vpc_test.go +++ b/ibm/service/vpc/data_source_ibm_is_vpc_test.go @@ -43,6 +43,44 @@ func TestAccIBMISVPCDatasource_basic(t *testing.T) { }, }) } +func TestAccIBMISVPCDatasource_dns(t *testing.T) { + var vpc string + name := acc.ISDelegegatedVPC + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMISVPCDestroy, + Steps: []resource.TestStep{ + { + Config: testDSCheckIBMISVPCDnsConfig(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMISVPCExists("ibm_is_vpc.testacc_vpc", vpc), + resource.TestCheckResourceAttr( + "data.ibm_is_vpc.ds_vpc", "name", name), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "cse_source_addresses.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_network_acl_name"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_security_group_name"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_routing_table_name"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "cse_source_addresses.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_network_acl_name"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_security_group_name"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_routing_table_name"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.enable_hub"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolution_binding_count"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.servers.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.type"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.vpc.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.vpc.0.crn"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.vpc.0.id"), + resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.vpc.0.resource_type"), + ), + }, + }, + }) +} func TestAccIBMISVPCDatasource_securityGroup(t *testing.T) { var vpc string @@ -81,6 +119,15 @@ func testDSCheckIBMISVPCConfig(name string) string { identifier = "${ibm_is_vpc.testacc_vpc.id}" }`, name) } +func testDSCheckIBMISVPCDnsConfig(name string) string { + return fmt.Sprintf(` + resource "ibm_is_vpc" "testacc_vpc" { + name = "for-test" + } + data "ibm_is_vpc" "ds_vpc" { + name = "%s" + }`, name) +} func testDSCheckIBMISVPCSgConfig(vpcname, sgname string) string { return fmt.Sprintf(`