Skip to content

Commit

Permalink
Add Opensearch support (#147)
Browse files Browse the repository at this point in the history
* add opensearch

* update helpers, add tests

* update client

* add examples

* add project id validators + replace plan modifiers

* Automated docs update

---------

Co-authored-by: Dean Oren <deangili.oren@mail.schwarz>
Co-authored-by: do87 <do87@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 2, 2023
1 parent 794cb41 commit b8e64ab
Show file tree
Hide file tree
Showing 32 changed files with 742 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .github/files/analyze-test-output/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func getDataServiceName(testName string) string {
if strings.Contains(testName, "Postgres") {
return "postgres-dsa"
}
if strings.Contains(testName, "Opensearch") {
return "opensearch-dsa"
}
if strings.Contains(testName, "RabbitMQ") {
return "rabbitmq-dsa"
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ dummy:
quality:
@goreportcard-cli -v .

pre-commit: docs quality
pre-commit: quality
@go run .github/files/generate-acceptance-tests/main.go
@find docs -type f | sort | cat | md5 > .github/files/pre-commit-check/checksum
@cat .github/workflows/acceptance_test.yml | md5 >> .github/files/pre-commit-check/checksum
Expand Down
70 changes: 70 additions & 0 deletions docs/data-sources/opensearch_credential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_opensearch_credential Data Source - stackit"
subcategory: ""
description: |-
Manages Opensearch credentials
-> Environment support
Productionhttps://opensearch.api.eu01.stackit.cloud
QAhttps://opensearch.api.eu01.qa.stackit.cloud
Devhttps://opensearch.api.eu01.dev.stackit.cloud
By default, production is used.To set a custom URL, set an environment variable STACKITREDISBASEURL
---

# stackit_opensearch_credential (Data Source)

Manages Opensearch credentials

<br />

-> __Environment support__<br /><table style='border-collapse: separate; border-spacing: 0px; margin-top:-20px; margin-left: 24px; font-size: smaller;'>
<tr><td style='width: 100px; background: #fbfcff; border: none;'>Production</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.stackit.cloud</td></tr>
<tr><td style='background: #fbfcff; border: none;'>QA</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.qa.stackit.cloud</td></tr>
<tr><td style='background: #fbfcff; border: none;'>Dev</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.dev.stackit.cloud</td></tr>
</table><br />
<small style='margin-left: 24px; margin-top: -5px; display: inline-block;'><a href="https://registry.terraform.io/providers/SchwarzIT/stackit/latest/docs#environment">By default</a>, production is used.<br />To set a custom URL, set an environment variable <code>STACKIT_REDIS_BASEURL</code></small>

## Example Usage

```terraform
resource "stackit_opensearch_instance" "example" {
name = "example"
project_id = "example"
}
resource "stackit_opensearch_credential" "example" {
project_id = "example"
instance_id = stackit_opensearch_instance.example.id
}
data "stackit_opensearch_credential" "example" {
id = stackit_opensearch_credential.example.id
project_id = "example"
instance_id = stackit_opensearch_instance.example.id
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (String) Specifies the resource ID
- `instance_id` (String) Instance ID the credential belongs to
- `project_id` (String) Project ID the credential belongs to

### Read-Only

- `database_name` (String) Database name
- `host` (String) Credential host
- `hosts` (List of String) Credential hosts
- `password` (String, Sensitive) Credential password
- `port` (Number) Credential port
- `route_service_url` (String) Credential route_service_url
- `syslog_drain_url` (String) Credential syslog_drain_url
- `uri` (String) The instance URI
- `username` (String) Credential username


63 changes: 63 additions & 0 deletions docs/data-sources/opensearch_instance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_opensearch_instance Data Source - stackit"
subcategory: ""
description: |-
Data source for Opensearch instances
-> Environment support
Productionhttps://opensearch.api.eu01.stackit.cloud
QAhttps://opensearch.api.eu01.qa.stackit.cloud
Devhttps://opensearch.api.eu01.dev.stackit.cloud
By default, production is used.To set a custom URL, set an environment variable STACKITREDISBASEURL
---

# stackit_opensearch_instance (Data Source)

Data source for Opensearch instances

<br />

-> __Environment support__<br /><table style='border-collapse: separate; border-spacing: 0px; margin-top:-20px; margin-left: 24px; font-size: smaller;'>
<tr><td style='width: 100px; background: #fbfcff; border: none;'>Production</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.stackit.cloud</td></tr>
<tr><td style='background: #fbfcff; border: none;'>QA</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.qa.stackit.cloud</td></tr>
<tr><td style='background: #fbfcff; border: none;'>Dev</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.dev.stackit.cloud</td></tr>
</table><br />
<small style='margin-left: 24px; margin-top: -5px; display: inline-block;'><a href="https://registry.terraform.io/providers/SchwarzIT/stackit/latest/docs#environment">By default</a>, production is used.<br />To set a custom URL, set an environment variable <code>STACKIT_REDIS_BASEURL</code></small>

## Example Usage

```terraform
resource "stackit_opensearch_instance" "example" {
name = "example"
project_id = "example"
}
data "stackit_opensearch_instance" "example" {
name = "example"
project_id = "example"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) Specifies the instance name.
- `project_id` (String) The project ID.

### Read-Only

- `acl` (List of String) Access Control rules to whitelist IP addresses
- `cf_guid` (String) Cloud Foundry GUID
- `cf_organization_guid` (String) Cloud Foundry Organization GUID
- `cf_space_guid` (String) Cloud Foundry Space GUID
- `dashboard_url` (String) Dashboard URL
- `id` (String) Specifies the resource ID
- `plan` (String) The RabbitMQ Plan
- `plan_id` (String) The selected plan ID
- `version` (String) RabbitMQ version


1 change: 0 additions & 1 deletion docs/resources/kubernetes_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ resource "stackit_kubernetes_cluster" "example" {
- `kubernetes_version` (String) Kubernetes version. Allowed Options are: `1.22`, `1.23`, `1.24`, or a full version including patch (not recommended).
- `maintenance` (Attributes) A single maintenance block as defined below (see [below for nested schema](#nestedatt--maintenance))
- `node_pools` (Attributes List) One or more `node_pool` block as defined below (see [below for nested schema](#nestedatt--node_pools))
- `project_id` (String, Deprecated) this attribure is deprecated. please remove it from your terraform config and use `kubernetes_project_id` instead
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only
Expand Down
53 changes: 53 additions & 0 deletions docs/resources/opensearch_credential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_opensearch_credential Resource - stackit"
subcategory: ""
description: |-
Manages Opensearch credentials
-> Environment support
Productionhttps://opensearch.api.eu01.stackit.cloud
QAhttps://opensearch.api.eu01.qa.stackit.cloud
Devhttps://opensearch.api.eu01.dev.stackit.cloud
By default, production is used.To set a custom URL, set an environment variable STACKITREDISBASEURL
---

# stackit_opensearch_credential (Resource)

Manages Opensearch credentials

<br />

-> __Environment support__<br /><table style='border-collapse: separate; border-spacing: 0px; margin-top:-20px; margin-left: 24px; font-size: smaller;'>
<tr><td style='width: 100px; background: #fbfcff; border: none;'>Production</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.stackit.cloud</td></tr>
<tr><td style='background: #fbfcff; border: none;'>QA</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.qa.stackit.cloud</td></tr>
<tr><td style='background: #fbfcff; border: none;'>Dev</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.dev.stackit.cloud</td></tr>
</table><br />
<small style='margin-left: 24px; margin-top: -5px; display: inline-block;'><a href="https://registry.terraform.io/providers/SchwarzIT/stackit/latest/docs#environment">By default</a>, production is used.<br />To set a custom URL, set an environment variable <code>STACKIT_REDIS_BASEURL</code></small>



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `instance_id` (String) Instance ID the credential belongs to
- `project_id` (String) Project ID the credential belongs to

### Read-Only

- `database_name` (String) Database name
- `host` (String) Credential host
- `hosts` (List of String) Credential hosts
- `id` (String) Specifies the resource ID
- `password` (String, Sensitive) Credential password
- `port` (Number) Credential port
- `raw_response` (String, Sensitive) The full API response (as JSON string)
- `route_service_url` (String) Credential route_service_url
- `syslog_drain_url` (String) Credential syslog_drain_url
- `uri` (String) The instance URI
- `username` (String) Credential username


64 changes: 64 additions & 0 deletions docs/resources/opensearch_instance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_opensearch_instance Resource - stackit"
subcategory: ""
description: |-
Manages Opensearch instances
-> Environment support
Productionhttps://opensearch.api.eu01.stackit.cloud
QAhttps://opensearch.api.eu01.qa.stackit.cloud
Devhttps://opensearch.api.eu01.dev.stackit.cloud
By default, production is used.To set a custom URL, set an environment variable STACKITREDISBASEURL
---

# stackit_opensearch_instance (Resource)

Manages Opensearch instances

<br />

-> __Environment support__<br /><table style='border-collapse: separate; border-spacing: 0px; margin-top:-20px; margin-left: 24px; font-size: smaller;'>
<tr><td style='width: 100px; background: #fbfcff; border: none;'>Production</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.stackit.cloud</td></tr>
<tr><td style='background: #fbfcff; border: none;'>QA</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.qa.stackit.cloud</td></tr>
<tr><td style='background: #fbfcff; border: none;'>Dev</td><td style='background: #fbfcff; border: none;'>https://opensearch.api.eu01.dev.stackit.cloud</td></tr>
</table><br />
<small style='margin-left: 24px; margin-top: -5px; display: inline-block;'><a href="https://registry.terraform.io/providers/SchwarzIT/stackit/latest/docs#environment">By default</a>, production is used.<br />To set a custom URL, set an environment variable <code>STACKIT_REDIS_BASEURL</code></small>



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) Specifies the instance name. Changing this value requires the resource to be recreated. Changing this value requires the resource to be recreated.
- `project_id` (String) The project ID.

### Optional

- `acl` (List of String) Access Control rules to whitelist IP addresses
- `plan` (String) The Opensearch Plan. Default is `stackit-opensearch-1.4.10-single`
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))
- `version` (String) Opensearch version. Default is 2

### Read-Only

- `cf_guid` (String) Cloud Foundry GUID
- `cf_organization_guid` (String) Cloud Foundry Organization GUID
- `cf_space_guid` (String) Cloud Foundry Space GUID
- `dashboard_url` (String) Dashboard URL
- `id` (String) Specifies the resource ID
- `plan_id` (String) The selected plan ID

<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `create` (String)
- `delete` (String)
- `update` (String)


15 changes: 15 additions & 0 deletions examples/data-sources/stackit_opensearch_credential/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "stackit_opensearch_instance" "example" {
name = "example"
project_id = "example"
}

resource "stackit_opensearch_credential" "example" {
project_id = "example"
instance_id = stackit_opensearch_instance.example.id
}

data "stackit_opensearch_credential" "example" {
id = stackit_opensearch_credential.example.id
project_id = "example"
instance_id = stackit_opensearch_instance.example.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "stackit_opensearch_instance" "example" {
name = "example"
project_id = "example"
}

data "stackit_opensearch_instance" "example" {
name = "example"
project_id = "example"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "stackit_opensearch_instance" "example" {
name = "example"
project_id = "example"
}

resource "stackit_opensearch_credential" "example" {
project_id = "example"
instance_id = stackit_opensearch_instance.example.id
}
4 changes: 4 additions & 0 deletions examples/resources/stackit_opensearch_instance/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "stackit_opensearch_instance" "example" {
name = "example"
project_id = "example"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/Masterminds/semver v1.5.0
github.com/SchwarzIT/community-stackit-go-client v1.22.1
github.com/SchwarzIT/community-stackit-go-client v1.23.2
github.com/hashicorp/terraform-plugin-framework v1.2.0
github.com/hashicorp/terraform-plugin-framework-timeouts v0.3.1
github.com/hashicorp/terraform-plugin-framework-validators v0.10.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugX
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/SchwarzIT/community-stackit-go-client v1.22.0 h1:2/6xZQQRO2AZuj77euuY54GzU13EkHSAalGegB00Hc0=
github.com/SchwarzIT/community-stackit-go-client v1.22.0/go.mod h1:hlTfBNOKE1fokWE8g3KrI0AHo0SqzTKkS+LrIdhH8Qg=
github.com/SchwarzIT/community-stackit-go-client v1.22.1 h1:MdW7lzXvwfa5njfjnuIdkIeB5s4ZGQMHtZRaENG2E6I=
github.com/SchwarzIT/community-stackit-go-client v1.22.1/go.mod h1:hlTfBNOKE1fokWE8g3KrI0AHo0SqzTKkS+LrIdhH8Qg=
github.com/SchwarzIT/community-stackit-go-client v1.23.2 h1:xYoseJcPdIFYFFqSCL8e9+wHClKl3knVkHKv485nOfQ=
github.com/SchwarzIT/community-stackit-go-client v1.23.2/go.mod h1:hlTfBNOKE1fokWE8g3KrI0AHo0SqzTKkS+LrIdhH8Qg=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
Expand Down
16 changes: 11 additions & 5 deletions stackit/internal/data-sources/data-services/credential/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (d *DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp
return
}

res, err := d.client.Credentials.Get(ctx, config.ProjectID.ValueString(), config.InstanceID.ValueString(), config.ID.ValueString())
res, err := d.client.Credentials.GetCredentialByID(ctx, config.ProjectID.ValueString(), config.InstanceID.ValueString(), config.ID.ValueString())
if agg := validate.Response(res, err, "JSON200.Raw"); agg != nil {
if validate.StatusEquals(res, http.StatusNotFound) {
resp.State.RemoveResource(ctx)
Expand All @@ -33,18 +33,24 @@ func (d *DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp
// set computed fields
config.Host = types.StringValue(i.Raw.Credentials.Host)
config.Hosts = types.ListNull(types.StringType)
if len(i.Raw.Credentials.Hosts) > 0 {
if i.Raw.Credentials.Hosts != nil && len(*i.Raw.Credentials.Hosts) > 0 {
h := []attr.Value{}
for _, v := range i.Raw.Credentials.Hosts {
for _, v := range *i.Raw.Credentials.Hosts {
h = append(h, types.StringValue(v))
}
config.Hosts = types.ListValueMust(types.StringType, h)
}

config.DatabaseName = types.StringValue(i.Raw.Credentials.Name)
config.DatabaseName = types.StringValue("")
if i.Raw.Credentials.Name != nil {
config.DatabaseName = types.StringValue(*i.Raw.Credentials.Name)
}
config.Username = types.StringValue(i.Raw.Credentials.Username)
config.Password = types.StringValue(i.Raw.Credentials.Password)
config.Port = types.Int64Value(int64(i.Raw.Credentials.Port))
config.Port = types.Int64Value(0)
if i.Raw.Credentials.Port != nil {
config.Port = types.Int64Value(int64(*i.Raw.Credentials.Port))
}
config.SyslogDrainURL = types.StringValue(i.Raw.SyslogDrainUrl)
config.RouteServiceURL = types.StringValue(i.Raw.RouteServiceUrl)
config.URI = types.StringValue(i.Uri)
Expand Down
Loading

0 comments on commit b8e64ab

Please sign in to comment.