-
Notifications
You must be signed in to change notification settings - Fork 38
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
Upgrade LavinMQ instances #296
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12ddc6c
add upgrade_lavinmq resource
viktorerlingsson 99862da
add test and fixture
viktorerlingsson 8e2c390
add TestAccUpgradeLavinMQ_Specific
viktorerlingsson a2c5bd6
remove test for upgrading to latest LavinMQ. Remove lavinmq-specific …
viktorerlingsson 068c4de
changelog
viktorerlingsson a6f273d
remove mentions of upgrade to latest, since that not supported for La…
viktorerlingsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,116 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
) | ||
|
||
// ReadVersions - Read versions LavinMQ can upgrade to | ||
func (api *API) ReadLavinMQVersions(instanceID int) (map[string]any, error) { | ||
var ( | ||
data map[string]any | ||
failed map[string]any | ||
path = fmt.Sprintf("api/instances/%d/actions/new-lavinmq-versions", instanceID) | ||
) | ||
|
||
log.Printf("[DEBUG] api::upgrade_lavinmq#read_versions path: %s", path) | ||
response, err := api.sling.New().Path(path).Receive(&data, &failed) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch response.StatusCode { | ||
case 200: | ||
return data, nil | ||
default: | ||
return nil, fmt.Errorf("ReadVersions failed, status: %d, message: %s", | ||
response.StatusCode, failed) | ||
} | ||
} | ||
|
||
// UpgradeLavinMQ - Upgrade to latest possible version or a specific available version | ||
func (api *API) UpgradeLavinMQ(instanceID int, new_version string) (string, error) { | ||
log.Printf("[DEBUG] api::upgrade_lavinmq#upgrade_lavinmq instanceID: %d"+ | ||
", new_version: %s", instanceID, new_version) | ||
|
||
if new_version == "" { | ||
return api.UpgradeToLatestLavinMQVersion(instanceID) | ||
} else { | ||
return api.UpgradeToSpecificLavinMQVersion(instanceID, new_version) | ||
} | ||
} | ||
|
||
func (api *API) UpgradeToSpecificLavinMQVersion(instanceID int, version string) (string, error) { | ||
var ( | ||
data map[string]any | ||
failed map[string]any | ||
path = fmt.Sprintf("api/instances/%d/actions/upgrade-lavinmq", instanceID) | ||
params = make(map[string]any) | ||
) | ||
|
||
params["version"] = version | ||
log.Printf("[DEBUG] api::upgrade_lavinmq#upgrade_to_specific_version path: %s, params: %v", | ||
path, params) | ||
response, err := api.sling.New().Post(path).BodyJSON(params).Receive(&data, &failed) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
switch response.StatusCode { | ||
case 200: | ||
return api.waitUntilLavinMQUpgraded(instanceID) | ||
default: | ||
return "", fmt.Errorf("upgrade LavinMQ failed, status: %d, message: %s", | ||
response.StatusCode, failed) | ||
} | ||
} | ||
|
||
func (api *API) UpgradeToLatestLavinMQVersion(instanceID int) (string, error) { | ||
var ( | ||
data map[string]any | ||
failed map[string]any | ||
path = fmt.Sprintf("api/instances/%d/actions/upgrade-lavinmq", instanceID) | ||
) | ||
|
||
log.Printf("[DEBUG] api::upgrade_lavinmq#upgrade_to_latest_version path: %s", path) | ||
response, err := api.sling.New().Post(path).Receive(&data, &failed) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
switch response.StatusCode { | ||
case 200: | ||
return "Already at highest possible version", nil | ||
case 202: | ||
return api.waitUntilLavinMQUpgraded(instanceID) | ||
default: | ||
return "", fmt.Errorf("upgrade LavinMQ failed, status: %d, message: %s", | ||
response.StatusCode, failed) | ||
} | ||
} | ||
|
||
func (api *API) waitUntilLavinMQUpgraded(instanceID int) (string, error) { | ||
var ( | ||
data []map[string]any | ||
failed map[string]any | ||
path = fmt.Sprintf("api/instances/%d/nodes", instanceID) | ||
) | ||
|
||
for { | ||
_, err := api.sling.New().Path(path).Receive(&data, &failed) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
log.Printf("[DEBUG] api::upgrade_lavinmq#waitUntilUpgraded data: %v", data) | ||
ready := true | ||
for _, node := range data { | ||
ready = ready && node["configured"].(bool) | ||
} | ||
if ready { | ||
return "", nil | ||
} | ||
time.Sleep(10 * time.Second) | ||
} | ||
} |
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,65 @@ | ||
package cloudamqp | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
|
||
"github.com/cloudamqp/terraform-provider-cloudamqp/api" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceUpgradeLavinMQ() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceUpgradeLavinMQInvoke, | ||
Read: resourceUpgradeLavinMQRead, | ||
Update: resourceUpgradeLavinMQUpdate, | ||
Delete: resourceUpgradeLavinMQRemove, | ||
Schema: map[string]*schema.Schema{ | ||
"instance_id": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "The CloudAMQP instance identifier", | ||
}, | ||
"new_version": { | ||
Type: schema.TypeString, | ||
ForceNew: true, | ||
Optional: true, | ||
Description: "The new version to upgrade to", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceUpgradeLavinMQInvoke(d *schema.ResourceData, meta interface{}) error { | ||
var ( | ||
api = meta.(*api.API) | ||
instanceID = d.Get("instance_id").(int) | ||
new_version = d.Get("new_version").(string) | ||
) | ||
|
||
log.Printf("[DEBUG] - Upgrading LavinMQ instance %d to version %s", instanceID, new_version) | ||
response, err := api.UpgradeLavinMQ(instanceID, new_version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(strconv.Itoa(instanceID)) | ||
|
||
if len(response) > 0 { | ||
log.Printf("[INFO] - " + response) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceUpgradeLavinMQRead(d *schema.ResourceData, meta interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceUpgradeLavinMQUpdate(d *schema.ResourceData, meta interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceUpgradeLavinMQRemove(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,91 @@ | ||
package cloudamqp | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/cloudamqp/terraform-provider-cloudamqp/cloudamqp/vcr-testing/configuration" | ||
"github.com/cloudamqp/terraform-provider-cloudamqp/cloudamqp/vcr-testing/converter" | ||
) | ||
|
||
// TestAccUpgradeLavintMQ: Upgrade LavinMQ to a specific version, from 1.3.1 -> 2.0.0-rc.3 | ||
// Extra checks are needed when comparing versions, because next step is executed before backend | ||
// have been updated. | ||
func TestAccUpgradeLavinMQ(t *testing.T) { | ||
var ( | ||
fileNames = []string{"instance_with_version", "data_source/nodes"} | ||
instanceResourceName = "cloudamqp_instance.instance" | ||
dataSourceNodesName = "data.cloudamqp_nodes.nodes" | ||
plan = "wolverine-1" | ||
|
||
params = map[string]string{ | ||
"InstanceName": "TestAccUpgradeLavinMQ", | ||
"InstanceTags": converter.CommaStringArray([]string{"terraform"}), | ||
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName), | ||
"InstanceRmqVersion": "1.3.1", | ||
"InstancePlan": plan, | ||
} | ||
|
||
fileNamesUpgrade = []string{"instance", "data_source/nodes", "upgrade_lavinmq"} | ||
|
||
paramsUpgrade01 = map[string]string{ | ||
"InstanceName": "TestAccUpgradeLavinMQ", | ||
"InstanceTags": converter.CommaStringArray([]string{"terraform"}), | ||
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName), | ||
"UpgradeLavinMQNewVersion": "2.0.0-rc.3", | ||
"InstancePlan": plan, | ||
} | ||
|
||
fileNamesCheckUpgrade = []string{"instance", "data_source/nodes"} | ||
paramsCheck = map[string]string{ | ||
"InstanceName": "TestAccUpgradeLavinMQ", | ||
"InstanceTags": converter.CommaStringArray([]string{"terraform"}), | ||
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName), | ||
"InstancePlan": plan, | ||
} | ||
) | ||
|
||
cloudamqpResourceTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviderFactory, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: configuration.GetTemplatedConfig(t, fileNames, params), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(instanceResourceName, "name", params["InstanceName"]), | ||
resource.TestCheckResourceAttr(instanceResourceName, "plan", "wolverine-1"), | ||
resource.TestCheckResourceAttr(instanceResourceName, "region", "amazon-web-services::us-east-1"), | ||
resource.TestCheckResourceAttr(instanceResourceName, "rmq_version", params["InstanceRmqVersion"]), | ||
resource.TestCheckResourceAttr(instanceResourceName, "tags.#", "1"), | ||
resource.TestCheckResourceAttr(instanceResourceName, "tags.0", "terraform"), | ||
resource.TestCheckResourceAttr(instanceResourceName, "nodes", "1"), | ||
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", params["InstanceRmqVersion"]), | ||
), | ||
}, | ||
{ | ||
Config: configuration.GetTemplatedConfig(t, fileNamesUpgrade, paramsUpgrade01), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "1.3.1"), | ||
), | ||
}, | ||
{ | ||
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "2.0.0-rc.3"), | ||
), | ||
}, | ||
{ | ||
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "2.0.0-rc.3"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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,92 @@ | ||
--- | ||
layout: "cloudamqp" | ||
page_title: "CloudAMQP: cloudamqp_upgrade_lavinmq" | ||
description: |- | ||
Invoke upgrade to latest possible upgradable versions for LavinMQ. | ||
--- | ||
|
||
# cloudamqp_upgrade_lavinmq | ||
|
||
This resource allows you to upgrade LavinMQ version. | ||
|
||
There is two different ways to trigger the version upgrade | ||
|
||
> - Specify LavinMQ version to upgrade to | ||
> - Upgrade to latest LavinMQ version | ||
|
||
See, below example usage for the difference. | ||
|
||
Only available for dedicated subscription plans running ***LavinMQ***. | ||
|
||
## Example Usage | ||
|
||
<details> | ||
<summary> | ||
<b> | ||
<i>Specify version upgrade, from v1.31.0</i> | ||
</b> | ||
</summary> | ||
|
||
Specify the version to upgrade to. List available upgradable versions, use [CloudAMQP API](https://docs.cloudamqp.com/cloudamqp_api.html#get-available-versions). | ||
After the upgrade finished, there can still be newer versions available. | ||
|
||
```hcl | ||
resource "cloudamqp_instance" "instance" { | ||
name = "lavinmq-version-upgrade-test" | ||
plan = "lynx-1" | ||
region = "amazon-web-services::us-west-1" | ||
} | ||
|
||
resource "cloudamqp_upgrade_lavinmq" "upgrade" { | ||
instance_id = cloudamqp_instance.instance.id | ||
new_version = "1.3.1" | ||
} | ||
``` | ||
|
||
</details> | ||
|
||
<details> | ||
<summary> | ||
<b> | ||
<i>Upgrade to latest possible version, from v1.31.0</i> | ||
</b> | ||
</summary> | ||
|
||
This will upgrade LavinMQ to the latest possible version detected by the data source `cloudamqp_upgradable_versions`. | ||
|
||
```hcl | ||
resource "cloudamqp_instance" "instance" { | ||
name = "lavinmq-version-upgrade-test" | ||
plan = "lynx-1" | ||
region = "amazon-web-services::us-west-1" | ||
} | ||
|
||
data "cloudamqp_upgradable_versions" "upgradable_versions" { | ||
instance_id = cloudamqp_instance.instance.id | ||
} | ||
|
||
resource "cloudamqp_upgrade_lavinmq" "upgrade" { | ||
instance_id = cloudamqp_instance.instance.id | ||
current_version = cloudamqp_instance.instance.rmq_version | ||
new_version = data.cloudamqp_upgradable_versions.upgradable_versions.new_lavinmq_version | ||
} | ||
``` | ||
|
||
</details> | ||
|
||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `instance_id` - (Required) The CloudAMQP instance identifier | ||
* `new_version` - (Optional/ForceNew) The new version to upgrade to | ||
|
||
## Import | ||
|
||
Not possible to import this resource. | ||
|
||
## Important Upgrade Information | ||
|
||
> - All single node upgrades will require some downtime since LavinMQ needs a restart. | ||
> - Auto delete queues (queues that are marked AD) will be deleted during the update. |
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,4 @@ | ||
resource "cloudamqp_upgrade_lavinmq" "upgrade" { | ||
instance_id = {{.InstanceID}} | ||
new_version = "{{.UpgradeLavinMQNewVersion}}" | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@viktorerlingsson Do we want to support upgrade to latest for LavinMQ? Been testing around a bit and will require some more changes to support that. If not we can remove some part of the documentation describing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you're right. I removed all text about upgrading to latest and re-phrased some stuff