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/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"