Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm committed Sep 21, 2023
1 parent 3b1d2a9 commit 9dc208c
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ func TestAccIBMISVirtualEndpointGatewayDataSource_basic(t *testing.T) {
},
})
}
func TestAccIBMISVirtualEndpointGatewayDataSource_AllowDnsResolutionBinding(t *testing.T) {
resName := "data.ibm_is_virtual_endpoint_gateway.data_test"
vpcname1 := fmt.Sprintf("tfvpngw-vpc-%d", acctest.RandIntRange(10, 100))
enable_hub := false
allowbinding := true
name1 := fmt.Sprintf("tfvpngw-createname-%d", acctest.RandIntRange(10, 100))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckisVirtualEndpointGatewayDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISVirtualEndpointGatewayAllowDnsResolutionBindingDataSourceConfig(vpcname1, name1, enable_hub, allowbinding),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
resName, "name", name1),
resource.TestCheckResourceAttr(
resName, "allow_dns_resolution_binding", fmt.Sprintf("%t", allowbinding)),
),
},
},
})
}

func testAccCheckIBMISVirtualEndpointGatewayDataSourceConfig(vpcname1, subnetname1, name1 string) string {
// status filter defaults to empty
Expand All @@ -41,6 +64,13 @@ func testAccCheckIBMISVirtualEndpointGatewayDataSourceConfig(vpcname1, subnetnam
name = ibm_is_virtual_endpoint_gateway.endpoint_gateway.name
}`)
}
func testAccCheckIBMISVirtualEndpointGatewayAllowDnsResolutionBindingDataSourceConfig(vpcname1, name1 string, enable_hub, allowbinding bool) string {
// status filter defaults to empty
return testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, name1, enable_hub, allowbinding) + fmt.Sprintf(`
data "ibm_is_virtual_endpoint_gateway" "data_test" {
name = ibm_is_virtual_endpoint_gateway.endpoint_gateway.name
}`)
}

// service endpoints
func TestAccIBMISVirtualEndpointGatewayDataSource_service_endpoints(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ func TestAccIBMISVirtualEndpointGatewaysDataSource_basic(t *testing.T) {
},
})
}
func TestAccIBMISVirtualEndpointGatewaysDataSource_AllowDnsResolutionBinding(t *testing.T) {
// t.Skip()
resName := "data.ibm_is_virtual_endpoint_gateways.test1"
vpcname1 := fmt.Sprintf("tfvpngw-vpc-%d", acctest.RandIntRange(10, 100))
name1 := fmt.Sprintf("tfvpngw-createname-%d", acctest.RandIntRange(10, 100))
enable_hub := false
allowbinding := true
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISVirtualEndpointGatewaysAllowDnsResolutionBindingDataSourceConfig(vpcname1, name1, enable_hub, allowbinding),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
resName, "virtual_endpoint_gateways.0.name"),
resource.TestCheckResourceAttrSet(
resName, "virtual_endpoint_gateways.0.allow_dns_resolution_binding"),
),
},
},
})
}

func testAccCheckIBMISVirtualEndpointGatewaysDataSourceConfig(vpcname1, subnetname1, name1 string) string {
// status filter defaults to empty
Expand All @@ -41,6 +64,13 @@ func testAccCheckIBMISVirtualEndpointGatewaysDataSourceConfig(vpcname1, subnetna
depends_on = [ibm_is_virtual_endpoint_gateway.endpoint_gateway]
}`)
}
func testAccCheckIBMISVirtualEndpointGatewaysAllowDnsResolutionBindingDataSourceConfig(vpcname1, name1 string, enable_hub, allowbinding bool) string {
// status filter defaults to empty
return testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, name1, enable_hub, allowbinding) + fmt.Sprintf(`
data "ibm_is_virtual_endpoint_gateways" "test1" {
depends_on = [ibm_is_virtual_endpoint_gateway.endpoint_gateway]
}`)
}

// service endpoints

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func DataSourceIBMIsVPCDnsResolutionBinding() *schema.Resource {
Required: true,
Description: "The VPC identifier.",
},
"id": &schema.Schema{
"identifier": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The DNS resolution binding identifier.",
Expand Down Expand Up @@ -230,7 +230,7 @@ func dataSourceIBMIsVPCDnsResolutionBindingRead(context context.Context, d *sche
getVPCDnsResolutionBindingOptions := &vpcv1.GetVPCDnsResolutionBindingOptions{}

getVPCDnsResolutionBindingOptions.SetVPCID(d.Get("vpc_id").(string))
getVPCDnsResolutionBindingOptions.SetID(d.Get("id").(string))
getVPCDnsResolutionBindingOptions.SetID(d.Get("identifier").(string))

vpcdnsResolutionBinding, response, err := sess.GetVPCDnsResolutionBindingWithContext(context, getVPCDnsResolutionBindingOptions)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
)

func TestAccIBMIsVPCDnsResolutionBindingDataSourceBasic(t *testing.T) {
vpcname1 := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
enable_hub1 := true
vpcname2 := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
bindingname := fmt.Sprintf("tf-vpc-dns-binding-%d", acctest.RandIntRange(10, 100))
enable_hub2 := false
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMIsVPCDnsResolutionBindingDataSourceConfigBasic(),
Config: testAccCheckIBMIsVPCDnsResolutionBindingDataSourceConfigBasic(vpcname1, vpcname2, bindingname, enable_hub1, enable_hub2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "vpc_id"),
Expand All @@ -36,11 +42,11 @@ func TestAccIBMIsVPCDnsResolutionBindingDataSourceBasic(t *testing.T) {
})
}

