// Code generated by "gen/generator.go"; DO NOT EDIT.
// In order to regenerate this file execute `go generate` from the repository root.
// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).

package provider

import (
	"regexp"
	"testing"

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

func TestAccResourceVzOOBBrCP(t *testing.T) {

	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "1.0(1e)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config: testConfigVzOOBBrCPMinAllowExisting + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "target_dscp", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "target_dscp", "unspecified"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "intent", "install"),
						resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "intent", "install")),
				),
			},
		},
	})

	setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "false")
	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "1.0(1e)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:      testConfigVzOOBBrCPMinAllowExisting,
				ExpectError: regexp.MustCompile("Object Already Exists"),
			},
		},
	})

	setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true")
	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "1.0(1e)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config: testConfigVzOOBBrCPMinAllowExisting + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "target_dscp", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "target_dscp", "unspecified"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test", "intent", "install"),
						resource.TestCheckResourceAttr("aci_out_of_band_contract.allow_test_2", "intent", "install")),
				),
			},
		},
	})

	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "1.0(1e)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config: testConfigVzOOBBrCPMin + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")),
				),
			},
			// Update with all config and verify default APIC values
			{
				Config: testConfigVzOOBBrCPAll + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "annotation"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", "description_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", "name_alias_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", "owner_key_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", "owner_tag_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "level1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "application-profile"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "AF11"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "estimate_add")),
				),
			},
			// Update with minimum config and verify config is unchanged
			{
				Config: testConfigVzOOBBrCPMin + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", "description_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", "name_alias_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", "owner_key_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", "owner_tag_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "level1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "application-profile"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "AF11"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "estimate_add")),
				),
			},
			// Update with empty strings config or default value
			{
				Config: testConfigVzOOBBrCPReset + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")),
				),
			},
			// Import testing
			{
				ResourceName:      "aci_out_of_band_contract.test",
				ImportState:       true,
				ImportStateVerify: true,
			},
			// Update with children
			{
				Config: testConfigVzOOBBrCPChildren + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.#", "2"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.#", "2"),
				),
			},
			// Update with children removed from config
			{
				Config: testConfigVzOOBBrCPChildrenRemoveFromConfig + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.#", "2"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.#", "2"),
				),
			},
			// Update with children first child removed
			{
				Config: testConfigVzOOBBrCPChildrenRemoveOne + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.key", "key_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.0.value", "test_value"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.#", "1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.0.key", "key_1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.0.value", "test_value"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.#", "1"),
				),
			},
			// Update with all children removed
			{
				Config: testConfigVzOOBBrCPChildrenRemoveAll + testConfigDataSourceSystem,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "description", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name_alias", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_key", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "owner_tag", ""),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "unspecified"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "scope", "context"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "unspecified"),
					composeAggregateTestCheckFuncWithVersion(t, "4.2(1i)-", "inside",
						resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "intent", "install")),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "annotations.#", "0"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "tags.#", "0"),
				),
			},
			// Update with minimum config and custom type semantic equivalent values
			{
				Config: testConfigVzOOBBrCPCustomType,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "name", "test_name"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "priority", "1"),
					resource.TestCheckResourceAttr("aci_out_of_band_contract.test", "target_dscp", "0"),
				),
			},
		},
		CheckDestroy: testCheckResourceDestroy,
	})
}

const testConfigVzOOBBrCPMinAllowExisting = `
resource "aci_out_of_band_contract" "allow_test" {
  name = "test_name"
}
resource "aci_out_of_band_contract" "allow_test_2" {
  name = "test_name"
  depends_on = [aci_out_of_band_contract.allow_test]
}
`

const testConfigVzOOBBrCPMin = `
resource "aci_out_of_band_contract" "test" {
  name = "test_name"
}
`

const testConfigVzOOBBrCPAll = `
resource "aci_out_of_band_contract" "test" {
  name = "test_name"
  annotation = "annotation"
  description = "description_1"
  name_alias = "name_alias_1"
  owner_key = "owner_key_1"
  owner_tag = "owner_tag_1"
  priority = "level1"
  scope = "application-profile"
  target_dscp = "AF11"
  intent = provider::aci::compare_versions(data.aci_system.version.version,"inside","4.2(1i)-") ? "estimate_add" : null
}
`

const testConfigVzOOBBrCPReset = `
resource "aci_out_of_band_contract" "test" {
  name = "test_name"
  annotation = "orchestrator:terraform"
  description = ""
  name_alias = ""
  owner_key = ""
  owner_tag = ""
  priority = "unspecified"
  scope = "context"
  target_dscp = "unspecified"
  intent = provider::aci::compare_versions(data.aci_system.version.version,"inside","4.2(1i)-") ? "install" : null
}
`
const testConfigVzOOBBrCPChildren = `
resource "aci_out_of_band_contract" "test" {
  name = "test_name"
  annotations = [
	{
	  key = "key_0"
	  value = "value_1"
	},
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
  tags = [
	{
	  key = "key_0"
	  value = "value_1"
	},
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
}
`

const testConfigVzOOBBrCPChildrenRemoveFromConfig = `
resource "aci_out_of_band_contract" "test" {
  name = "test_name"
}
`

const testConfigVzOOBBrCPChildrenRemoveOne = `
resource "aci_out_of_band_contract" "test" {
  name = "test_name"
  annotations = [ 
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
  tags = [ 
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
}
`

const testConfigVzOOBBrCPChildrenRemoveAll = `
resource "aci_out_of_band_contract" "test" {
  name = "test_name"
  annotations = []
  tags = []
}
`

const testConfigVzOOBBrCPCustomType = `
resource "aci_out_of_band_contract" "test" {
  name = "test_name"
  priority = "1"
  target_dscp = "0"
}
`
