Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Filter Entry #124

Merged
merged 2 commits into from
Jan 21, 2022
Merged
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
5 changes: 4 additions & 1 deletion aci/data_source_aci_vzentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ func dataSourceAciFilterEntry() *schema.Resource {
},

"tcp_rules": &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}),
}
Expand Down
16 changes: 16 additions & 0 deletions aci/resource_aci_vzentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ func resourceAciFilterEntryCreate(ctx context.Context, d *schema.ResourceData, m
for _, val := range TcpRules.([]interface{}) {
tcpRulesList = append(tcpRulesList, val.(string))
}
err := checkDuplicate(tcpRulesList)
if err != nil {
return diag.FromErr(err)
}
err = checkWhetherListContainOnlyParameter(tcpRulesList, "unspecified")
if err != nil {
return diag.FromErr(err)
}
TcpRules := strings.Join(tcpRulesList, ",")
vzEntryAttr.TcpRules = TcpRules
}
Expand Down Expand Up @@ -524,6 +532,14 @@ func resourceAciFilterEntryUpdate(ctx context.Context, d *schema.ResourceData, m
for _, val := range TcpRules.([]interface{}) {
tcpRulesList = append(tcpRulesList, val.(string))
}
err := checkDuplicate(tcpRulesList)
if err != nil {
return diag.FromErr(err)
}
err = checkWhetherListContainOnlyParameter(tcpRulesList, "unspecified")
if err != nil {
return diag.FromErr(err)
}
TcpRules := strings.Join(tcpRulesList, ",")
vzEntryAttr.TcpRules = TcpRules
}
Expand Down
2 changes: 1 addition & 1 deletion aci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func checkWhetherListContainOnlyParameter(arr []string, val string) error {
}
}
if vis && len(arr) > 1 {
return fmt.Errorf("%s should't be used along with other values", val)
return fmt.Errorf("%s should not be used along with other values", val)
}
return nil
}
9 changes: 4 additions & 5 deletions testacc/data_source_aci_aaasamlenccert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestAccAciKeypairforSAMLEncryptionDataSource_Basic(t *testing.T) {
randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz")
randomValue := acctest.RandString(10)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func(){ testAccPreCheck(t) },
ProviderFactories: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: CreateAccKeypairforSAMLEncryptionConfigDataSource(),
Expand All @@ -37,7 +37,6 @@ func TestAccAciKeypairforSAMLEncryptionDataSource_Basic(t *testing.T) {
})
}


func CreateAccKeypairforSAMLEncryptionConfigDataSource() string {
fmt.Println("=== STEP testing saml_certificate Data Source with required arguments only")
resource := fmt.Sprintf(`
Expand All @@ -52,6 +51,6 @@ func CreateAccKeypairforSAMLEncryptionDataSourceUpdate(key, value string) string
data "aci_saml_certificate" "test" {
%s = "%s"
}
`, key,value)
`, key, value)
return resource
}
}
2 changes: 1 addition & 1 deletion testacc/data_source_aci_fabricnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ func CreateAccTopologyFabricNodeDataSourceUpdate(podId, nodeId, key, value strin
}
`, podId, nodeId, key, value)
return resource
}
}
221 changes: 221 additions & 0 deletions testacc/data_source_aci_vzentry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
package testacc

