From 9a5e2931d086446749fc967424942528dbb30d15 Mon Sep 17 00:00:00 2001 From: chinthalapalli Date: Thu, 1 Aug 2024 15:45:52 +0530 Subject: [PATCH 1/2] adding fixes for tests --- bigip/datasource_bigip_ltm_monitor.go | 31 ++++++++ bigip/resource_bigip_awaf_policy_test.go | 76 +++++++++++++++++++ bigip/resource_bigip_ltm_monitor.go | 38 ++++++++++ bigip/resource_bigip_ltm_monitor_test.go | 36 +++++++++ .../github.com/f5devcentral/go-bigip/ltm.go | 12 +++ 5 files changed, 193 insertions(+) create mode 100644 bigip/resource_bigip_awaf_policy_test.go diff --git a/bigip/datasource_bigip_ltm_monitor.go b/bigip/datasource_bigip_ltm_monitor.go index 24f7febdd..a4a3ec8ba 100644 --- a/bigip/datasource_bigip_ltm_monitor.go +++ b/bigip/datasource_bigip_ltm_monitor.go @@ -103,6 +103,32 @@ func dataSourceBigipLtmMonitor() *schema.Resource { Computed: true, Description: "the database in which your user is created", }, + + "base": { + Type: schema.TypeString, + Computed: true, + Description: "Specifies the location in the LDAP tree from which the monitor starts the health check", + }, + "filter": { + Type: schema.TypeString, + Computed: true, + Description: "Specifies an LDAP key for which the monitor searches", + }, + "mandatory_attributes": { + Type: schema.TypeString, + Computed: true, + Description: "Specifies whether the target must include attributes in its response to be considered up. The options are no (Specifies that the system performs only a one-level search (based on the Filter setting), and does not require that the target returns any attributes.) and yes (Specifies that the system performs a sub-tree search, and if the target returns no attributes, the target is considered down.)", + }, + "chase_referrals": { + Type: schema.TypeString, + Computed: true, + Description: "Specifies whether the system will query the LDAP servers pointed to by any referrals in the query results.", + }, + "security": { + Type: schema.TypeString, + Computed: true, + Description: "Specifies the secure communications protocol that the monitor uses to communicate with the target. The options are none (Specifies that the system does not use a security protocol for communications with the target.), ssl (Specifies that the system uses the SSL protocol for communications with the target.), and tls (Specifies that the system uses the TLS protocol for communications with the target.)", + }, }, } } @@ -141,6 +167,11 @@ func dataSourceBigipLtmMonitorRead(ctx context.Context, d *schema.ResourceData, _ = d.Set("username", m.Username) _ = d.Set("name", name) _ = d.Set("database", m.Database) + _ = d.Set("base", m.Base) + _ = d.Set("filter", m.Filter) + _ = d.Set("mandatory_attributes", m.MandatoryAttributes) + _ = d.Set("chase_referrals", m.ChaseReferrals) + _ = d.Set("security", m.Security) d.SetId(m.FullPath) return nil } diff --git a/bigip/resource_bigip_awaf_policy_test.go b/bigip/resource_bigip_awaf_policy_test.go new file mode 100644 index 000000000..8676f2601 --- /dev/null +++ b/bigip/resource_bigip_awaf_policy_test.go @@ -0,0 +1,76 @@ +/* +Original work from https://github.com/DealerDotCom/terraform-provider-bigip +Modifications Copyright 2019 F5 Networks Inc. +This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +If a copy of the MPL was not distributed with this file,You can obtain one at https://mozilla.org/MPL/2.0/. +*/ +package bigip + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccBigipLtmWafPolicyTestCases(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAcctPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testMonitorsDestroyed, + Steps: []resource.TestStep{ + { + Config: loadFixtureString("../examples/awaf/awaftest_issue822.tf"), + Check: resource.ComposeTestCheckFunc( + // testCheckMonitorExists("/Common/test_monitor_tc1"), + // testCheckMonitorExists("/Common/test_monitor_tc2"), + // testCheckMonitorExists("/Common/test_monitor_tc3"), + // testCheckMonitorExists("/Common/test_monitor_tc4"), + // testCheckMonitorExists("/Common/test_monitor_tc5"), + ), + }, + }, + }) +} + +// func testCheckMonitorExists(name string) resource.TestCheckFunc { +// return func(s *terraform.State) error { +// client := testAccProvider.Meta().(*bigip.BigIP) + +// monitors, err := client.Monitors() +// if err != nil { +// return err +// } + +// for _, m := range monitors { +// if m.FullPath == name { +// return nil +// } +// } +// return fmt.Errorf("Monitor %s was not created ", name) +// } +// } + +// func testMonitorsDestroyed(s *terraform.State) error { +// client := testAccProvider.Meta().(*bigip.BigIP) + +// monitors, err := client.Monitors() +// if err != nil { +// return err +// } + +// for _, rs := range s.RootModule().Resources { +// if rs.Type != "bigip_ltm_monitor" { +// continue +// } + +// name := rs.Primary.ID +// for _, m := range monitors { +// if m.FullPath == name { +// return fmt.Errorf("Monitor %s not destroyed ", name) +// } +// } +// } +// return nil +// } diff --git a/bigip/resource_bigip_ltm_monitor.go b/bigip/resource_bigip_ltm_monitor.go index 943198e8c..444b6a4be 100644 --- a/bigip/resource_bigip_ltm_monitor.go +++ b/bigip/resource_bigip_ltm_monitor.go @@ -196,6 +196,33 @@ func resourceBigipLtmMonitor() *schema.Resource { Optional: true, Description: "the ssl profile", }, + + "base": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies the location in the LDAP tree from which the monitor starts the health check", + }, + "filter": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies an LDAP key for which the monitor searches", + }, + "mandatory_attributes": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies whether the target must include attributes in its response to be considered up. The options are no (Specifies that the system performs only a one-level search (based on the Filter setting), and does not require that the target returns any attributes.) and yes (Specifies that the system performs a sub-tree search, and if the target returns no attributes, the target is considered down.)", + }, + "chase_referrals": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Specifies whether the system will query the LDAP servers pointed to by any referrals in the query results.", + }, + "security": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies the secure communications protocol that the monitor uses to communicate with the target. The options are none (Specifies that the system does not use a security protocol for communications with the target.), ssl (Specifies that the system uses the SSL protocol for communications with the target.), and tls (Specifies that the system uses the TLS protocol for communications with the target.)", + }, }, } } @@ -287,6 +314,12 @@ func resourceBigipLtmMonitorRead(ctx context.Context, d *schema.ResourceData, me _ = d.Set("password", m.Password) _ = d.Set("name", name) _ = d.Set("database", m.Database) + + _ = d.Set("base", m.Base) + _ = d.Set("filter", m.Filter) + _ = d.Set("mandatory_attributes", m.MandatoryAttributes) + _ = d.Set("chase_referrals", m.ChaseReferrals) + _ = d.Set("security", m.Security) return nil } } @@ -382,5 +415,10 @@ func getLtmMonitorConfig(d *schema.ResourceData, config *bigip.Monitor) *bigip.M config.Password = d.Get("password").(string) config.UpInterval = d.Get("up_interval").(int) config.SSLProfile = d.Get("ssl_profile").(string) + config.Base = d.Get("base").(string) + config.Filter = d.Get("filter").(string) + config.MandatoryAttributes = d.Get("mandatory_attributes").(string) + config.ChaseReferrals = d.Get("chase_referrals").(string) + config.Security = d.Get("security").(string) return config } diff --git a/bigip/resource_bigip_ltm_monitor_test.go b/bigip/resource_bigip_ltm_monitor_test.go index eaebe5981..06d93b3d5 100644 --- a/bigip/resource_bigip_ltm_monitor_test.go +++ b/bigip/resource_bigip_ltm_monitor_test.go @@ -22,6 +22,7 @@ var TestHttpsMonitorName = fmt.Sprintf("/%s/test-https-monitor", TestPartition) var TestFtpMonitorName = fmt.Sprintf("/%s/test-ftp-monitor", TestPartition) var TestUdpMonitorName = fmt.Sprintf("/%s/test-udp-monitor", TestPartition) var TestPostgresqlMonitorName = fmt.Sprintf("/%s/test-postgresql-monitor", TestPartition) +var TestLDAPMonitorName = fmt.Sprintf("/%s/test-ldap-monitor", TestPartition) var TestGatewayIcmpMonitorName = fmt.Sprintf("/%s/test-gateway", TestPartition) var TestTcpHalfOpenMonitorName = fmt.Sprintf("/%s/test-tcp-half-open", TestPartition) @@ -97,6 +98,17 @@ resource "bigip_ltm_monitor" "test-postgresql-monitor" { } ` +var TestLDAPMonitorResource = ` +resource "bigip_ltm_monitor" "test-ldap-monitor" { + name = "` + TestLDAPMonitorName + `" + parent = "/Common/ldap" + interval = 5 + timeout = 16 + base = "DC=company,DC=com" + filter = "(cn=username)" + security = "ssl" +} +` var TestGatewayIcmpMonitorResource = ` resource "bigip_ltm_monitor" "test-gateway-icmp-monitor" { name = "` + TestGatewayIcmpMonitorName + `" @@ -292,6 +304,30 @@ func TestAccBigipLtmMonitor_UdpCreate(t *testing.T) { }, }) } +func TestAccBigipLtmMonitor_LDAPCreate(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAcctPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testMonitorsDestroyed, + Steps: []resource.TestStep{ + { + Config: TestLDAPMonitorResource, + Check: resource.ComposeTestCheckFunc( + testCheckMonitorExists(TestLDAPMonitorName), + resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "parent", "/Common/ldap"), + resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "timeout", "16"), + resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "interval", "5"), + resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "filter", "(cn=username)"), + resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "security", "ssl"), + resource.TestCheckResourceAttr("bigip_ltm_monitor.test-ldap-monitor", "base", "DC=company,DC=com"), + ), + }, + }, + }) +} + func TestAccBigipLtmMonitor_PostgresqlCreate(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { diff --git a/vendor/github.com/f5devcentral/go-bigip/ltm.go b/vendor/github.com/f5devcentral/go-bigip/ltm.go index be226f060..9661bbbb9 100644 --- a/vendor/github.com/f5devcentral/go-bigip/ltm.go +++ b/vendor/github.com/f5devcentral/go-bigip/ltm.go @@ -1067,6 +1067,12 @@ type Monitor struct { RecvRow string `json:"recvRow,omitempty"` RecvColumn string `json:"recvColumn,omitempty"` SSLProfile string `json:"sslProfile,omitempty"` + // ldap specifics + Base string `json:"base,omitempty"` + Filter string `json:"filter,omitempty"` + MandatoryAttributes string `json:"mandatoryAttributes,omitempty"` + ChaseReferrals string `json:"chaseReferrals,omitempty"` + Security string `json:"security,omitempty"` } type monitorDTO struct { @@ -1100,6 +1106,12 @@ type monitorDTO struct { RecvRow string `json:"recvRow,omitempty"` RecvColumn string `json:"recvColumn,omitempty"` SSLProfile string `json:"sslProfile,omitempty"` + // ldap specifics + Base string `json:"base,omitempty"` + Filter string `json:"filter,omitempty"` + MandatoryAttributes string `json:"mandatoryAttributes,omitempty"` + ChaseReferrals string `json:"chaseReferrals,omitempty"` + Security string `json:"security,omitempty"` } type Profiles struct { From bf37ccb8eddc160a5acf58d5b29c9520f5815293 Mon Sep 17 00:00:00 2001 From: chinthalapalli Date: Thu, 1 Aug 2024 15:57:31 +0530 Subject: [PATCH 2/2] fix vendor issues --- bigip/version.go | 2 +- go.mod | 4 ++-- go.sum | 8 ++++---- vendor/modules.txt | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bigip/version.go b/bigip/version.go index efbc84df9..e893ab519 100644 --- a/bigip/version.go +++ b/bigip/version.go @@ -1,4 +1,4 @@ package bigip // ProviderVersion is set at build-time in the release process -var ProviderVersion = "1.22.2" +var ProviderVersion = "1.22.3" diff --git a/go.mod b/go.mod index 72c209b23..5244920fd 100644 --- a/go.mod +++ b/go.mod @@ -10,8 +10,8 @@ require ( github.com/Azure/azure-storage-blob-go v0.13.0 github.com/Azure/go-autorest/autorest v0.11.18 github.com/Azure/go-autorest/autorest/adal v0.9.13 - github.com/f5devcentral/go-bigip v0.0.0-20240614094559-88a99e648815 - github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240614094559-88a99e648815 + github.com/f5devcentral/go-bigip v0.0.0-20240801101847-64d6eb419ed6 + github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240801101847-64d6eb419ed6 github.com/google/uuid v1.3.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 3574ec992..409e4de31 100644 --- a/go.sum +++ b/go.sum @@ -51,10 +51,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= -github.com/f5devcentral/go-bigip v0.0.0-20240614094559-88a99e648815 h1:SV4C8S2tTdDCTVmqvpc+6qtZnu0R5oFZHzt06xbUUTo= -github.com/f5devcentral/go-bigip v0.0.0-20240614094559-88a99e648815/go.mod h1:0Lkr0fBU6O1yBxF2mt9JFwXpaFbIb/wAY7oM3dMJDdA= -github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240614094559-88a99e648815 h1:djBhjzmQzoU7Up3Mwr+CXCo2QswlkpNEapwWX339JxI= -github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240614094559-88a99e648815/go.mod h1:r7o5I22EvO+fps2u10bz4ZUlTlNHopQSWzVcW19hK3U= +github.com/f5devcentral/go-bigip v0.0.0-20240801101847-64d6eb419ed6 h1:ckTAKRScUrCQLzhr0LjuGEQ+Cdw+DihVacGtk7VHRn4= +github.com/f5devcentral/go-bigip v0.0.0-20240801101847-64d6eb419ed6/go.mod h1:0Lkr0fBU6O1yBxF2mt9JFwXpaFbIb/wAY7oM3dMJDdA= +github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240801101847-64d6eb419ed6 h1:1n8eAKWABMl4ZkjdheVQC19fdyNwO5k/DqP8e3OB2sI= +github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240801101847-64d6eb419ed6/go.mod h1:r7o5I22EvO+fps2u10bz4ZUlTlNHopQSWzVcW19hK3U= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= diff --git a/vendor/modules.txt b/vendor/modules.txt index 53ec37ca9..6ec2436f7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -42,10 +42,10 @@ github.com/apparentlymart/go-textseg/v13/textseg # github.com/davecgh/go-spew v1.1.1 ## explicit github.com/davecgh/go-spew/spew -# github.com/f5devcentral/go-bigip v0.0.0-20240614094559-88a99e648815 +# github.com/f5devcentral/go-bigip v0.0.0-20240801101847-64d6eb419ed6 ## explicit; go 1.20 github.com/f5devcentral/go-bigip -# github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240614094559-88a99e648815 +# github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240801101847-64d6eb419ed6 ## explicit; go 1.13 github.com/f5devcentral/go-bigip/f5teem # github.com/fatih/color v1.13.0