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

Sync common code with sw broker, initial doc updates #2

Merged
merged 1 commit into from
Oct 27, 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
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ We'd love for you to contribute and welcome your help. Here are some guidelines

## <a name="issue"></a> Did you find a issue?

- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/SolaceProducts/pubsubplus-kubernetes-quickstart/issues).
- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/SolaceProducts/terraform-provider-solacebrokerappliance/issues).

- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/SolaceProducts/pubsubplus-kubernetes-quickstart/issues). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/SolaceProducts/terraform-provider-solacebrokerappliance/issues). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.

## <a name="submitting"></a> Did you write a patch that fixes a bug?

Open a new GitHub pull request with the patch following the steps outlined below. Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.

Before you submit your pull request consider the following guidelines:

- Search [GitHub](/https://github.com/SolaceProducts/pubsubplus-kubernetes-quickstart/pulls) for an open or closed Pull Request
- Search [GitHub](/https://github.com/SolaceProducts/terraform-provider-solacebrokerappliance/pulls) for an open or closed Pull Request
that relates to your submission. You don't want to duplicate effort.

### Submitting a Pull Request
Expand All @@ -32,7 +32,7 @@ Fork the project and clone your fork
locally.

```sh
prompt:~$ git clone https://github.com/SolaceProducts/pubsubplus-kubernetes-quickstart
prompt:~$ git clone https://github.com/SolaceProducts/terraform-provider-solacebrokerappliance
```

#### Step 2: Branch
Expand Down Expand Up @@ -61,7 +61,7 @@ repository.
If you have not set the upstream, do so as follows:

```sh
prompt:~$ git remote add upstream https://github.com/SolaceProducts/pubsubplus-kubernetes-quickstart
prompt:~$ git remote add upstream https://github.com/SolaceProducts/terraform-provider-solacebrokerappliance
```

then:
Expand Down Expand Up @@ -108,7 +108,7 @@ That's it! Thank you for your contribution!

## <a name="features"></a> **Do you have an ideas for a new feature or a change to an existing one?**

- Open a GitHub [enhancement request issue](https://github.com/SolaceProducts/pubsubplus-kubernetes-quickstart/issues) and describe the new functionality.
- Open a GitHub [enhancement request issue](https://github.com/SolaceProducts/terraform-provider-solacebrokerappliance/issues) and describe the new functionality.

## <a name="questions"></a> Do you have questions about the source code?

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2023 Solace Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ test: ## Run unit tests

.PHONY:
test-coverage: ## Run tests with coverage
mkdir -p reports
@mkdir -p reports
@go test -short -coverprofile reports/cover.out ${PKG_LIST}
@go tool cover -html reports/cover.out -o reports/cover.html

.PHONY: testacc
testacc: # Run acceptance tests
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m
testacc: ## Run acceptance tests
@TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m

.PHONY:
generate-docs: dep ## Build the binary file
Expand Down
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
# Terraform provider for Solace PubSub+ Software Event Broker
# Terraform Provider for Solace PubSub+ Event Broker Appliance
[![Actions Status](https://github.com/SolaceProducts/terraform-provider-solacebroker/actions/workflows/core-pipeline-main-branch-only.yml/badge.svg?branch=main)](https://github.com/SolaceProducts/terraform-provider-solacebroker/actions?query=workflow:%22Test+Provider%22+branch:main)
[![Go Report Card](https://goreportcard.com/badge/github.com/solaceproducts/terraform-provider-solacebroker)](https://goreportcard.com/report/github.com/solaceproducts/terraform-provider-solacebroker)

This provider is a plugin for Terraform that allows for the configuration of the PubSub+ Software Event Broker and it is maintained by Solace.

This provider, maintained by Solace, is a plugin for Terraform that enables you to configure PubSub+ Event Broker Appliances.

The provider is available from the [Terraform Providers Registry](https://registry.terraform.io/providers/solaceproducts/solacebroker/latest).

The minimum required PubSub+ Event Broker Appliance version is 10.4.

## Quick Start

1. Ensure you have admin access to a Solace PubSub+ Software Event Broker. Options include [locally deployment of a containerized version](https://docs.solace.com/Software-Broker/SW-Broker-Set-Up/Containers/Set-Up-Container-Image.htm) or use of a free broker from [PubSub+ Cloud](https://docs.solace.com/Cloud/cloud-lp.htm).
1. Ensure you have admin access to a Solace PubSub+ Event Broker Appliance.
2. Install the [Terraform CLI](https://www.terraform.io/downloads)
3. Create the [`examples/sampleconfig.tf`](examples/sampleconfig.tf) sample file in a new directory, adjust `url`, and the management credential parameters `username` and `password` to your broker's setup.
4. From this directory run `terraform plan`, then `terraform apply`.
5. Open the `url` link in your browser to access the broker's web managment UI. The creadentials are the same as used in the Terraform config. Observe the new objects created: a new message-vpn and a messaging queue under that message-vpn.
6. Run `terraform delete` from your command line and observe the message-vpn deleted.
3. Create the [`examples/sampleconfig.tf`](examples/sampleconfig.tf) sample file in a new directory, adjust the `url`, and the management credential parameters `username` and `password` to your broker's setup.
4. From this directory run `terraform plan`, then `terraform apply` (if prompted, `terraform init` may also be required).
5. Open the `url` link in your browser to access the broker's web management UI. The credentials are the same as used in the Terraform config. Observe the new objects created: a new Message VPN and a messaging queue under that Message VPN.
6. Run `terraform destroy` from your command line and observe that the Message VPN is deleted.

Note that the provider also offers the unique functionality of generating a config file from an already configured broker. Refer to the documentation for more details on that.
Note that the provider also offers the unique ability to generate a config file from an already configured broker. For more information, refer to the [full documentation](https://registry.terraform.io/providers/SolaceProducts/solacebroker/latest/docs).

## Documentation

Full documentation is available on the [Terraform Providers Registry website](https://registry.terraform.io/providers/confluentinc/confluent/latest/docs).
Full documentation is available on the [Terraform Providers Registry website](https://registry.terraform.io/providers/solaceproducts/solacebroker/latest/docs).

It is recommended to familiarize yourself with Solace technology and broker management, refer to the [Resources section](#resources).

Expand All @@ -31,20 +36,20 @@ It is recommended to familiarize yourself with Solace technology and broker mana

### Building

1. `git clone` this repository and `cd` into its directory
1. `git clone` this repository and `cd` into its directory.
2. `make install` will trigger the Golang build of the provider in your [`${GOBIN}`](https://pkg.go.dev/cmd/go#hdr-Compile_and_install_packages_and_dependencies) (defaults to `${GOPATH}/bin` or `${HOME}/go/bin` if `${GOPATH}` is not set). Repeat
this every time you make changes to the provider locally.

The provided `makefile` defines additional commands generally useful during development.
The provided `makefile` defines additional commands that are useful during development.

### Using a development build
### Using a Development Build

Create or update your `${HOME}/.terraformrc` (Unix) / `%APPDATA%\terraform.rc` (Windows) configuration with a `provider_installation` section that contains the following `dev_overrides`:

```hcl
provider_installation {
dev_overrides {
"hashicorp/random" = "${GOBIN}" //< replace `${GOBIN}` with the actual path on your system
"registry.terraform.io/solaceproducts/solacebroker" = "${GOBIN}" //< replace `${GOBIN}` with the actual path on your system
}

direct {}
Expand Down
2 changes: 1 addition & 1 deletion cmd/broker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"net/http/cookiejar"
"os"
"strings"
terraform "terraform-provider-solacebroker/cmd/command"
"terraform-provider-solacebroker/cmd/command"
"terraform-provider-solacebroker/internal/broker"
"terraform-provider-solacebroker/internal/semp"
"time"
Expand Down
10 changes: 2 additions & 8 deletions cmd/command/configgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ import (
"context"
"errors"
"fmt"
"golang.org/x/exp/slices"
"net/http"
"os"
"regexp"
"strings"
internalbroker "terraform-provider-solacebroker/internal/broker"
"terraform-provider-solacebroker/internal/broker/generated"
"terraform-provider-solacebroker/internal/semp"

"golang.org/x/exp/slices"
)

type BrokerObjectType string
Expand Down Expand Up @@ -211,16 +210,11 @@ func GetNameForResource(resourceTerraformName string, attributeResourceTerraform
}
if found {
//sanitize name
value = strings.ReplaceAll(value, " ", "_")
value = strings.ReplaceAll(value, "#", "_")
value = strings.ReplaceAll(value, "\\", "_")
value = strings.ReplaceAll(value, "/", "_")
value = strings.ReplaceAll(value, "\"", "")
resourceName = "_" + value
}
}
}
}
}
return resourceName
return SanitizeHclIdentifierName(resourceName)
}
9 changes: 9 additions & 0 deletions cmd/command/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,12 @@ func hclFormatResource(resourceConfig ResourceConfig) string {
config := b.String()
return config
}

func SanitizeHclIdentifierName(name string) string {
name = regexp.MustCompile(`[^a-zA-Z0-9 ]+`).ReplaceAllString(strings.TrimSpace(name), "_")
if len(name) == 0 || (name[0] >= '0' && name[0] <= '9') || (len(name) == 1 && name[0] == '_') {
//just prepend static string to avoid checking all characters
name = "gn_" + name
}
return name
}
64 changes: 64 additions & 0 deletions cmd/command/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,67 @@ func Test_newAttributeInfo(t *testing.T) {
})
}
}

func TestSanitizeHclIdentifierName(t *testing.T) {
type args struct {
name string
}
tests := []struct {
name string
args args
want string
}{
{
"SanitizeTextStartingWithNumber",
args{name: "1testing"},
"gn_1testing",
},
{
"SanitizeTextContainingSpecialCharacters",
args{name: "*testing*"},
"_testing_",
},
{
"SanitizeTextContainingSpecialCharactersTwo",
args{name: "#testing/"},
"_testing_",
},
{
"SanitizeTextContainingSpecialCharactersThree",
args{name: "$testing\""},
"_testing_",
},
{
"SanitizeTextContainingSpecialCharactersFour",
args{name: "%testing^"},
"_testing_",
},
{
"SanitizeTextContainingSpecialCharactersFive",
args{name: "%testing^"},
"_testing_",
},
{
"SanitizeTextEmpty",
args{name: ""},
"gn_",
},
{
"SanitizeTextContainingEmpty",
args{name: " "},
"gn_",
},
{
"SanitizeTextOnlySpecialCharacter",
args{name: "#"},
"gn__",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SanitizeHclIdentifierName(tt.args.name); got != tt.want {
t.Errorf("SanitizeHclIdentifierName() = %v, want %v", got, tt.want)
}
})
}
}
5 changes: 3 additions & 2 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ This command would create a file my-messagevpn.tf that contains a resource defin
}
providerSpecificIdentifier := cmd.Flags().Arg(1)
if len(providerSpecificIdentifier) == 0 {
command.LogCLIError("Broker object not provided")
command.LogCLIError("Broker object not provided")
_ = cmd.Help()
os.Exit(1)
}
Expand Down Expand Up @@ -108,7 +108,8 @@ This command would create a file my-messagevpn.tf that contains a resource defin
brokerObjectInstanceName := strings.ToLower(brokerObjectType)
if strings.Contains(brokerObjectType, ".") {
brokerObjectTypeName = strings.Split(brokerObjectType, ".")[0]
brokerObjectInstanceName = strings.Split(brokerObjectType, ".")[1]
//sanitize name
brokerObjectInstanceName = command.SanitizeHclIdentifierName(strings.Split(brokerObjectType, ".")[1])
}

brokerObjectTerraformName := strings.ReplaceAll(brokerObjectTypeName, "solacebroker_", "")
Expand Down
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
package cmd

import (
terraform "terraform-provider-solacebroker/cmd/command"

"github.com/spf13/cobra"
terraform "terraform-provider-solacebroker/cmd/command"
)

var rootCmd = &cobra.Command{
Expand Down
Loading