Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions mso/datasource_mso_schema_template_vrf_contract_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package mso

import (
"fmt"
"regexp"
"testing"

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

func TestAccMSOSchemaTemplateVrfContractDatasource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMSOSchemaTemplateVrfContractDestroy,
Steps: []resource.TestStep{
{
PreConfig: func() { fmt.Println("Test: Read VRF contract datasource not found error") },
Config: testAccMSOSchemaTemplateVrfContractDatasourceNotFound(),
ExpectError: regexp.MustCompile("Unable to find the VRF Contract"),
},
{
PreConfig: func() { fmt.Println("Test: Read VRF contract datasource") },
Config: testAccMSOSchemaTemplateVrfContractDatasource(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.mso_schema_template_vrf_contract.vrf_contract", "schema_id"),
resource.TestCheckResourceAttr("data.mso_schema_template_vrf_contract.vrf_contract", "template_name", msoSchemaTemplateName),
resource.TestCheckResourceAttr("data.mso_schema_template_vrf_contract.vrf_contract", "vrf_name", msoSchemaTemplateVrfName),
resource.TestCheckResourceAttr("data.mso_schema_template_vrf_contract.vrf_contract", "contract_name", msoSchemaTemplateContractName),
resource.TestCheckResourceAttr("data.mso_schema_template_vrf_contract.vrf_contract", "relationship_type", "provider"),
resource.TestCheckResourceAttrSet("data.mso_schema_template_vrf_contract.vrf_contract", "contract_schema_id"),
resource.TestCheckResourceAttr("data.mso_schema_template_vrf_contract.vrf_contract", "contract_template_name", msoSchemaTemplateName),
),
},
},
})
}

func testAccMSOSchemaTemplateVrfContractDatasourceConfig() string {
return fmt.Sprintf(`%[1]s
resource "mso_schema_template_vrf_contract" "vrf_contract" {
schema_id = mso_schema.%[2]s.id
template_name = "%[3]s"
vrf_name = mso_schema_template_vrf.%[4]s.name
contract_name = mso_schema_template_contract.%[5]s.contract_name
relationship_type = "provider"
}
resource "mso_schema_template_vrf_contract" "vrf_contract_consumer" {
schema_id = mso_schema.%[2]s.id
template_name = "%[3]s"
vrf_name = mso_schema_template_vrf.%[4]s.name
contract_name = mso_schema_template_contract.%[5]s.contract_name
relationship_type = "consumer"
}`, testAccMSOSchemaTemplateVrfContractPrerequisiteConfig(), msoSchemaName, msoSchemaTemplateName, msoSchemaTemplateVrfName, msoSchemaTemplateContractName)
}

func testAccMSOSchemaTemplateVrfContractDatasource() string {
return fmt.Sprintf(`%s
data "mso_schema_template_vrf_contract" "vrf_contract" {
schema_id = mso_schema.%[2]s.id
template_name = "%[3]s"
vrf_name = mso_schema_template_vrf.%[4]s.name
contract_name = mso_schema_template_vrf_contract.vrf_contract.contract_name
relationship_type = "provider"
}`, testAccMSOSchemaTemplateVrfContractDatasourceConfig(), msoSchemaName, msoSchemaTemplateName, msoSchemaTemplateVrfName)
}

func testAccMSOSchemaTemplateVrfContractDatasourceNotFound() string {
return fmt.Sprintf(`%s
data "mso_schema_template_vrf_contract" "vrf_contract" {
schema_id = mso_schema.%[2]s.id
template_name = "%[3]s"
vrf_name = mso_schema_template_vrf.%[4]s.name
contract_name = "non_existing_contract"
relationship_type = "provider"
}`, testAccMSOSchemaTemplateVrfContractDatasourceConfig(), msoSchemaName, msoSchemaTemplateName, msoSchemaTemplateVrfName)
}
5 changes: 5 additions & 0 deletions mso/resource_mso_schema_template_vrf_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func resourceMSOTemplateVRFContract() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
// There is a difference in behavior for this relationship_type attribute between resources
// In mso/resource_mso_schema_template_anp_epg_contract.go ForceNew is not set
// In mso/resource_mso_schema_template_external_epg_contract.go ForceNew is not set
// Updating a relationship_type would be possible if we want to introduce this change in behavior
// This requires the introduction of a new update function
"relationship_type": &schema.Schema{
Type: schema.TypeString,
Required: true,
Expand Down
Loading
Loading