Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devel fixes #1025

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app1.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
}
}


4 changes: 3 additions & 1 deletion bigip/resource_bigip_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions bigip/resource_bigip_vcmp_guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,19 @@ 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)
err := client.DeleteVcmpDisk(name)
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
}
35 changes: 26 additions & 9 deletions docs/resources/bigip_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 7 additions & 3 deletions examples/as3/example1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -39,4 +43,4 @@
}
}
}
}
}
12 changes: 6 additions & 6 deletions vendor/github.com/f5devcentral/go-bigip/bigip.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions vendor/github.com/f5devcentral/go-bigip/shared.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.