import (
"fmt"
"regexp"
"testing"

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

func TestAccAciFilterEntryDataSource_Basic(t *testing.T) {
resourceName := "aci_filter_entry.test"
dataSourceName := "data.aci_filter_entry.test"
rName := makeTestVariable(acctest.RandString(5))
randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz")
randomValue := acctest.RandString(10)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckAciFilterEntryDestroy,
Steps: []resource.TestStep{
{
Config: CreateAccFilterEntryDSWithoutFilter(rName),
ExpectError: regexp.MustCompile(`Missing required argument`),
},
{
Config: CreateAccFilterEntryDSWithoutName(rName),
ExpectError: regexp.MustCompile(`Missing required argument`),
},
{
Config: CreateAccFilterEntryConfigDataSource(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"),
resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"),
resource.TestCheckResourceAttrPair(dataSourceName, "apply_to_frag", resourceName, "apply_to_frag"),
resource.TestCheckResourceAttrPair(dataSourceName, "arp_opc", resourceName, "arp_opc"),
// resource.TestCheckResourceAttrPair(dataSourceName, "d_from_port", resourceName, "d_from_port"),
// resource.TestCheckResourceAttrPair(dataSourceName, "d_to_port", resourceName, "d_to_port"),
resource.TestCheckResourceAttrPair(dataSourceName, "ether_t", resourceName, "ether_t"),
resource.TestCheckResourceAttrPair(dataSourceName, "icmpv4_t", resourceName, "icmpv4_t"),
resource.TestCheckResourceAttrPair(dataSourceName, "icmpv6_t", resourceName, "icmpv6_t"),
resource.TestCheckResourceAttrPair(dataSourceName, "match_dscp", resourceName, "match_dscp"),
resource.TestCheckResourceAttrPair(dataSourceName, "prot", resourceName, "prot"),
// resource.TestCheckResourceAttrPair(dataSourceName, "s_from_port", resourceName, "s_from_port"),
// resource.TestCheckResourceAttrPair(dataSourceName, "s_to_port", resourceName, "s_to_port"),
resource.TestCheckResourceAttrPair(dataSourceName, "stateful", resourceName, "stateful"),
resource.TestCheckResourceAttrPair(dataSourceName, "tcp_rules", resourceName, "tcp_rules"),
resource.TestCheckResourceAttrPair(dataSourceName, "filter_dn", resourceName, "filter_dn"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
),
},
{
Config: CreateAccFilterEntryUpdatedConfigDataSourceRandomAttr(rName, randomParameter, randomValue),
ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`),
},
{
Config: CreateAccFilterEntryUpdatedConfigDataSource(rName, "description", randomValue),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
),
},
{
Config: CreateAccFilterEntryDSWithInvalidName(rName),
ExpectError: regexp.MustCompile(`(.)+ Object may not exists`),
},
},
})
}

func CreateAccFilterEntryUpdatedConfigDataSourceRandomAttr(rName, attribute, value string) string {
fmt.Println("=== STEP Basic: Testing filter entry data source with updated resource")
resource := fmt.Sprintf(`
resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_filter" "test"{
tenant_dn = aci_tenant.test.id
name = "%s"
}

resource "aci_filter_entry" "test"{
filter_dn = aci_filter.test.id
name = "%s"
}

data "aci_filter_entry" "test" {
filter_dn = aci_filter.test.id
name = aci_filter_entry.test.name
%s = "%s"
}
`, rName, rName, rName, attribute, value)
return resource
}

func CreateAccFilterEntryUpdatedConfigDataSource(rName, attribute, value string) string {
fmt.Println("=== STEP Basic: Testing filter entry data source with updated resource")
resource := fmt.Sprintf(`
resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_filter" "test"{
tenant_dn = aci_tenant.test.id
name = "%s"
}

resource "aci_filter_entry" "test"{
filter_dn = aci_filter.test.id
name = "%s"
%s = "%s"
}

data "aci_filter_entry" "test" {
filter_dn = aci_filter.test.id
name = aci_filter_entry.test.name
}
`, rName, rName, rName, attribute, value)
return resource
}

func CreateAccFilterEntryConfigDataSource(rName string) string {
fmt.Println("=== STEP Basic: Testing filter entry data source")
resource := fmt.Sprintf(`
resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_filter" "test"{
tenant_dn = aci_tenant.test.id
name = "%s"
}

resource "aci_filter_entry" "test"{
filter_dn = aci_filter.test.id
name = "%s"
description = "test_description"
}

data "aci_filter_entry" "test" {
filter_dn = aci_filter.test.id
name = aci_filter_entry.test.name
}
`, rName, rName, rName)
return resource
}

func CreateAccFilterEntryDSWithInvalidName(rName string) string {
fmt.Println("=== STEP Basic: testing filter entry reading with invalid name")
resource := fmt.Sprintf(`
resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_filter" "test"{
tenant_dn = aci_tenant.test.id
name = "%s"
}

resource "aci_filter_entry" "test"{
filter_dn = aci_filter.test.id
name = "%s"
}

data "aci_filter_entry" "test" {
filter_dn = aci_filter.test.id
name = "${aci_filter_entry.test.name}abc"
}
`, rName, rName, rName)
return resource
}

func CreateAccFilterEntryDSWithoutFilter(rName string) string {
fmt.Println("=== STEP Basic: testing filter entry reading without giving filter_dn")
resource := fmt.Sprintf(`
resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_filter" "test"{
tenant_dn = aci_tenant.test.id
name = "%s"
}