func testAccCheckIBMIsVPCDnsResolutionBindingDataSourceConfigBasic() string {
return fmt.Sprintf(`
func testAccCheckIBMIsVPCDnsResolutionBindingDataSourceConfigBasic(vpcname1, vpcname2, bindingname string, enable_hub1, enable_hub2 bool) string {
return testAccCheckIBMIsVPCDnsResolutionBindingResourceConfigBasic(vpcname1, vpcname2, bindingname, enable_hub1, enable_hub2) + fmt.Sprintf(`
data "ibm_is_vpc_dns_resolution_binding" "is_vpc_dns_resolution_binding_instance" {
vpc_id = "vpc_id"
id = "id"
vpc_id = ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding.vpc_id
identifier = "id"
}
`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func dataSourceIBMIsVPCDnsResolutionBindingsRead(context context.Context, d *sch
l[isVPCDnsResolutionBindingLifecycleState] = dns.LifecycleState

l[isVPCDnsResolutionBindingName] = dns.Name
l[isVPCDnsResolutionBindingHref] = dns.Href

l[isVPCDnsResolutionBindingResourceType] = dns.ResourceType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
)

func TestAccIBMIsVPCDnsResolutionBindingsDataSourceBasic(t *testing.T) {
vpcname1 := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
enable_hub1 := true
vpcname2 := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
bindingname := fmt.Sprintf("tf-vpc-dns-binding-%d", acctest.RandIntRange(10, 100))
enable_hub2 := false
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMIsVPCDnsResolutionBindingsDataSourceConfigBasic(),
Config: testAccCheckIBMIsVPCDnsResolutionBindingsDataSourceConfigBasic(vpcname1, vpcname2, bindingname, enable_hub1, enable_hub2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "dns_resolution_bindings.0.id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "dns_resolution_bindings.0.vpc_id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "vpc_id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "dns_resolution_bindings.0.id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "dns_resolution_bindings.0.created_at"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "dns_resolution_bindings.0.endpoint_gateways.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "dns_resolution_bindings.0.href"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "dns_resolution_bindings.0.lifecycle_state"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_bindings.is_vpc_dns_resolution_bindings", "dns_resolution_bindings.0.name"),
Expand All @@ -36,11 +40,10 @@ func TestAccIBMIsVPCDnsResolutionBindingsDataSourceBasic(t *testing.T) {
})
}

func testAccCheckIBMIsVPCDnsResolutionBindingsDataSourceConfigBasic() string {
return fmt.Sprintf(`
func testAccCheckIBMIsVPCDnsResolutionBindingsDataSourceConfigBasic(vpcname1, vpcname2, bindingname string, enable_hub1, enable_hub2 bool) string {
return testAccCheckIBMIsVPCDnsResolutionBindingResourceConfigBasic(vpcname1, vpcname2, bindingname, enable_hub1, enable_hub2) + fmt.Sprintf(`
data "ibm_is_vpc_dns_resolution_bindings" "is_vpc_dns_resolution_bindings" {
vpc_id = "vpc_id"
id = "id"
vpc_id = ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding.vpc_id
}
`)
}
35 changes: 14 additions & 21 deletions ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccIBMISVirtualEndpointGateway_Basic(t *testing.T) {
func TestAccIBMISVirtualEndpointGateway_AllowDnsResolutionBinding(t *testing.T) {
var endpointGateway string
vpcname1 := fmt.Sprintf("tfvpngw-vpc-%d", acctest.RandIntRange(10, 100))
subnetname1 := fmt.Sprintf("tfvpngw-subnet-%d", acctest.RandIntRange(10, 100))
enable_hub := false
name1 := fmt.Sprintf("tfvpngw-createname-%d", acctest.RandIntRange(10, 100))
name := "ibm_is_virtual_endpoint_gateway.endpoint_gateway"
allowDnsResolutionBindingTrue := true
Expand All @@ -49,17 +49,19 @@ func TestAccIBMISVirtualEndpointGateway_AllowDnsResolutionBinding(t *testing.T)
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, subnetname1, name1, allowDnsResolutionBindingTrue),
Config: testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, name1, enable_hub, allowDnsResolutionBindingTrue),
Check: resource.ComposeTestCheckFunc(
testAccCheckisVirtualEndpointGatewayExists(name, &endpointGateway),
resource.TestCheckResourceAttr(name, "name", name1),
resource.TestCheckResourceAttr(name, "allow_dns_resolution_binding", fmt.Sprintf("%t", allowDnsResolutionBindingTrue)),
),
},
{
Config: testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, subnetname1, name1, allowDnsResolutionBindingFalse),
Config: testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, name1, enable_hub, allowDnsResolutionBindingFalse),
Check: resource.ComposeTestCheckFunc(
testAccCheckisVirtualEndpointGatewayExists(name, &endpointGateway),
resource.TestCheckResourceAttr(name, "name", name1),
resource.TestCheckResourceAttr(name, "allow_dns_resolution_binding", fmt.Sprintf("%t", allowDnsResolutionBindingFalse)),
),
},
},
Expand Down Expand Up @@ -283,32 +285,23 @@ func testAccCheckisVirtualEndpointGatewayConfigBasic(vpcname1, subnetname1, name
}`, vpcname1, subnetname1, acc.ISZoneName, acc.ISCIDR, name1)
}

func testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, subnetname1, name1 string, allowDnsResolutionBinding bool) string {
func testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, name1 string, enable_hub, allowDnsResolutionBinding bool) string {
return fmt.Sprintf(`
data "ibm_resource_group" "test_acc" {
is_default=true
}
resource "ibm_is_vpc" "testacc_vpc" {
name = "%[1]s"
resource_group = data.ibm_resource_group.test_acc.id
}
resource "ibm_is_subnet" "testacc_subnet" {
name = "%[2]s"
vpc = ibm_is_vpc.testacc_vpc.id
zone = "%[3]s"
ipv4_cidr_block = "%[4]s"
resource_group = data.ibm_resource_group.test_acc.id
name = "%s"
dns {
enable_hub = %t
}
}
resource "ibm_is_virtual_endpoint_gateway" "endpoint_gateway" {
name = "%[5]s"
name = "%s"
target {
name = "ibm-dns-server2"
resource_type = "provider_infrastructure_service"
name = "ibm-ntp-server"
resource_type = "provider_infrastructure_service"
}
vpc = ibm_is_vpc.testacc_vpc.id
resource_group = data.ibm_resource_group.test_acc.id
allow_dns_resolution_binding = %t
}`, vpcname1, subnetname1, acc.ISZoneName, acc.ISCIDR, name1, allowDnsResolutionBinding)
}`, vpcname1, enable_hub, name1, allowDnsResolutionBinding)
}

