Skip to content

Commit

Permalink
Add creation plan (#228)
Browse files Browse the repository at this point in the history
Co-authored-by: Hieu Doan <[email protected]>
Co-authored-by: Greg Nuttall <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2022
1 parent 09c33e7 commit 39a3652
Show file tree
Hide file tree
Showing 9 changed files with 784 additions and 1,355 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ website/node_modules
*.iml

website/vendor

vendor
.vscode/

# Test exclusions
!command/test-fixtures/**/*.tfstate
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
All notable changes to this project will be documented in this file.
See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## 1.0.0 (X July 2022)

### Added
- Added the creation_plan block in the subscription resource schema.

### Removed
- Removed the database block from the subscription resource schema.

## 0.3.0 (May 24 2022)

### Added
Expand Down
155 changes: 25 additions & 130 deletions docs/resources/rediscloud_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,16 @@ description: |-
# Resource: rediscloud_subscription

Creates a Subscription within your Redis Enterprise Cloud Account.
This resource is responsible for creating subscriptions and the databases within that subscription.
This allows Redis Enterprise Cloud to provision your databases in the most efficient way.
This resource is responsible for creating subscriptions and the databases within
that subscription. This allows Redis Enterprise Cloud to provision
your databases defined in separate resources in the most efficient way.

~> **Note:** The subscription resource manages changes to its databases by identifying a databases through its name. This means **database names cannot be changed**, as this resource has no other way of being able to identify the database and would lead to the database to be destroyed.
Due to the limitations mentioned above, the differences shown by Terraform will be different from normal plan.
When an argument has been changed on a nested database - for example changing the `memory_limit_in_gb` from 1 to 2, Terraform
will display the resource as being modified with the database as being removed, and a new one added. As the resource
identifies the database based on the name, the only change that would happen would be to update the database to increase
the memory limit. Below is the Terraform output for changing the `memory_limit_in_gb` for a single database within a
subscription.

```
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# rediscloud_subscription.example will be updated in-place
~ resource "rediscloud_subscription" "example" {
...
- database {
- average_item_size_in_bytes = 0 -> null
- data_persistence = "none" -> null
- db_id = 51040112 -> null
- external_endpoint_for_oss_cluster_api = false -> null
- memory_limit_in_gb = 1 -> null
- name = "tf-example-database" -> null
- password = (sensitive value)
- private_endpoint = "private.example.com" -> null
- protocol = "redis" -> null
- public_endpoint = "public.example.com" -> null
- replica_of = [] -> null
- replication = false -> null
- source_ips = [] -> null
- support_oss_cluster_api = false -> null
- throughput_measurement_by = "operations-per-second" -> null
- throughput_measurement_value = 10000 -> null
}
+ database {
+ average_item_size_in_bytes = 0
+ data_persistence = "none"
+ db_id = (known after apply)
+ external_endpoint_for_oss_cluster_api = false
+ memory_limit_in_gb = 2
+ name = "tf-example-database"
+ password = (sensitive value)
+ private_endpoint = (known after apply)
+ protocol = "redis"
+ public_endpoint = (known after apply)
+ replica_of = []
+ replication = false
+ source_ips = []
+ support_oss_cluster_api = false
+ throughput_measurement_by = "operations-per-second"
+ throughput_measurement_value = 10000
}
}
Plan: 0 to add, 1 to change, 0 to destroy.
```
~> **Note:** The creation_plan block allows the API server to create a well-optimised hardware specification for your databases in the cluster.
The attributes inside the block are used by the provider to create initial
databases. Those databases will be deleted after provisioning a new
subscription, then the databases defined as separate resources will be attached to
the subscription. The creation_plan block can ONLY be used for provisioning new
subscriptions, the block will be ignored if you make any further changes or try importing the resource (e.g. `terraform import` ...).

## Example Usage

Expand All @@ -84,14 +31,6 @@ data "rediscloud_cloud_account" "account" {
provider_type = "AWS"
}
resource "random_password" "password" {
length = 20
upper = true
lower = true
number = true
special = false
}
resource "rediscloud_subscription" "example" {
name = "example"
Expand All @@ -109,26 +48,17 @@ resource "rediscloud_subscription" "example" {
}
}
database {
name = "tf-example-database"
protocol = "redis"
memory_limit_in_gb = 1
data_persistence = "none"
// This block needs to be defined for provisioning a new subscription.
// This allows creating a well-optimised hardware specification for databases in the cluster
creation_plan {
average_item_size_in_bytes = 1
memory_limit_in_gb = 2
quantity = 1
replication=false
support_oss_cluster_api=false
throughput_measurement_by = "operations-per-second"
throughput_measurement_value = 10000
password = random_password.password.result
alert {
name = "dataset-size"
value = 40
}
}
}
output "database_endpoints" {
value = {
for database in rediscloud_subscription.example.database:
database.name => database.public_endpoint
modules = ["RediSearch", "RedisBloom"]
}
}
```
Expand Down Expand Up @@ -161,34 +91,16 @@ The `cloud_provider` block supports:
only with Redis Labs internal cloud account
* `region` - (Required) Cloud networking details, per region, documented below

The `database` block supports:
The `creation_plan` block supports:

* `name` - (Required) A meaningful name to identify the database. Caution should be taken when changing this value - see
the top of the page for more information.
* `protocol` - (Optional) The protocol that will be used to access the database, (either ‘redis’ or 'memcached’) Default: ‘redis’
* `memory_limit_in_gb` - (Required) Maximum memory usage for this specific database
* `memory_limit_in_gb` - (Required) Maximum memory usage for the initial databases
* `support_oss_cluster_api` - (Optional) Support Redis open-source (OSS) Cluster API. Default: ‘false’
* `external_endpoint_for_oss_cluster_api` - (Optional) Should use the external endpoint for open-source (OSS) Cluster API.
Can only be enabled if OSS Cluster API support is enabled. Default: 'false'
* `client_ssl_certificate` - (Optional) SSL certificate to authenticate user connections
* `periodic_backup_path` - (Optional) Path that will be used to store database backup files
* `replica_of` - (Optional) Set of Redis database URIs, in the format `redis://user:password@host:port`, that this
database will be a replica of. If the URI provided is Redis Labs Cloud instance, only host and port should be provided.
Cannot be enabled when `support_oss_cluster_api` is enabled.
* `module` - (Optional) A module object, documented below
* `alert` - (Optional) Set of alerts to enable on the database, documented below
* `data_persistence` - (Optional) Rate of database data persistence (in persistent storage). Default: ‘none’
* `data_eviction` - (Optional) The data items eviction policy (either: 'allkeys-lru', 'allkeys-lfu', 'allkeys-random', 'volatile-lru', 'volatile-lfu', 'volatile-random', 'volatile-ttl' or 'noeviction'. Default: 'volatile-lru')
* `password` - (Required) Password used to access the database
* `replication` - (Optional) Databases replication. Default: ‘true’
* `modules` - (Optional) A list of modules.
* `replication` - (Required) Databases replication.
* `throughput_measurement_by` - (Required) Throughput measurement method, (either ‘number-of-shards’ or ‘operations-per-second’)
* `throughput_measurement_value` - (Required) Throughput value (as applies to selected measurement method)
* `average_item_size_in_bytes` - (Optional) Relevant only to ram-and-flash clusters. Estimated average size (measured in bytes)
of the items stored in the database. Default: 1000
* `source_ips` - (Optional) Set of CIDR addresses to allow access to the database. Defaults to allowing traffic.
* `hashing_policy` - (Optional) List of regular expression rules to shard the database by. See
[the documentation on clustering](https://docs.redislabs.com/latest/rc/concepts/clustering/) for more information on the
hashing policy. This cannot be set when `support_oss_cluster_api` is set to true.
of the items stored in the database. Default: 0

The cloud_provider `region` block supports:

Expand All @@ -198,19 +110,6 @@ The cloud_provider `region` block supports:
* `networking_vpc_id` - (Optional) Either an existing VPC Id (already exists in the specific region) or create a new VPC
(if no VPC is specified). VPC Identifier must be in a valid format (for example: ‘vpc-0125be68a4625884ad’) and existing
within the hosting account.
* `preferred_availability_zones` - (Required) Availability zones deployment preferences (for the selected provider & region).

~> **Note:** The preferred_availability_zones parameter is required for Terraform, but is optional within the Redis Enterprise Cloud UI.
This difference in behaviour is to guarantee that a plan after an apply does not generate differences.

The database `alert` block supports:

* `name` (Required) Alert name
* `value` (Required) Alert value

The database `module` block supports:

* `name` (Required) Name of the module to enable

### Timeouts

Expand All @@ -222,12 +121,6 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d

## Attribute reference

The `database` block has these attributes:

* `db_id` - Identifier of the database created
* `public_endpoint` - Public endpoint to access the database
* `private_endpoint` - Private endpoint to access the database

The `region` block has these attributes:

* `networks` - List of generated network configuration
Expand All @@ -245,3 +138,5 @@ The `networks` block has these attributes:
```
$ terraform import rediscloud_subscription.example 12345678
```

~> **Note:** the creation_plan block will be ignored during imports.
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/bflad/tfproviderlint v0.27.1
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/stretchr/testify v1.7.1
golang.org/x/tools v0.0.0-20201124005743-911501bfb504 // indirect
)

Expand All @@ -24,7 +23,6 @@ require (
github.com/armon/go-radix v1.0.0 // indirect
github.com/avast/retry-go v3.0.0+incompatible // indirect
github.com/aws/aws-sdk-go v1.37.0 // indirect
github.com/bflad/gopaniccheck v0.1.0 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -74,7 +72,6 @@ require (
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/posener/complete v1.2.1 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
Expand All @@ -97,5 +94,4 @@ require (
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect
google.golang.org/grpc v1.32.0 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3A
github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.37.0 h1:GzFnhOIsrGyQ69s7VgqtrG2BG8v7X7vwB3Xpbd/DBBk=
github.com/aws/aws-sdk-go v1.37.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/bflad/gopaniccheck v0.1.0 h1:tJftp+bv42ouERmUMWLoUn/5bi/iQZjHPznM00cP/bU=
github.com/bflad/gopaniccheck v0.1.0/go.mod h1:ZCj2vSr7EqVeDaqVsWN4n2MwdROx1YL+LFo47TSWtsA=
github.com/bflad/tfproviderlint v0.27.1 h1:sYlc6R8cQ0NtaCCA7Oh1ld8xfn0oiwn6mm4unooi2fo=
github.com/bflad/tfproviderlint v0.27.1/go.mod h1:7Z9Pyl1Z1UWJcPBuyjN89D2NaJGpjReQb5NoaaQCthQ=
Expand Down Expand Up @@ -198,7 +197,6 @@ github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBM
github.com/hashicorp/go-getter v1.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY=
github.com/hashicorp/go-getter v1.5.0/go.mod h1:a7z7NPPfNQpJWcn4rSWFtdrSldqLdLPEF3d8nFMsSLM=
github.com/hashicorp/go-getter v1.5.2/go.mod h1:orNH3BTYLu/fIxGIdLjLoAJHWMDQ/UKQr5O4m3iBuoo=
github.com/hashicorp/go-getter v1.5.3 h1:NF5+zOlQegim+w/EUhSLh6QhXHmZMEeHLQzllkQ3ROU=
github.com/hashicorp/go-getter v1.5.3/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI=
github.com/hashicorp/go-getter v1.5.11 h1:wioTuNmaBU3IE9vdFtFMcmZWj0QzLc6DYaP6sNe5onY=
github.com/hashicorp/go-getter v1.5.11/go.mod h1:9i48BP6wpWweI/0/+FBjqLrp9S8XtwUGjiu0QkWHEaY=
Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func New(version string) func() *schema.Provider {
ResourcesMap: map[string]*schema.Resource{
"rediscloud_cloud_account": resourceRedisCloudCloudAccount(),
"rediscloud_subscription": resourceRedisCloudSubscription(),
"rediscloud_database": resourceRedisCloudDatabase(),
"rediscloud_subscription_peering": resourceRedisCloudSubscriptionPeering(),
},
}
Expand Down
Loading

0 comments on commit 39a3652

Please sign in to comment.