Skip to content

Commit

Permalink
Add support to upgrade to latest possible versions for RabbitMQ and E…
Browse files Browse the repository at this point in the history
…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
tbroden84 and nordlundj authored May 13, 2022
1 parent b8438dc commit c5a5389
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 23 deletions.
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 1.17.0 (Unreleased)

NOTE:

* Updated the API wrapper (go-api) dependency with newer version (1.7.0)

FEATURES:

* Added support to upgrade to latest possible versions for RabbitMQ and Erlang ([#151](https://github.com/cloudamqp/terraform-provider-cloudamqp/pull/151))

## 1.16.0 (May 09, 2022)

NOTE:
Expand All @@ -6,20 +16,23 @@ NOTE:
* Introducing managed VPC resource to decouple VPC from instance. ([#148](https://github.com/cloudamqp/terraform-provider-cloudamqp/pull/148))
* To avoid breaking changes
* It's still possible to create VPC from instance with vpc_subnet, but is discouraged.
* Default behaviour for instance is still to delete associated VPC.
* Default behaviour for instance is still to delete associated VPC.
* To keep managed VPC, set attribute *keep_associated_vpc = true* on each instance resource. This will override the default behaviour when deleting an instance.

FEATURES:
FEATURES:

* Added support for managed VPC resource.
* Added list on all available standalone VPC for an account.
* Added multiple attribute (vpc_id and instance_id) to fetch VPC information.
* Added multiple attribute (vpc_id and instance_id) to handle VPC peering.
* Added documentations for managed VPC resources and guide

IMPROVEMENTS:

* Added keep_associated_vpc attribute for instance resource

DEPRECATED:

* data_source/vpc_gcp_info, intance_id use vpc_id instead
* data_source/vpc_info, instance_id use vpc_id instead
* resource/instance, vpc_subnet create managed VPC instead
Expand Down
59 changes: 59 additions & 0 deletions cloudamqp/data_source_cloudamqp_upgradable_versions.go
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
}
38 changes: 20 additions & 18 deletions cloudamqp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,33 @@ func Provider(v string) *schema.Provider {
},
},
DataSourcesMap: map[string]*schema.Resource{
"cloudamqp_account": dataSourceAccount(),
"cloudamqp_account_vpcs": dataSourceAccountVpcs(),
"cloudamqp_alarm": dataSourceAlarm(),
"cloudamqp_credentials": dataSourceCredentials(),
"cloudamqp_instance": dataSourceInstance(),
"cloudamqp_plugins": dataSourcePlugins(),
"cloudamqp_plugins_community": dataSourcePluginsCommunity(),
"cloudamqp_notification": dataSourceNotification(),
"cloudamqp_vpc_gcp_info": dataSourceVpcGcpInfo(),
"cloudamqp_vpc_info": dataSourceVpcInfo(),
"cloudamqp_nodes": dataSourceNodes(),
"cloudamqp_account_vpcs": dataSourceAccountVpcs(),
"cloudamqp_account": dataSourceAccount(),
"cloudamqp_alarm": dataSourceAlarm(),
"cloudamqp_credentials": dataSourceCredentials(),
"cloudamqp_instance": dataSourceInstance(),
"cloudamqp_nodes": dataSourceNodes(),
"cloudamqp_notification": dataSourceNotification(),
"cloudamqp_plugins_community": dataSourcePluginsCommunity(),
"cloudamqp_plugins": dataSourcePlugins(),
"cloudamqp_upgradable_versions": dataSourceUpgradableVersions(),
"cloudamqp_vpc_gcp_info": dataSourceVpcGcpInfo(),
"cloudamqp_vpc_info": dataSourceVpcInfo(),
},
ResourcesMap: map[string]*schema.Resource{
"cloudamqp_instance": resourceInstance(),
"cloudamqp_notification": resourceNotification(),
"cloudamqp_alarm": resourceAlarm(),
"cloudamqp_custom_domain": resourceCustomDomain(),
"cloudamqp_plugin": resourcePlugin(),
"cloudamqp_instance": resourceInstance(),
"cloudamqp_integration_log": resourceIntegrationLog(),
"cloudamqp_integration_metric": resourceIntegrationMetric(),
"cloudamqp_notification": resourceNotification(),
"cloudamqp_plugin_community": resourcePluginCommunity(),
"cloudamqp_plugin": resourcePlugin(),
"cloudamqp_security_firewall": resourceSecurityFirewall(),
"cloudamqp_vpc": resourceVpc(),
"cloudamqp_vpc_peering": resourceVpcPeering(),
"cloudamqp_upgrade_rabbitmq": resourceUpgradeRabbitMQ(),
"cloudamqp_vpc_gcp_peering": resourceVpcGcpPeering(),
"cloudamqp_integration_log": resourceIntegrationLog(),
"cloudamqp_integration_metric": resourceIntegrationMetric(),
"cloudamqp_vpc_peering": resourceVpcPeering(),
"cloudamqp_vpc": resourceVpc(),
"cloudamqp_webhook": resourceWebhook(),
},
ConfigureFunc: providerConfigure,
Expand Down
49 changes: 49 additions & 0 deletions cloudamqp/resource_cloudamqp_upgrade_rabbitmq.go
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
}
33 changes: 33 additions & 0 deletions docs/data-sources/upgradable_versions.md
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`.
60 changes: 60 additions & 0 deletions docs/resources/upgrade_rabbitmq.md
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.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/cloudamqp/terraform-provider-cloudamqp

go 1.17

require github.com/84codes/go-api v1.6.0
require github.com/84codes/go-api v1.7.0

require github.com/hashicorp/terraform-plugin-sdk v1.17.2

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0 h1:STgFzyU5/8miMl0//zKh2aQeTyeaUH3WN9bSUiJ09bA=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/84codes/go-api v1.6.0 h1:D/UvP9WaZB/lLOM3NjCyyz6QTLkbF+irIJZ1RdUzzaY=
github.com/84codes/go-api v1.6.0/go.mod h1:tn30UAxVRjmXztEc22AJ/Mc4XAeJuxNb7PlwtDrI3c0=
github.com/84codes/go-api v1.7.0 h1:aFUPJRPa8AOCZXWnYz5y99Cp5H+hWShfTZA5VNvJFxA=
github.com/84codes/go-api v1.7.0/go.mod h1:tn30UAxVRjmXztEc22AJ/Mc4XAeJuxNb7PlwtDrI3c0=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
Expand Down

0 comments on commit c5a5389

Please sign in to comment.