// 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 TestAccResourceL3extRsInstPToProfileWithL3extInstP(t *testing.T) {

	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "apic", "1.1(1j)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigL3extRsInstPToProfileMinDependencyWithL3extInstPAllowExisting,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test_2", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test_2", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test", "direction", "import"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test_2", "direction", "import"),
				),
			},
		},
	})

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

	setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true")
	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "apic", "1.1(1j)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigL3extRsInstPToProfileMinDependencyWithL3extInstPAllowExisting,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test_2", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test_2", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test", "direction", "import"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.allow_test_2", "direction", "import"),
				),
			},
		},
	})

	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "apic", "1.1(1j)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigL3extRsInstPToProfileMinDependencyWithL3extInstP,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "direction", "import"),
				),
			},
			// Update with all config and verify default APIC values
			{
				Config:             testConfigL3extRsInstPToProfileAllDependencyWithL3extInstP,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotation", "annotation"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "direction", "export"),
				),
			},
			// Update with minimum config and verify config is unchanged
			{
				Config:             testConfigL3extRsInstPToProfileMinDependencyWithL3extInstP,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "direction", "import"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
				),
			},
			// Update with empty strings config or default value
			{
				Config:             testConfigL3extRsInstPToProfileResetDependencyWithL3extInstP,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "direction", "import"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotation", "orchestrator:terraform"),
				),
			},
			// Import testing
			{
				ResourceName:      "aci_relation_from_external_epg_to_route_control_profile.test",
				ImportState:       true,
				ImportStateVerify: true,
			},
			// Update with children
			{
				Config:             testConfigL3extRsInstPToProfileChildrenDependencyWithL3extInstP,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "direction", "import"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "route_control_profile_name", "test_tn_rtctrl_profile_name"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.1.value", "test_value"),
				),
			},
			// Refresh State before import testing to ensure that the state is up to date
			{
				RefreshState:       true,
				ExpectNonEmptyPlan: false,
			},
			// Import testing with children
			{
				ResourceName:      "aci_relation_from_external_epg_to_route_control_profile.test",
				ImportState:       true,
				ImportStateVerify: true,
			},
			// Update with children removed from config
			{
				Config:             testConfigL3extRsInstPToProfileChildrenRemoveFromConfigDependencyWithL3extInstP,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.#", "2"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.#", "2"),
				),
			},
			// Update with children first child removed
			{
				Config:             testConfigL3extRsInstPToProfileChildrenRemoveOneDependencyWithL3extInstP,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.0.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.0.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.#", "1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.0.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.0.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.#", "1"),
				),
			},
			// Update with all children removed
			{
				Config:             testConfigL3extRsInstPToProfileChildrenRemoveAllDependencyWithL3extInstP,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "annotations.#", "0"),
					resource.TestCheckResourceAttr("aci_relation_from_external_epg_to_route_control_profile.test", "tags.#", "0"),
				),
			},
		},
		CheckDestroy: testCheckResourceDestroy,
	})
}

const testConfigL3extRsInstPToProfileMinDependencyWithL3extInstPAllowExisting = testConfigL3extInstPMinDependencyWithL3extOut + `
resource "aci_relation_from_external_epg_to_route_control_profile" "allow_test" {
  parent_dn = aci_external_epg.test.id
  direction = "import"
  route_control_profile_name = "test_tn_rtctrl_profile_name"
}
resource "aci_relation_from_external_epg_to_route_control_profile" "allow_test_2" {
  parent_dn = aci_external_epg.test.id
  direction = "import"
  route_control_profile_name = "test_tn_rtctrl_profile_name"
  depends_on = [aci_relation_from_external_epg_to_route_control_profile.allow_test]
}
`

const testConfigL3extRsInstPToProfileMinDependencyWithL3extInstP = testConfigL3extInstPMinDependencyWithL3extOut + `
resource "aci_relation_from_external_epg_to_route_control_profile" "test" {
  parent_dn = aci_external_epg.test.id
  direction = "import"
  route_control_profile_name = "test_tn_rtctrl_profile_name"
}
`

const testConfigL3extRsInstPToProfileAllDependencyWithL3extInstP = testConfigL3extInstPMinDependencyWithL3extOut + `
resource "aci_relation_from_external_epg_to_route_control_profile" "test" {
  parent_dn = aci_external_epg.test.id
  route_control_profile_name = "test_tn_rtctrl_profile_name"
  annotation = "annotation"
  direction = "export"
}
`

const testConfigL3extRsInstPToProfileResetDependencyWithL3extInstP = testConfigL3extInstPMinDependencyWithL3extOut + `
resource "aci_relation_from_external_epg_to_route_control_profile" "test" {
  parent_dn = aci_external_epg.test.id
  route_control_profile_name = "test_tn_rtctrl_profile_name"
  annotation = "orchestrator:terraform"
  direction = "import"
}
`
const testConfigL3extRsInstPToProfileChildrenDependencyWithL3extInstP = testConfigL3extInstPMinDependencyWithL3extOut + `
resource "aci_relation_from_external_epg_to_route_control_profile" "test" {
  parent_dn = aci_external_epg.test.id
  direction = "import"
  route_control_profile_name = "test_tn_rtctrl_profile_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 testConfigL3extRsInstPToProfileChildrenRemoveFromConfigDependencyWithL3extInstP = testConfigL3extInstPMinDependencyWithL3extOut + `
resource "aci_relation_from_external_epg_to_route_control_profile" "test" {
  parent_dn = aci_external_epg.test.id
  direction = "import"
  route_control_profile_name = "test_tn_rtctrl_profile_name"
}
`

const testConfigL3extRsInstPToProfileChildrenRemoveOneDependencyWithL3extInstP = testConfigL3extInstPMinDependencyWithL3extOut + `
resource "aci_relation_from_external_epg_to_route_control_profile" "test" {
  parent_dn = aci_external_epg.test.id
  direction = "import"
  route_control_profile_name = "test_tn_rtctrl_profile_name"
  annotations = [ 
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
  tags = [ 
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
}
`

const testConfigL3extRsInstPToProfileChildrenRemoveAllDependencyWithL3extInstP = testConfigL3extInstPMinDependencyWithL3extOut + `
resource "aci_relation_from_external_epg_to_route_control_profile" "test" {
  parent_dn = aci_external_epg.test.id
  direction = "import"
  route_control_profile_name = "test_tn_rtctrl_profile_name"
  annotations = []
  tags = []
}
`
