-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to upgrade to latest possible versions for RabbitMQ and E…
…rlang (#151) Automatically upgrades both RabbitMQ and Erlang to latest possible upgradable versions. Depends on the current versions used for the CloudAMQP instance. - Retrieve latest possible upgradable versions based on current versions used. - Upgrade to latest possible upgradable versions. Co-authored-by: Johan Nordlund <[email protected]>
- Loading branch information
Showing
8 changed files
with
239 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cloudamqp | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/84codes/go-api/api" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceUpgradableVersions() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceUpgradableVersionRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"instance_id": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "Instance identifier", | ||
}, | ||
"new_rabbitmq_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Latest possible upgradable RabbitMQ version", | ||
}, | ||
"new_erlang_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Latest possible upgradable Erlang version", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceUpgradableVersionRead(d *schema.ResourceData, meta interface{}) error { | ||
api := meta.(*api.API) | ||
data, err := api.ReadVersions(d.Get("instance_id").(int)) | ||
if err != nil { | ||
return err | ||
} | ||
instanceID := strconv.Itoa(d.Get("instance_id").(int)) | ||
d.SetId(instanceID) | ||
|
||
for k, v := range data { | ||
if validateVersionsSchemaAttribute(k) { | ||
d.Set(k, v) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validateVersionsSchemaAttribute(key string) bool { | ||
switch key { | ||
case "new_rabbitmq_version", | ||
"new_erlang_version": | ||
return true | ||
} | ||
return false | ||
} |
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,49 @@ | ||
package cloudamqp | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
|
||
"github.com/84codes/go-api/api" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceUpgradeRabbitMQ() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceUpgradeRabbitMQInvoke, | ||
Read: resourceUpgradeRabbitMQRead, | ||
Delete: resourceUpgradeRabbitMQRemove, | ||
Schema: map[string]*schema.Schema{ | ||
"instance_id": { | ||
Type: schema.TypeInt, | ||
ForceNew: true, | ||
Required: true, | ||
Description: "The CloudAMQP instance identifier", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceUpgradeRabbitMQInvoke(d *schema.ResourceData, meta interface{}) error { | ||
api := meta.(*api.API) | ||
response, err := api.UpgradeRabbitMQ(d.Get("instance_id").(int)) | ||
if err != nil { | ||
return err | ||
} | ||
id := strconv.Itoa(d.Get("instance_id").(int)) | ||
d.SetId(id) | ||
|
||
if len(response) > 0 { | ||
log.Printf("[INFO] - " + response) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceUpgradeRabbitMQRead(d *schema.ResourceData, meta interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceUpgradeRabbitMQRemove(d *schema.ResourceData, meta interface{}) error { | ||
return nil | ||
} |
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,33 @@ | ||
--- | ||
layout: "cloudamqp" | ||
page_title: "CloudAMQP: data source upgradable_versions" | ||
description: |- | ||
Get information of upgradable versions for RabbitMQ and Erlang. | ||
--- | ||
|
||
# cloudamqp_plugins | ||
|
||
Use this data source to retrieve information about possible upgradable versions for RabbitMQ and Erlang. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "cloudamqp_upgradable_versions" "versions" { | ||
instance_id = cloudamqp_instance.instance.id | ||
} | ||
``` | ||
|
||
## Argument reference | ||
|
||
* `instance_id` - (Required) The CloudAMQP instance identifier. | ||
|
||
## Attributes reference | ||
|
||
All attributes reference are computed | ||
|
||
* `new_rabbitmq_version` - Possible upgradable version for RabbitMQ. | ||
* `new_erlang_version` - Possible upgradable version for Erlang. | ||
|
||
## Dependency | ||
|
||
This data source depends on CloudAMQP instance identifier, `cloudamqp_instance.instance.id`. |
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,60 @@ | ||
--- | ||
layout: "cloudamqp" | ||
page_title: "CloudAMQP: cloudamqp_upgrade_rabbitmq" | ||
description: |- | ||
Invoke upgrade to latest possible upgradable versions for RabbitMQ and Erlang. | ||
--- | ||
|
||
# cloudamqp_vpc | ||
|
||
This resource allows you to automatically upgrade to latest possible upgradable versions for RabbitMQ and Erlang. Depending on initial versions of RabbitMQ and Erlang of the CloudAMQP instance. Multiple runs may be needed to get to latest versions. (E.g. after completed upgrade, check data source `cloudamqp_upgradable_versions` to see if newer versions is available. Then delete `cloudamqp_upgrade_rabbitmq` and create it again to invoke the upgrade. | ||
|
||
Only available for dedicated subscription plans. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
# Retrieve latest possible upgradable versions for RabbitMQ and Erlang | ||
data "cloudamqp_upgradable_versions" "versions" { | ||
instance_id = cloudamqp_instance.instance.id | ||
} | ||
# Invoke automatically upgrade to latest possible upgradable versions for RabbitMQ and Erlang | ||
resource "cloudamqp_upgrade_rabbitmq" "upgrade" { | ||
instance_id = cloudamqp_instance.instance.id | ||
} | ||
``` | ||
|
||
```hcl | ||
# Retrieve latest possible upgradable versions for RabbitMQ and Erlang | ||
data "cloudamqp_upgradable_versions" "versions" { | ||
instance_id = cloudamqp_instance.instance.id | ||
} | ||
# Delete the resource | ||
# resource "cloudamqp_upgrade_rabbitmq" "upgrade" { | ||
# instance_id = cloudamqp_instance.instance.id | ||
# } | ||
``` | ||
|
||
If newer version is still available to be upgradable in the data source, re-run again. | ||
|
||
```hcl | ||
# Retrieve latest possible upgradable versions for RabbitMQ and Erlang | ||
data "cloudamqp_upgradable_versions" "versions" { | ||
instance_id = cloudamqp_instance.instance.id | ||
} | ||
# Invoke automatically upgrade to latest possible upgradable versions for RabbitMQ and Erlang | ||
resource "cloudamqp_upgrade_rabbitmq" "upgrade" { | ||
instance_id = cloudamqp_instance.instance.id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `instance_id` - (Required) The CloudAMQP instance identifier | ||
|
||
## Import | ||
|
||
Not possible to import this resource. |
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