diff --git a/app1.json b/app1.json new file mode 100644 index 00000000..9d026336 --- /dev/null +++ b/app1.json @@ -0,0 +1,27 @@ +{ + "schemaVersion": "3.50.1", + "path_app1": { + "class": "Application", + "vs_name_app1": { + "class": "Service_HTTP", + "virtualAddresses": [ + "192.1.1.24" + ], + "pool": "pool" + }, + "pool": { + "class": "Pool", + "members": [ + { + "servicePort": 80, + "serverAddresses": [ + "192.20.1.10", + "192.30.1.20" + ] + } + ] + } + } +} + + diff --git a/bigip/resource_bigip_command.go b/bigip/resource_bigip_command.go index c2f4b869..fbe79df5 100644 --- a/bigip/resource_bigip_command.go +++ b/bigip/resource_bigip_command.go @@ -61,7 +61,9 @@ func resourceBigipCommandCreate(ctx context.Context, d *schema.ResourceData, met if d.Get("when").(string) == "apply" { if m, ok := d.GetOk("commands"); ok { for _, cmd := range m.([]interface{}) { - commandList = append(commandList, fmt.Sprintf("-c 'tmsh %s'", cmd.(string))) + // Handle edge case where command contains our quote character + escapedCmd := strings.ReplaceAll(cmd.(string), "'", "'\\''") + commandList = append(commandList, fmt.Sprintf("-c 'tmsh %s'", escapedCmd)) } } log.Printf("[INFO] Running TMSH Command : %v ", commandList) diff --git a/bigip/resource_bigip_vcmp_guest.go b/bigip/resource_bigip_vcmp_guest.go index 513007da..2ab3a30b 100644 --- a/bigip/resource_bigip_vcmp_guest.go +++ b/bigip/resource_bigip_vcmp_guest.go @@ -247,6 +247,7 @@ func deleteVirtualDisk(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error retrieving vCMP virtual disks: %v", err) } + diskFound := false for _, disk := range virtualDisks.Disks { if strings.HasPrefix(disk.Name, diskName) { name := strings.Replace(disk.Name, "/", "~", 1) @@ -254,10 +255,11 @@ func deleteVirtualDisk(d *schema.ResourceData, meta interface{}) error { if err != nil { return fmt.Errorf("error deleting vCMP virtual disk: %v %v", diskName, err) } - } else { - return fmt.Errorf("cannot find vCMP virtual disk: %v ", diskName) + diskFound = true } - + } + if !diskFound { + return fmt.Errorf("cannot find vCMP virtual disk: %v ", diskName) } return nil } diff --git a/docs/resources/bigip_command.md b/docs/resources/bigip_command.md index 302a1c44..57ae274b 100644 --- a/docs/resources/bigip_command.md +++ b/docs/resources/bigip_command.md @@ -11,36 +11,53 @@ description: |- `bigip_command` Run TMSH commands on F5 devices This resource is helpful to send TMSH command to an BIG-IP node and returns the results read from the device -## Example Usage +## Example Usage ```hcl resource "bigip_command" "test-command" { commands = ["show sys version"] } - -#create ltm node +# Create ltm node resource "bigip_command" "test-command" { commands = ["create ltm node 10.10.10.70"] } # Destroy ltm node - resource "bigip_command" "test-command" { when = "destroy" commands = ["delete ltm node 10.10.10.70"] } +``` -``` -## Argument Reference +It is also possible to send Bash commands however care is needed with quoting: -* `commands` - (Required) The commands to send to the remote BIG-IP device over the configured provider. The resulting output from the command is returned and added to `command_result` -* `when` - (Optional,possible values:`apply` or `destroy`) default value will be `apply`,can be set to `destroy` for terraform destroy call. +```hcl +resource "bigip_command" "byol-license" { + commands = [ + "bash -c \"cp /config/bigip.license /config/bigip.license.bak.$(date +%s)\"", + "bash -c \"echo ${var.license_file_contents_base64} | base64 --decode > /config/bigip.license\"", + "bash -c \"reloadlic\"" + ] +} +``` + +Note that use of single quotes is not supported, thus this will not work: + +```hcl +resource "bigip_command" "hello-world" { + commands = ["bash -c 'echo hello world'"] +} +``` + +## Argument Reference +* `commands` - (Required) The commands to send to the remote BIG-IP device over the configured provider. The resulting output from the command is returned and added to `command_result` +* `when` - (Optional, possible values: `apply` or `destroy`) default value will be `apply`,can be set to `destroy` for terraform destroy call. ## Attributes Reference In addition to all arguments above, the following attributes are exported: -* `command_result` - The resulting output from the `commands` executed +* `command_result` - The resulting output from the `commands` executed. \ No newline at end of file diff --git a/examples/as3/example1.json b/examples/as3/example1.json index afa24e4b..0ed62980 100644 --- a/examples/as3/example1.json +++ b/examples/as3/example1.json @@ -8,19 +8,23 @@ "id": "example-declaration-01", "label": "Sample 1", "remark": "Simple HTTP application with round robin pool", - "Sample_new": { + "Example_Bot_Def": { "class": "Tenant", "defaultRouteDomain": 0, - "Application_1": { + "Application_Bot": { "class": "Application", "template": "http", "serviceMain": { "class": "Service_HTTP", + "virtualPort": 8080, "virtualAddresses": [ "10.0.1.10" ], "pool": "web_pool" }, + "profileBotDefense": { + "bigip": "/Common/bot-defense" + }, "web_pool": { "class": "Pool", "monitors": [ @@ -39,4 +43,4 @@ } } } -} +} \ No newline at end of file diff --git a/go.mod b/go.mod index 293c9fcd..f3849dac 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-20241015134941-ace8c7550cdb - github.com/f5devcentral/go-bigip/f5teem v0.0.0-20241015134941-ace8c7550cdb + github.com/f5devcentral/go-bigip v0.0.0-20241021135443-33e2cde9829b + github.com/f5devcentral/go-bigip/f5teem v0.0.0-20241021135443-33e2cde9829b 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 97ca1a06..68a3ae41 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-20241015134941-ace8c7550cdb h1:fXszVqyYEUktmRzhAfkBa38quBIGN4mCVdgnEgnzZw4= -github.com/f5devcentral/go-bigip v0.0.0-20241015134941-ace8c7550cdb/go.mod h1:0Lkr0fBU6O1yBxF2mt9JFwXpaFbIb/wAY7oM3dMJDdA= -github.com/f5devcentral/go-bigip/f5teem v0.0.0-20241015134941-ace8c7550cdb h1:m7yCTq/MdZ3JKcXBOqwgnOhOmnAuiHuo4iGODW5nJHQ= -github.com/f5devcentral/go-bigip/f5teem v0.0.0-20241015134941-ace8c7550cdb/go.mod h1:r7o5I22EvO+fps2u10bz4ZUlTlNHopQSWzVcW19hK3U= +github.com/f5devcentral/go-bigip v0.0.0-20241021135443-33e2cde9829b h1:j8CYiCIPBJAO1A94MPQ2mMKwaoZTYYq3+OQPGXJSqcM= +github.com/f5devcentral/go-bigip v0.0.0-20241021135443-33e2cde9829b/go.mod h1:0Lkr0fBU6O1yBxF2mt9JFwXpaFbIb/wAY7oM3dMJDdA= +github.com/f5devcentral/go-bigip/f5teem v0.0.0-20241021135443-33e2cde9829b h1:0/nrne/GsIApV1R2VVG2KPOCOkr5WR4NJ3sRXtM9pFs= +github.com/f5devcentral/go-bigip/f5teem v0.0.0-20241021135443-33e2cde9829b/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/github.com/f5devcentral/go-bigip/bigip.go b/vendor/github.com/f5devcentral/go-bigip/bigip.go index b87183ea..37fd9062 100644 --- a/vendor/github.com/f5devcentral/go-bigip/bigip.go +++ b/vendor/github.com/f5devcentral/go-bigip/bigip.go @@ -159,11 +159,11 @@ func NewTokenSession(bigipConfig *Config) (b *BigIP, err error) { Timeout int64 `json:"timeout"` } - type timeoutResp struct { - Timeout struct { - Timeout int64 - } - } + // type timeoutResp struct { + // Timeout struct { + // Timeout int64 + // } + // } auth := authReq{ bigipConfig.Username, @@ -254,7 +254,7 @@ func NewTokenSession(bigipConfig *Config) (b *BigIP, err error) { } var tresp map[string]interface{} errToken = json.Unmarshal(resp, &tresp) - if err != nil { + if errToken != nil { return b, errToken } if time.Duration(int64(tresp["timeout"].(float64)))*time.Second != bigipConfig.ConfigOptions.TokenTimeout { diff --git a/vendor/github.com/f5devcentral/go-bigip/shared.go b/vendor/github.com/f5devcentral/go-bigip/shared.go index 1f6aa473..6da13361 100644 --- a/vendor/github.com/f5devcentral/go-bigip/shared.go +++ b/vendor/github.com/f5devcentral/go-bigip/shared.go @@ -8,13 +8,12 @@ import ( ) const ( - uriShared = "shared" - uriLicensing = "licensing" - uriActivation = "activation" - uriRegistration = "registration" - uriFileTransfer = "file-transfer" - uriUploads = "uploads" - + uriShared = "shared" + uriLicensing = "licensing" + uriActivation = "activation" + uriRegistration = "registration" + uriFileTransfer = "file-transfer" + uriUploads = "uploads" activationComplete = "LICENSING_COMPLETE" activationInProgress = "LICENSING_ACTIVATION_IN_PROGRESS" activationFailed = "LICENSING_FAILED" diff --git a/vendor/modules.txt b/vendor/modules.txt index 05a5fb0d..d83f5c85 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-20241015134941-ace8c7550cdb +# github.com/f5devcentral/go-bigip v0.0.0-20241021135443-33e2cde9829b ## explicit; go 1.20 github.com/f5devcentral/go-bigip -# github.com/f5devcentral/go-bigip/f5teem v0.0.0-20241015134941-ace8c7550cdb +# github.com/f5devcentral/go-bigip/f5teem v0.0.0-20241021135443-33e2cde9829b ## explicit; go 1.13 github.com/f5devcentral/go-bigip/f5teem # github.com/fatih/color v1.13.0