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

	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "5.0(1k)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigL3extRsLblToInstPMinDependencyWithL3extConsLblAllowExisting,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.allow_test", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.allow_test_2", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.allow_test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.allow_test_2", "annotation", "orchestrator:terraform"),
				),
			},
		},
	})

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

	setEnvVariable(t, "ACI_ALLOW_EXISTING_ON_CREATE", "true")
	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "5.0(1k)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigL3extRsLblToInstPMinDependencyWithL3extConsLblAllowExisting,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.allow_test", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.allow_test_2", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.allow_test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.allow_test_2", "annotation", "orchestrator:terraform"),
				),
			},
		},
	})

	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t, "both", "5.0(1k)-") },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create with minimum config and verify default APIC values
			{
				Config:             testConfigL3extRsLblToInstPMinDependencyWithL3extConsLbl,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotation", "orchestrator:terraform"),
				),
			},
			// Update with all config and verify default APIC values
			{
				Config:             testConfigL3extRsLblToInstPAllDependencyWithL3extConsLbl,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotation", "annotation"),
				),
			},
			// Update with minimum config and verify config is unchanged
			{
				Config:             testConfigL3extRsLblToInstPMinDependencyWithL3extConsLbl,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
				),
			},
			// Update with empty strings config or default value
			{
				Config:             testConfigL3extRsLblToInstPResetDependencyWithL3extConsLbl,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotation", "orchestrator:terraform"),
				),
			},
			// Import testing
			{
				ResourceName:      "aci_relation_from_l3out_consumer_label_to_external_epg.test",
				ImportState:       true,
				ImportStateVerify: true,
			},
			// Update with children
			{
				Config:             testConfigL3extRsLblToInstPChildrenDependencyWithL3extConsLbl,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "target_dn", "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotation", "orchestrator:terraform"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.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_l3out_consumer_label_to_external_epg.test",
				ImportState:       true,
				ImportStateVerify: true,
			},
			// Update with children removed from config
			{
				Config:             testConfigL3extRsLblToInstPChildrenRemoveFromConfigDependencyWithL3extConsLbl,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.#", "2"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.0.key", "key_0"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.0.value", "value_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.1.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.1.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.#", "2"),
				),
			},
			// Update with children first child removed
			{
				Config:             testConfigL3extRsLblToInstPChildrenRemoveOneDependencyWithL3extConsLbl,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.0.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.0.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.#", "1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.0.key", "key_1"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.0.value", "test_value"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.#", "1"),
				),
			},
			// Update with all children removed
			{
				Config:             testConfigL3extRsLblToInstPChildrenRemoveAllDependencyWithL3extConsLbl,
				ExpectNonEmptyPlan: false,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "annotations.#", "0"),
					resource.TestCheckResourceAttr("aci_relation_from_l3out_consumer_label_to_external_epg.test", "tags.#", "0"),
				),
			},
		},
		CheckDestroy: testCheckResourceDestroy,
	})
}

const testDependencyConfigL3extRsLblToInstP = `
`

const testConfigL3extRsLblToInstPMinDependencyWithL3extConsLblAllowExisting = testDependencyConfigL3extRsLblToInstP + testConfigL3extConsLblMinDependencyWithL3extOut + `
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "allow_test" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
}
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "allow_test_2" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
  depends_on = [aci_relation_from_l3out_consumer_label_to_external_epg.allow_test]
}
`

const testConfigL3extRsLblToInstPMinDependencyWithL3extConsLbl = testDependencyConfigL3extRsLblToInstP + testConfigL3extConsLblMinDependencyWithL3extOut + `
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "test" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
}
`

const testConfigL3extRsLblToInstPAllDependencyWithL3extConsLbl = testDependencyConfigL3extRsLblToInstP + testConfigL3extConsLblMinDependencyWithL3extOut + `
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "test" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
  annotation = "annotation"
}
`

const testConfigL3extRsLblToInstPResetDependencyWithL3extConsLbl = testDependencyConfigL3extRsLblToInstP + testConfigL3extConsLblMinDependencyWithL3extOut + `
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "test" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
  annotation = "orchestrator:terraform"
}
`
const testConfigL3extRsLblToInstPChildrenDependencyWithL3extConsLbl = testDependencyConfigL3extRsLblToInstP + testConfigL3extConsLblMinDependencyWithL3extOut + `
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "test" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
  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 testConfigL3extRsLblToInstPChildrenRemoveFromConfigDependencyWithL3extConsLbl = testDependencyConfigL3extRsLblToInstP + testConfigL3extConsLblMinDependencyWithL3extOut + `
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "test" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
}
`

const testConfigL3extRsLblToInstPChildrenRemoveOneDependencyWithL3extConsLbl = testDependencyConfigL3extRsLblToInstP + testConfigL3extConsLblMinDependencyWithL3extOut + `
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "test" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
  annotations = [ 
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
  tags = [ 
	{
	  key = "key_1"
	  value = "test_value"
	},
  ]
}
`

const testConfigL3extRsLblToInstPChildrenRemoveAllDependencyWithL3extConsLbl = testDependencyConfigL3extRsLblToInstP + testConfigL3extConsLblMinDependencyWithL3extOut + `
resource "aci_relation_from_l3out_consumer_label_to_external_epg" "test" {
  parent_dn = aci_l3out_consumer_label.test.id
  target_dn = "uni/tn-test_name/out-test_l3_outside/instP-inst_profile_1"
  annotations = []
  tags = []
}
`
