Skip to content

Commit

Permalink
Add redis support (#48)
Browse files Browse the repository at this point in the history
* Added Redis capabilities to Terraform

* Updated Readme and examples to include Redis

* Allowed upper/lowercase bundle types.

* Updated makefile version
  • Loading branch information
Mitchel-Stig-Instaclustr authored Sep 3, 2020
1 parent f6084b7 commit 9d114e0
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BIN_NAME="terraform-provider-instaclustr"
VERSION=v1.3.1
VERSION=v1.4.0

.PHONY: install clean all build test testacc

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ cluster_network|The private network address block for the cluster specified usin
private_network_cluster|Accepts true/false. Creates the cluster with private network only.|false
pci_compliant_cluster|Accepts true/false. Creates the cluster with PCI compliance enabled.|false
cluster_provider|The information of infrastructure provider. See below for its properties.|Required
rack_allocation|The number of resources to use. See below for its properties.|Required
rack_allocation|The number of resources to use. See below for its properties.|Optional, but Required for all Bundle types excluding Redis.
bundle|Array of bundle information. See below for its properties.|Required

`cluster_provider`
Expand Down Expand Up @@ -144,7 +144,7 @@ options|Options and add-ons for the given bundle. See `bundle.options` below for
Property | Description | For Bundles | Default
---------|-------------|-------------|--------
auth_n_authz|Accepts true/false. Enables Password Authentication and User Authorization.|Cassandra|false
client_encryption|Accepts true/false. Enables Client ⇄ Node Encryption.|Cassandra, Kafka, Elasticsearch, Spark|false
client_encryption|Accepts true/false. Enables Client ⇄ Node Encryption.|Cassandra, Kafka, Elasticsearch, Spark, Redis|false
dedicated_master_nodes|Accepts true/false. Enables Dedicated Master Nodes.|Elasticsearch|false
master_node_size|Desired master node size. See [here](https://www.instaclustr.com/support/api-integrations/api-reference/provisioning-api/#section-reference-data-data-centres-and-node-sizes) for more details.|Elasticsearch|Required
security_plugin|Accepts true/false. Enables Security Plugin. This option gives an extra layer of security to the cluster. This will automatically enable internode encryption.|Elasticsearch|false
Expand All @@ -161,6 +161,8 @@ aws_access_key, aws_secret_key, s3_bucket_name|Access information for the S3 buc
azure_storage_account_name, azure_storage_account_key, azure_storage_container_name|Access information for the Azure Storage container where you will store your custom connectors.|Kafka Connect
ssl_enabled_protocols, ssl_truststore_password, ssl_protocol, security_protocol, sasl_mechanism, sasl_jaas_config, bootstrap_servers|Connection information for your Kafka Cluster. These options are analogous to the similarly named options that you would place in your Kafka Connect worker.properties file. Only required if connecting to a Non-Instaclustr managed Kafka Cluster|Kafka Connect
truststore|Base64 encoded version of the TLS trust store (in JKS format) used to connect to your Kafka Cluster. Only required if connecting to a Non-Instaclustr managed Kafka Cluster with TLS enabled|Kafka Connect
master_nodes|The number of Master nodes in a generated Redis Cluster.|Redis|Required (Integers)
replica_nodes|The number of Replica nodes in a generated Redis Cluster.|Redis|Required (Integers)

### Resource: `instaclustr_firewall_rule`
A resource for managing cluster firewall rules on Instaclustr Managed Platform. A firewall rule allows access to your Instaclustr cluster.
Expand Down Expand Up @@ -289,6 +291,7 @@ KAFKA_REST_PROXY|5.0.0|KAFKA
KAFKA_SCHEMA_REGISTRY|5.0.0|KAFKA
ELASTICSEARCH|opendistro-for-elasticsearch:1.4.0
KAFKA_CONNECT|2.3.1, 2.4.1|
REDIS|6.0.4|

### Migrating from 0.0.1 → 1.0.0+
A schema change has been made from 0.0.1 which no longer supports the `bundles` argument and uses `bundle` blocks instead. This change can cause `terraform apply` to fail with a message that `bundles` has been removed and/or updating isn't supported. To resolve this -<br>
Expand Down
20 changes: 20 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,24 @@ resource "instaclustr_cluster" "private_cluster_example" {
bundle = "APACHE_CASSANDRA"
version = "3.11.4"
}
}

resource "instaclustr_cluster" "example-redis" {
cluster_name = "testcluster"
node_size = "t3.small-20-r"
data_centre = "US_WEST_2"
sla_tier = "NON_PRODUCTION"
cluster_network = "192.168.0.0/18"
cluster_provider = {
name = "AWS_VPC"
}

bundle {
bundle = "REDIS"
version = "6.0.4"
options = {
master_nodes = 3,
replica_nodes = 3
}
}
}
44 changes: 36 additions & 8 deletions instaclustr/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func resourceCluster() *schema.Resource {

"rack_allocation": {
Type: schema.TypeMap,
Required: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"number_of_racks": {
Expand Down Expand Up @@ -254,6 +254,14 @@ func resourceCluster() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"master_nodes": {
Type: schema.TypeInt,
Optional: true,
},
"replica_nodes": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
Expand All @@ -279,12 +287,6 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error {
return err
}

var rackAllocation RackAllocation
err = mapstructure.Decode(d.Get("rack_allocation").(map[string]interface{}), &rackAllocation)
if err != nil {
return err
}

createData := CreateRequest{
ClusterName: d.Get("cluster_name").(string),
Bundles: bundles,
Expand All @@ -295,7 +297,17 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error {
ClusterNetwork: d.Get("cluster_network").(string),
PrivateNetworkCluster: fmt.Sprintf("%v", d.Get("private_network_cluster")),
PCICompliantCluster: fmt.Sprintf("%v", d.Get("pci_compliant_cluster")),
RackAllocation: rackAllocation,
}

// Some Bundles do not use Rack Allocation so add that separately if needed. (Redis for example)
if checkIfBundleRequiresRackAllocation(bundles) {
var rackAllocation RackAllocation
err = mapstructure.Decode(d.Get("rack_allocation").(map[string]interface{}), &rackAllocation)
if err != nil {
return err
}

createData.RackAllocation = &rackAllocation
}

var jsonStr []byte
Expand Down Expand Up @@ -421,3 +433,19 @@ func getBundles(d *schema.ResourceData) ([]Bundle, error) {
func formatCreateErrMsg(err error) error {
return fmt.Errorf("[Error] Error creating cluster: %s", err)
}

func checkIfBundleRequiresRackAllocation(bundles []Bundle) bool {
var noRackAllocationBundles = []string{
"REDIS",
}

for i := 0; i < len(bundles); i++ {
for j := 0; j < len(noRackAllocationBundles); j++ {
if strings.ToLower(bundles[i].Bundle) == strings.ToLower(noRackAllocationBundles[j]) {
return false
}
}
}

return true
}
20 changes: 11 additions & 9 deletions instaclustr/structs.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package instaclustr

type FirewallRule struct {
Network string `json:"network,omitempty"`
Network string `json:"network,omitempty"`
SecurityGroupId string `json:"securityGroupId,omitempty"`
Rules []RuleType `json:"rules"`
Rules []RuleType `json:"rules"`
}

type RuleType struct {
Expand Down Expand Up @@ -45,6 +45,8 @@ type BundleOptions struct {
SaslJaasConfig string `json:"sasl.jaas.config,omitempty" mapstructure:"sasl_jaas_config"`
BootstrapServers string `json:"bootstrap.servers,omitempty" mapstructure:"bootstrap_servers"`
Truststore string `json:"truststore,omitempty" mapstructure:"truststore"`
RedisMasterNodes string `json:"masterNodes,omitempty" mapstructure:"master_nodes"`
RedisReplicaNodes string `json:"replicaNodes,omitempty" mapstructure:"replica_nodes"`
}

type ClusterProvider struct {
Expand All @@ -71,7 +73,7 @@ type CreateRequest struct {
ClusterNetwork string `json:"clusterNetwork"`
PrivateNetworkCluster string `json:"privateNetworkCluster"`
PCICompliantCluster string `json:"pciCompliantCluster"`
RackAllocation RackAllocation `json:"rackAllocation"`
RackAllocation *RackAllocation `json:"rackAllocation,omitempty"`
}

type Cluster struct {
Expand Down Expand Up @@ -153,16 +155,16 @@ type EncryptionKey struct {
}

type CreateKafkaUserRequest struct {
Username string `json:"username"`
Password string `json:"password"`
InitialPermissions string `json:"initial-permissions"`
Username string `json:"username"`
Password string `json:"password"`
InitialPermissions string `json:"initial-permissions"`
}

type UpdateKafkaUserRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username"`
Password string `json:"password"`
}

type DeleteKafkaUserRequest struct {
Username string `json:"username"`
Username string `json:"username"`
}
25 changes: 25 additions & 0 deletions test/data/valid_redis_cluster_create.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
provider "instaclustr" {
username = "%s"
api_key = "%s"
}

resource "instaclustr_cluster" "validRedis" {
cluster_name = "testcluster"
node_size = "t3.small-20-r"
data_centre = "US_WEST_2"
sla_tier = "NON_PRODUCTION"
cluster_network = "192.168.0.0/18"
cluster_provider = {
name = "AWS_VPC"
}

bundle {
bundle = "REDIS"
version = "6.0.4"
options = {
master_nodes = 3,
replica_nodes = 3
}
}
}

Loading

0 comments on commit 9d114e0

Please sign in to comment.