func testAccCheckisVirtualEndpointGatewayConfigFullySpecified(vpcname1, subnetname1, name1 string) string {
Expand Down
51 changes: 35 additions & 16 deletions ibm/service/vpc/resource_ibm_is_vpc_dns_resolution_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,59 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
)

func TestAccIBMIsVPCDnsResolutionBindingResourceBasic(t *testing.T) {
vpcname1 := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
enable_hub1 := true
vpcname2 := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
bindingname := fmt.Sprintf("tf-vpc-dns-binding-%d", acctest.RandIntRange(10, 100))
enable_hub2 := false
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMIsVPCDnsResolutionBindingDataSourceConfigBasic(),
Config: testAccCheckIBMIsVPCDnsResolutionBindingResourceConfigBasic(vpcname1, vpcname2, bindingname, enable_hub1, enable_hub2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "vpc_id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "created_at"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "endpoint_gateways.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "href"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "lifecycle_state"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "name"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "resource_type"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "vpc.#"),
resource.TestCheckResourceAttrSet("ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "id"),
resource.TestCheckResourceAttrSet("ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "vpc_id"),
resource.TestCheckResourceAttrSet("ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "created_at"),
resource.TestCheckResourceAttrSet("ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "href"),
resource.TestCheckResourceAttrSet("ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "lifecycle_state"),
resource.TestCheckResourceAttrSet("ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "name"),
resource.TestCheckResourceAttrSet("ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "resource_type"),
resource.TestCheckResourceAttrSet("ibm_is_vpc_dns_resolution_binding.is_vpc_dns_resolution_binding", "vpc.#"),
),
},
},
})
}

func testAccCheckIBMIsVPCDnsResolutionBindingResourceConfigBasic() string {
func testAccCheckIBMIsVPCDnsResolutionBindingResourceConfigBasic(vpcname1, vpcname2, bindingname string, enablehub1, enablehub2 bool) string {
return fmt.Sprintf(`
data "ibm_is_vpc_dns_resolution_binding" "is_vpc_dns_resolution_binding_instance" {
vpc_id = "vpc_id"
id = "id"
resource ibm_is_vpc testacc_vpc1 {
name = "%s"
dns {
enable_hub = %t
}
`)
}
resource ibm_is_vpc testacc_vpc2 {
name = "%s"
dns {
enable_hub = %t
}
}
resource ibm_is_vpc_dns_resolution_binding is_vpc_dns_resolution_binding {
name = "%s"
vpc_id= ibm_is_vpc.testacc_vpc2.id
vpc {
id = ibm_is_vpc.testacc_vpc1.id
}
}
`, vpcname1, enablehub1, vpcname2, enablehub2, bindingname)
}

0 comments on commit 9dc208c

Please sign in to comment.