resource "aci_filter_entry" "test"{
filter_dn = aci_filter.test.id
name = "%s"
}

data "aci_filter_entry" "test" {
name = "%s"
}
`, rName, rName, rName, rName)
return resource
}

func CreateAccFilterEntryDSWithoutName(rName string) string {
fmt.Println("=== STEP Basic: testing filter entry reading without giving name")
resource := fmt.Sprintf(`
resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_filter" "test"{
tenant_dn = aci_tenant.test.id
name = "%s"
}

resource "aci_filter_entry" "test"{
filter_dn = aci_filter.test.id
name = "%s"
}

data "aci_filter_entry" "test" {
filter_dn = aci_filter.test.id
}
`, rName, rName, rName)
return resource
}
2 changes: 0 additions & 2 deletions testacc/resource_aci_cloudcidr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,3 @@ func CreateAccCloudCIDRPoolUpdatedAttr(fvTenantName, cloudCtxProfileName, addr,
`, fvTenantName, fvTenantName, cloudCtxProfileName, primaryCidrVal, regionVal, cloudVendorVal, addr, attribute, value)
return resource
}


2 changes: 1 addition & 1 deletion testacc/resource_aci_epipagingp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestAccAciIPAgingPolicy_Basic(t *testing.T) {
),
},
{
Config: CreateAccIPAgingPolicyUpdatedAttr("admin_st", "disabled"),
Config: CreateAccIPAgingPolicyUpdatedAttr("admin_st", "disabled"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAciIPAgingPolicyExists(resourceName, &endpoint_ip_aging_profile_updated),
resource.TestCheckResourceAttr(resourceName, "admin_st", "disabled"),
Expand Down
2 changes: 1 addition & 1 deletion testacc/resource_aci_fcdomp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,4 @@ func CreateAccFCDomainUpdatedAttr(rName, attribute, value string) string {
}
`, rName, attribute, value)
return resource
}
}
1 change: 0 additions & 1 deletion testacc/resource_aci_fvepretpol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func TestAccAciEndPointRetentionPolicy_Basic(t *testing.T) {
})
}


func TestAccAciEndPointRetentionPolicy_Negative(t *testing.T) {
rName := makeTestVariable(acctest.RandString(5))

Expand Down
2 changes: 1 addition & 1 deletion testacc/resource_aci_infrafexbndlgrp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,4 @@ func CreateAccFexBundleGroupUpdatedAttr(infraFexPName, rName, attribute, value s
}
`, infraFexPName, rName, attribute, value)
return resource
}
}
1 change: 0 additions & 1 deletion testacc/resource_aci_tagannotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,3 @@ func CreateAccAnnotationRemovingRequiredField() string {

return resource
}

2 changes: 1 addition & 1 deletion testacc/resource_aci_tagtag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,4 @@ func CreateAccTagRemovingRequiredField() string {
`)

return resource
}
}
Loading