-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #875 from F5Networks/devel
devel sync to master
- Loading branch information
Showing
12 changed files
with
467 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// Copyright 2023 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 ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
bigip "github.com/f5devcentral/go-bigip" | ||
"github.com/f5devcentral/go-bigip/f5teem" | ||
"github.com/google/uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceBigipLtmCipherGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceBigipLtmCipherGroupCreate, | ||
ReadContext: resourceBigipLtmCipherGroupRead, | ||
UpdateContext: resourceBigipLtmCipherGroupUpdate, | ||
DeleteContext: resourceBigipLtmCipherGroupDelete, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the cipher group,name should be in pattern ``partition` + `cipher group name``", | ||
ForceNew: true, | ||
ValidateFunc: validateF5Name, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Specifies descriptive text that identifies the cipher rule", | ||
}, | ||
"ordering": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
//Default: "default", | ||
Description: "Controls the order of the Cipher String list in the Cipher Audit section. Options are Default, Speed, Strength, FIPS, and Hardware. The rules are processed in the order listed", | ||
}, | ||
"allow": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Description: "Specifies the configuration of the allowed groups of ciphers. You can select a cipher rule from the Available Cipher Rules list", | ||
}, | ||
"require": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Description: "Specifies the configuration of the restrict groups of ciphers. You can select a cipher rule from the Available Cipher Rules list", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceBigipLtmCipherGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*bigip.BigIP) | ||
|
||
name := d.Get("name").(string) | ||
|
||
log.Printf("[INFO] Creating Cipher rule:%+v", name) | ||
|
||
cipherGrouptmp := &bigip.CipherGroupReq{} | ||
cipherGrouptmp.Name = name | ||
cipherGroup := getCipherGroupConfig(d, cipherGrouptmp) | ||
|
||
log.Printf("[INFO] cipherGroup config :%+v", cipherGroup) | ||
err := client.AddLtmCipherGroup(cipherGroup) | ||
if err != nil { | ||
return diag.FromErr(fmt.Errorf("error creating cipher rule (%s): %s", name, err)) | ||
} | ||
if !client.Teem { | ||
id := uuid.New() | ||
uniqueID := id.String() | ||
assetInfo := f5teem.AssetInfo{ | ||
Name: "Terraform-provider-bigip", | ||
Version: client.UserAgent, | ||
Id: uniqueID, | ||
} | ||
apiKey := os.Getenv("TEEM_API_KEY") | ||
teemDevice := f5teem.AnonymousClient(assetInfo, apiKey) | ||
f := map[string]interface{}{ | ||
"Terraform Version": client.UserAgent, | ||
} | ||
tsVer := strings.Split(client.UserAgent, "/") | ||
err = teemDevice.Report(f, "bigip_ltm_cipher_group", tsVer[3]) | ||
if err != nil { | ||
log.Printf("[ERROR]Sending Telemetry data failed:%v", err) | ||
} | ||
} | ||
d.SetId(name) | ||
return resourceBigipLtmCipherGroupRead(ctx, d, meta) | ||
} | ||
|
||
func resourceBigipLtmCipherGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*bigip.BigIP) | ||
name := d.Id() | ||
log.Printf("[INFO] Fetching Cipher group :%+v", name) | ||
cipherGroup, err := client.GetLtmCipherGroup(name) | ||
if err != nil { | ||
log.Printf("[ERROR] Unable to retrieve cipher group %s %v :", name, err) | ||
return diag.FromErr(err) | ||
} | ||
_ = d.Set("name", cipherGroup.FullPath) | ||
_ = d.Set("ordering", cipherGroup.Ordering) | ||
log.Printf("[INFO] Cipher group response :%+v", cipherGroup) | ||
return nil | ||
} | ||
|
||
func resourceBigipLtmCipherGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*bigip.BigIP) | ||
name := d.Id() | ||
cipherGrouptmp := &bigip.CipherGroupReq{} | ||
cipherGrouptmp.Name = name | ||
cipherGroupconfig := getCipherGroupConfig(d, cipherGrouptmp) | ||
if err := client.ModifyLtmCipherGroup(name, cipherGroupconfig); err != nil { | ||
return diag.FromErr(fmt.Errorf("error modifying cipher group %s: %v", name, err)) | ||
} | ||
|
||
return resourceBigipLtmCipherGroupRead(ctx, d, meta) | ||
} | ||
|
||
func resourceBigipLtmCipherGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*bigip.BigIP) | ||
|
||
name := d.Id() | ||
log.Printf("[INFO] Deleting cipher group :%+v", name) | ||
err := client.DeleteLtmCipherGroup(name) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR] Unable to Delete cipher rule %s %v : ", name, err) | ||
return diag.FromErr(err) | ||
} | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
func getCipherGroupConfig(d *schema.ResourceData, cipherGroup *bigip.CipherGroupReq) *bigip.CipherGroupReq { | ||
cipherGroup.Ordering = d.Get("ordering").(string) | ||
if p, ok := d.GetOk("allow"); ok { | ||
for _, r := range p.(*schema.Set).List() { | ||
cipherGroup.Allow = append(cipherGroup.Allow, r.(string)) | ||
} | ||
} | ||
if p, ok := d.GetOk("require"); ok { | ||
for _, r := range p.(*schema.Set).List() { | ||
cipherGroup.Require = append(cipherGroup.Require, r.(string)) | ||
} | ||
} | ||
return cipherGroup | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
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 ( | ||
"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" | ||
) | ||
|
||
const testCipherGroupConfigTC1 = ` | ||
resource "bigip_ltm_cipher_group" "test-cipher-group" { | ||
name = "/Common/test-cipher-group-01" | ||
allow = ["/Common/f5-aes"] | ||
require = ["/Common/f5-quic"] | ||
ordering = "speed" | ||
} | ||
` | ||
|
||
func TestAccBigipLtmCipherGroupCreateTC1(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAcctPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckCipherGroupDestroyed, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testCipherGroupConfigTC1, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckCipherGroupExists("/Common/test-cipher-group-01"), | ||
resource.TestCheckResourceAttr("bigip_ltm_cipher_group.test-cipher-group", "name", "/Common/test-cipher-group-01"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testCheckCipherGroupExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
client := testAccProvider.Meta().(*bigip.BigIP) | ||
|
||
p, err := client.GetLtmCipherGroup(name) | ||
if err != nil { | ||
return err | ||
} | ||
if p == nil { | ||
return fmt.Errorf("Pool %s does not exist ", name) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testCheckCipherGroupDestroyed(s *terraform.State) error { | ||
client := testAccProvider.Meta().(*bigip.BigIP) | ||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "bigip_ltm_cipher_group" { | ||
continue | ||
} | ||
name := rs.Primary.ID | ||
pool, err := client.GetLtmCipherGroup(name) | ||
if err != nil { | ||
return err | ||
} | ||
if pool != nil { | ||
return fmt.Errorf("Cipher rule %s not destroyed ", name) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.