Skip to content

Commit

Permalink
typo correction for bot-defense
Browse files Browse the repository at this point in the history
  • Loading branch information
RavinderReddyF5 committed Jan 30, 2024
1 parent c6e5097 commit 98f8a8a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bigip/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func Provider() *schema.Provider {
"bigip_ltm_cipher_group": resourceBigipLtmCipherGroup(),
"bigip_partition": resourceBigipPartition(),
"bigip_ltm_request_log_profile": resourceBigipLtmProfileRequestLog(),
"bigip_ltm_profile_bot_defence": resourceBigipLtmProfileBotDefence(),
"bigip_ltm_profile_bot_defense": resourceBigipLtmProfileBotDefense(),
},
}
p.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceBigipLtmProfileBotDefence() *schema.Resource {
func resourceBigipLtmProfileBotDefense() *schema.Resource {
return &schema.Resource{
CreateContext: resourceBigipLtmProfileBotDefenceCreate,
ReadContext: resourceBigipLtmProfileBotDefenceRead,
UpdateContext: resourceBigipLtmProfileBotDefenceUpdate,
DeleteContext: resourceBigipLtmProfileBotDefenceDelete,
CreateContext: resourceBigipLtmProfileBotDefenseCreate,
ReadContext: resourceBigipLtmProfileBotDefenseRead,
UpdateContext: resourceBigipLtmProfileBotDefenseUpdate,
DeleteContext: resourceBigipLtmProfileBotDefenseDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand All @@ -29,7 +29,7 @@ func resourceBigipLtmProfileBotDefence() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Name of the Bot Defence profile",
Description: "Name of the Bot Defense profile",
ValidateFunc: validateF5NameWithDirectory,
},
"defaults_from": {
Expand All @@ -43,7 +43,7 @@ func resourceBigipLtmProfileBotDefence() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "User defined description for Bot Defence profile",
Description: "User defined description for Bot Defense profile",
},
"template": {
Type: schema.TypeString,
Expand All @@ -52,7 +52,7 @@ func resourceBigipLtmProfileBotDefence() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{
"relaxed",
"enabled"}, false),
Description: "Enables or disables Bot Defence. The default is `disabled`",
Description: "Enables or disables Bot Defense. The default is `disabled`",
},
"enforcement_mode": {
Type: schema.TypeString,
Expand All @@ -67,33 +67,33 @@ func resourceBigipLtmProfileBotDefence() *schema.Resource {
}
}

func resourceBigipLtmProfileBotDefenceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceBigipLtmProfileBotDefenseCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)
name := d.Get("name").(string)
log.Printf("[INFO] Creating Bot Defence Profile:%+v ", name)
log.Printf("[INFO] Creating Bot Defense Profile:%+v ", name)
pss := &bigip.BotDefenseProfile{

Check failure on line 74 in bigip/resource_bigip_ltm_profile_bot_defense.go

View workflow job for this annotation

GitHub Actions / golint

undefined: bigip.BotDefenseProfile
Name: name,
}
config := getProfileBotDefenceConfig(d, pss)
log.Printf("[DEBUG] Bot Defence Profile config :%+v ", config)
config := getProfileBotDefenseConfig(d, pss)
log.Printf("[DEBUG] Bot Defense Profile config :%+v ", config)
err := client.AddBotDefenseProfile(config)

Check failure on line 79 in bigip/resource_bigip_ltm_profile_bot_defense.go

View workflow job for this annotation

GitHub Actions / golint

client.AddBotDefenseProfile undefined (type *"github.com/f5devcentral/go-bigip".BigIP has no field or method AddBotDefenseProfile)
if err != nil {
return diag.FromErr(err)
}
d.SetId(name)
return resourceBigipLtmProfileBotDefenceRead(ctx, d, meta)
return resourceBigipLtmProfileBotDefenseRead(ctx, d, meta)
}

func resourceBigipLtmProfileBotDefenceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceBigipLtmProfileBotDefenseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)
log.Printf("[INFO] Reading Bot Defence Profile:%+v ", client)
log.Printf("[INFO] Reading Bot Defense Profile:%+v ", client)
name := d.Id()
log.Printf("[INFO] Reading Bot Defence Profile:%+v ", name)
log.Printf("[INFO] Reading Bot Defense Profile:%+v ", name)
botProfile, err := client.GetBotDefenseProfile(name)

Check failure on line 92 in bigip/resource_bigip_ltm_profile_bot_defense.go

View workflow job for this annotation

GitHub Actions / golint

client.GetBotDefenseProfile undefined (type *"github.com/f5devcentral/go-bigip".BigIP has no field or method GetBotDefenseProfile)
if err != nil {
return diag.FromErr(err)
}
log.Printf("[DEBUG] Bot Defence Profile config :%+v ", botProfile)
log.Printf("[DEBUG] Bot Defense Profile config :%+v ", botProfile)
d.Set("name", botProfile.FullPath)
d.Set("defaults_from", botProfile.DefaultsFrom)
d.Set("description", botProfile.Description)
Expand All @@ -102,27 +102,27 @@ func resourceBigipLtmProfileBotDefenceRead(ctx context.Context, d *schema.Resour
return nil
}

func resourceBigipLtmProfileBotDefenceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceBigipLtmProfileBotDefenseUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)
name := d.Id()
log.Printf("[INFO] Updating Bot Defence Profile:%+v ", name)
log.Printf("[INFO] Updating Bot Defense Profile:%+v ", name)
pss := &bigip.BotDefenseProfile{

Check failure on line 109 in bigip/resource_bigip_ltm_profile_bot_defense.go

View workflow job for this annotation

GitHub Actions / golint

undefined: bigip.BotDefenseProfile
Name: name,
}
config := getProfileBotDefenceConfig(d, pss)
config := getProfileBotDefenseConfig(d, pss)

err := client.ModifyBotDefenseProfile(name, config)

Check failure on line 114 in bigip/resource_bigip_ltm_profile_bot_defense.go

View workflow job for this annotation

GitHub Actions / golint

client.ModifyBotDefenseProfile undefined (type *"github.com/f5devcentral/go-bigip".BigIP has no field or method ModifyBotDefenseProfile)
if err != nil {
return diag.FromErr(err)
}
return resourceBigipLtmProfileBotDefenceRead(ctx, d, meta)
return resourceBigipLtmProfileBotDefenseRead(ctx, d, meta)
}

func resourceBigipLtmProfileBotDefenceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceBigipLtmProfileBotDefenseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)

name := d.Id()
log.Println("[INFO] Deleting Bot Defence Profile " + name)
log.Println("[INFO] Deleting Bot Defense Profile " + name)
err := client.DeleteBotDefenseProfile(name)

Check failure on line 126 in bigip/resource_bigip_ltm_profile_bot_defense.go

View workflow job for this annotation

GitHub Actions / golint

client.DeleteBotDefenseProfile undefined (type *"github.com/f5devcentral/go-bigip".BigIP has no field or method DeleteBotDefenseProfile)
if err != nil {
return diag.FromErr(err)
Expand All @@ -132,12 +132,12 @@ func resourceBigipLtmProfileBotDefenceDelete(ctx context.Context, d *schema.Reso
return nil
}

func getProfileBotDefenceConfig(d *schema.ResourceData, config *bigip.BotDefenseProfile) *bigip.BotDefenseProfile {
func getProfileBotDefenseConfig(d *schema.ResourceData, config *bigip.BotDefenseProfile) *bigip.BotDefenseProfile {

Check failure on line 135 in bigip/resource_bigip_ltm_profile_bot_defense.go

View workflow job for this annotation

GitHub Actions / golint

undefined: bigip.BotDefenseProfile
config.Name = d.Get("name").(string)
config.DefaultsFrom = d.Get("defaults_from").(string)
config.Description = d.Get("description").(string)
config.Template = d.Get("template").(string)
config.EnforcementMode = d.Get("enforcement_mode").(string)
log.Printf("[INFO][getProfileBotDefenceConfig] config:%+v ", config)
log.Printf("[INFO][getProfileBotDefenseConfig] config:%+v ", config)
return config
}
83 changes: 83 additions & 0 deletions bigip/resource_bigip_ltm_profile_bot_defense_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package bigip

import (
"fmt"
"testing"

bigip "github.com/f5devcentral/go-bigip"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

var resBotDefenseName = "bigip_ltm_profile_bot_defense"

func TestAccBigipLtmProfileBotDefenseTC1(t *testing.T) {
t.Parallel()
var instName = "test-bot-defense-tc1"
var TestBotDefenseName = fmt.Sprintf("/%s/%s", TestPartition, instName)
resFullName := fmt.Sprintf("%s.%s", resBotDefenseName, instName)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckBotDefensesDestroyed,
Steps: []resource.TestStep{
{
Config: testaccbigipltmprofileBotDefenseDefaultConfig(TestPartition, TestBotDefenseName, instName),
Check: resource.ComposeTestCheckFunc(
testCheckBotDefenseExists(TestBotDefenseName),
resource.TestCheckResourceAttr(resFullName, "name", TestBotDefenseName),
resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/bot-defense"),
),
Destroy: false,
},
},
})
}

func testCheckBotDefenseExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)
p, err := client.GetBotDefenseProfile(name)
if err != nil {
return err
}
if p == nil {
return fmt.Errorf("BotDefense %s was not created ", name)
}

return nil
}
}

func testCheckBotDefensesDestroyed(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)

for _, rs := range s.RootModule().Resources {
if rs.Type != "bigip_ltm_profile_bot_defence" {
continue
}

name := rs.Primary.ID
BotDefense, err := client.GetBotDefenseProfile(name)
if err != nil {
return err
}
if BotDefense != nil {
return fmt.Errorf("BotDefense %s not destroyed. ", name)
}
}
return nil
}

func testaccbigipltmprofileBotDefenseDefaultConfig(partition, profileName, resourceName string) string {
return fmt.Sprintf(`
resource "bigip_ltm_profile_bot_defence" "%[3]s" {
name = "%[2]s"
defaults_from = "/%[1]s/bot-defense"
description = "test-bot"
template = "relaxed"
}
`, partition, profileName, resourceName)
}

0 comments on commit 98f8a8a

Please sign in to comment.