Skip to content
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

feat: Initial dynamodb-ns implementation #800

Merged
merged 3 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions aws-dynamodb-namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2023 VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
version: 1
name: csb-aws-dynamodb-namespace
id: 07d06aeb-f87a-4e06-90ae-0b07a8c21a02
description: CSB Amazon DynamoDB Namespace
display_name: CSB Amazon DynamoDB Namespace
image_url: file://service-images/csb.png
documentation_url: https://docs.vmware.com/en/Tanzu-Cloud-Service-Broker-for-AWS/1.5/csb-aws/GUID-reference-aws-dynamodb-namespace.html
provider_display_name: VMware
support_url: https://aws.amazon.com/dynamodb/
tags: [aws, dynamodb, namespace]
plan_updateable: true
plans:
- name: default
id: 73b55e9a-4cdd-4d6f-81bd-c34d5c27a086
description: "A DynamoDB Namespace"
display_name: "dynamodb namespace"
provision:
template_refs:
outputs: terraform/dynamodb-namespace/provision/outputs.tf
variables: terraform/dynamodb-namespace/provision/variables.tf
computed_inputs:
- name: prefix
type: string
details: Prefix for the DynamoDB table names
default: csb-${request.instance_id}
- name: region
type: string
details: Region for the DynamoDB tables
default: ${region}
outputs:
- field_name: prefix
type: string
details: Prefix for the DynamoDB table names
- field_name: region
type: string
details: Region for the DynamoDB tables
bind:
plan_inputs: []
user_inputs: []
computed_inputs: []
template_refs: {}
outputs: []
1 change: 1 addition & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ service_definitions:
- aws-postgresql.yml
- aws-s3-bucket.yml
- aws-dynamodb.yml
- aws-dynamodb-namespace.yml
- aws-aurora-postgresql.yml
- aws-aurora-mysql.yml

Expand Down
45 changes: 45 additions & 0 deletions terraform-tests/dynamodb_namespace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package terraformtests

import (
"path"

tfjson "github.com/hashicorp/terraform-json"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "csbbrokerpakaws/terraform-tests/helpers"
)

var _ = Describe("dynamodb-namespace", Label("dynamodb-ns-terraform"), Ordered, func() {
var (
plan tfjson.Plan
terraformProvisionDir string
)

defaultVars := map[string]any{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the Ginkgo docs:

Information is shared between closures via closure variables. It is idiomatic for these closure variables to be declared within the container node closure and initialized in the setup node closure. Doing so ensures that each spec has a pristine, correctly initialized, copy of the shared variable.

Initialising a non-const outside of a BeforeEach() can lead to subtle issues that are hard to debug as if one testcase alters the value, another testcase will the the altered value and not the original (expected) value. Because testcases run in random order, these issues take ages to debug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On seconds thoughts, this is an ordered test with a BeforeAll() rather than a BeforeEach(), so while the above point is true, the risk is lower as the tests are not randomised.

"region": "fake-region",
"prefix": "csb-fake-5368-489c-9f18-b53140316fb2",
}

BeforeAll(func() {
terraformProvisionDir = path.Join(workingDir, "dynamodb-namespace/provision")
Init(terraformProvisionDir)
})

Context("default provisioning", func() {
BeforeAll(func() {
plan = ShowPlan(terraformProvisionDir, buildVars(defaultVars, map[string]any{}))
})

It("should not create any resources", func() {
Expect(plan.ResourceChanges).To(BeEmpty())
})

It("should pass through the parameters", func() {
Expect(plan.OutputChanges).To(HaveKeyWithValue("region", BeAssignableToTypeOf(&tfjson.Change{})))
Expect(plan.OutputChanges).To(HaveKeyWithValue("prefix", BeAssignableToTypeOf(&tfjson.Change{})))
Expect(plan.OutputChanges["region"].After).To(Equal("fake-region"))
Expect(plan.OutputChanges["prefix"].After).To(Equal("csb-fake-5368-489c-9f18-b53140316fb2"))
})
})
})
16 changes: 16 additions & 0 deletions terraform/dynamodb-namespace/provision/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

output "region" { value = var.region }
output "prefix" { value = var.prefix }
16 changes: 16 additions & 0 deletions terraform/dynamodb-namespace/provision/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

variable "prefix" { type = string }
variable "region" { type = string }