Skip to content

Commit

Permalink
Merge pull request #53 from jbraiuka/ebsProviderValidation
Browse files Browse the repository at this point in the history
Add provider variable to kms encryption keys, fix cluster tags
  • Loading branch information
jordanbraiuka authored Sep 30, 2020
2 parents 0643479 + 35fd667 commit fa89005
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 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.5.0
VERSION=v1.6.0

.PHONY: install clean all build test testacc

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,13 @@ Property | Description | Default
key_id|Internal ID of the KMS encryption key. Can be found via GET to `https://api.instaclustr.com/provisioning/v1/encryption-keys`|""
alias|KMS key alias, a human-readibly identifier specified alongside your KMS ARN|""
arn|KMS ARN, identifier specifying provider, location and key in a ':' value seperated string|""
key_provider|For customers running in their own account. Value specifying the provider account’s name, similar to `instaclustr_cluster.cluster_provider.account_name`|INSTACLUSTR

#### Example
```
resource "instaclustr_encryption_key" "example_encryption_key" {
alias: "virginia 1"
arn: "arn:aws:kms:us-east-1:123456789012:key12345678-1234-1234-1234-123456789abc"
alias = "virginia 1"
arn = "arn:aws:kms:us-east-1:123456789012:key12345678-1234-1234-1234-123456789abc"
}
```

Expand Down
6 changes: 5 additions & 1 deletion examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ provider "instaclustr" {
resource "instaclustr_encryption_key" "add_ebs_key" {
alias = "testkey"
arn = "<Your KMS key ARN here>"
provider = "INSTACLUSTR"
}

resource "instaclustr_cluster" "example2" {
Expand All @@ -18,6 +19,9 @@ resource "instaclustr_cluster" "example2" {
cluster_provider = {
name = "AWS_VPC",
disk_encryption_key = "${instaclustr_encryption_key.add_ebs_key.key_id}"
tags = {
"myTag" = "myTagValue"
}
}
rack_allocation = {
number_of_racks = 3
Expand Down Expand Up @@ -231,4 +235,4 @@ resource "instaclustr_cluster" "example-redis" {
replica_nodes = 3
}
}
}
}
11 changes: 7 additions & 4 deletions instaclustr/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ func resourceCluster() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"tags": {
Type: schema.TypeString,
Optional: true,
},
"resource_group": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -108,6 +104,11 @@ func resourceCluster() *schema.Resource {
},
},

"tags": {
Type: schema.TypeMap,
Optional: true,
},

"rack_allocation": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -299,6 +300,8 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error {
return err
}

clusterProvider.Tags = d.Get("tags").(map[string]interface{})

createData := CreateRequest{
ClusterName: d.Get("cluster_name").(string),
Bundles: bundles,
Expand Down
7 changes: 7 additions & 0 deletions instaclustr/resource_encryption_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func resourceEncryptionKey() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"key_provider": {
Type: schema.TypeString,
Optional: true,
Default: "INSTACLUSTR",
},
},
}
}
Expand All @@ -39,6 +44,7 @@ func resourceEncryptionKeyCreate(d *schema.ResourceData, meta interface{}) error
createData := EncryptionKey{
Alias: d.Get("alias").(string),
ARN: d.Get("arn").(string),
Provider: d.Get("key_provider").(string),
}

var jsonStr []byte
Expand Down Expand Up @@ -70,6 +76,7 @@ func resourceEncryptionKeyRead(d *schema.ResourceData, meta interface{}) error {
d.Set("key_id", keyResource.ID)
d.Set("alias", keyResource.Alias)
d.Set("arn", keyResource.ARN)
d.Set("key_provider", keyResource.Provider)
log.Printf("[INFO] Read encyption key %s.", id)
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion instaclustr/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type ClusterProvider struct {
Name *string `json:"name" mapstructure:"name"`
AccountName *string `json:"accountName, omitempty" mapstructure:"account_name"`
CustomVirtualNetworkId *string `json:"customVirtualNetworkId, omitempty" mapstructure:"custom_virtual_network_id"`
Tags *string `json:"tags,omitempty" mapstructure:"tags"`
Tags map[string]interface{} `json:"tags,omitempty"`
ResourceGroup *string `json:"resourceGroup,omitempty" mapstructure:"resource_group"`
DiskEncryptionKey *string `json:"diskEncryptionKey,omitempty" mapstructure:"disk_encryption_key"`
}
Expand Down Expand Up @@ -155,6 +155,7 @@ type EncryptionKey struct {
ID string `json:"id,omitempty"`
Alias string `json:"alias,omitempty"`
ARN string `json:"arn,omitempty"`
Provider string `json:"provider,omitempty"`
}

type CreateKafkaUserRequest struct {
Expand Down
1 change: 1 addition & 0 deletions test/data/valid_encryption_key.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ provider "instaclustr" {
resource "instaclustr_encryption_key" "valid" {
alias = "ic_test_key"
arn = "%s"
key_provider = "INSTACLUSTR"
}

0 comments on commit fa89005

Please sign in to comment.