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(mnq): add nats and sqs beta resources #2127

Merged
merged 29 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e082bc3
feat(mnq): add nats beta resources
Codelax Sep 19, 2023
77aabe0
add sqs activation and credentials
Codelax Sep 21, 2023
0d6ccc0
add sqs queue resource
Codelax Sep 22, 2023
f93764e
fix AlreadyActivated test
Codelax Oct 9, 2023
18f72c8
add mnq_nats_account doc
Codelax Oct 10, 2023
75c14b5
add mnq_nats_credentials doc
Codelax Oct 10, 2023
02fc378
add mnq_sqs doc
Codelax Oct 10, 2023
780c1ce
add mnq_sqs_credentials doc
Codelax Oct 11, 2023
a079415
lint
Codelax Oct 16, 2023
226b30e
add mnq_sqs_queue doc
Codelax Oct 16, 2023
d2d869e
add mnq_sqs datasource doc
Codelax Oct 16, 2023
da9fb92
fix tests
Codelax Oct 16, 2023
c596451
add mnq sqs cassettes
Codelax Oct 16, 2023
5fd676f
fix tflint and cassette validation
Codelax Oct 16, 2023
aa5d94f
remove nats queue
Codelax Oct 16, 2023
8812c23
fix sqs queue test
Codelax Oct 16, 2023
f4895eb
lint markdown and update doc links
Codelax Oct 16, 2023
5e11c75
add datasource test cassette
Codelax Oct 17, 2023
0f46da6
fix cassette validation
Codelax Oct 17, 2023
6e2eff4
fix datasource example
Codelax Oct 17, 2023
66f3183
test mnq sqs queue with default project
Codelax Oct 17, 2023
4c5d59b
omit endpoint in mnq sqs queue default project test
Codelax Oct 17, 2023
39ff565
set sqs queue endpoint as optional with default value
Codelax Oct 17, 2023
c42c586
add missing descriptions
Codelax Oct 17, 2023
7b14dd1
improve and fix doc
Codelax Oct 17, 2023
9eb6b38
fix mnq_sqs tests, avoid getQueue if sqs is disabled
Codelax Oct 17, 2023
a36ae1c
remove commented code
Codelax Oct 17, 2023
aaf81c0
docs: fix links and add warnings to old resources
Codelax Oct 17, 2023
0f0a154
Merge branch 'master' into feat/mnq-beta
remyleone Oct 17, 2023
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
41 changes: 41 additions & 0 deletions docs/data-sources/mnq_sqs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
subcategory: "Messaging and Queuing"
page_title: "Scaleway: scaleway_mnq_sqs"
---

# scaleway_mnq_sqs

Gets information about SQS for a project

## Examples

### Basic

```hcl
// For default project
data "scaleway_mnq_sqs" "main" {}

// For specific project
data "scaleway_mnq_sqs" "for_project" {
project_id = scaleway_account_project.main.id
}
```

## Arguments Reference

The following arguments are supported:

- `region` - (Defaults to [provider](../index.md#region) `region`). The [region](../guides/regions_and_zones.md#regions) in which sqs is enabled.

- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project for which sqs is enabled.


## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the project

~> **Important:** Messaging and Queueing sqs' IDs are [regional](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{region}/{id}`, e.g. `fr-par/11111111-1111-1111-1111-111111111111`

- `endpoint` - The endpoint of the SQS service for this project.
111 changes: 15 additions & 96 deletions docs/guides/mnq_with_nats_terraform_provider.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
subcategory: "Messaging and Queuing"
page_title: "Using Scaleway Messaging and Queuing service with NATS Terraform provider"
---

Expand All @@ -7,19 +8,13 @@ page_title: "Using Scaleway Messaging and Queuing service with NATS Terraform pr
This guide shows the combination of Scaleway Messaging and Queuing configuration with to terraform NATS Jetstream
provider. Il will allow you to provision and manage NATS Jetstream resources.

At the end of this guide, you will have a running NATS server and a configured NATS CLI to interact with it.

## Prerequisites

* First, you will need to set up a new Terraform configuration file
with [Scaleway](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/mnq_namespace)
and [Jetstream provider](https://registry.terraform.io/providers/nats-io/jetstream/latest/docs/guides/setup).
## Examples

```hcl
terraform {
required_providers {
scaleway = {
source = "scaleway/scaleway"
source = "scaleway/scaleway"
}
jetstream = {
source = "nats-io/jetstream"
Expand All @@ -28,98 +23,22 @@ terraform {
}
}

provider "scaleway" {
region = "fr-par"
access_key = "<SCW_ACCESS_KEY>"
secret_key = "<SCW_SECRET_KEY>"
project_id = "<SCW_DEFAULT_PROJECT_ID>"
}
```

* Next, you should create a Messaging and Queuing namespace. Check our example below.
resource "scaleway_mnq_nats_account" "account" {}

```hcl
resource "scaleway_mnq_namespace" "main" {
name = "mnq-ns"
protocol = "nats"
resource "scaleway_mnq_nats_credentials" "creds" {
account_id = scaleway_mnq_nats_account.account.id
}
```

* Before creating your credentials, be aware that due to an
ongoing [issue](https://github.com/hashicorp/terraform/issues/516) since 2014, secrets stored in `terraform.tfstate`
remain in plain text. While there are methods to remove secrets from state files, they are unreliable and may not
function properly with updates to Terraform. It is not recommended to use these workarounds.

---

* Otherwise, the official update on December3, 2020:
Terraform 0.14 has added the ability to mark variables as sensitive, which helps keep them out of your logs, so you
should add `sensitive = true` to variables!

---

* You can create Credentials easily using the Scaleway provider.
Check our example below and more about authenticating with a Credentials
File [here](https://docs.nats.io/using-nats/developer/connecting/creds)

```hcl
resource "scaleway_mnq_credential" "main" {
name = "creds-ns"
namespace_id = scaleway_mnq_namespace.main.id
}
```

* At this point you have your Namespace and your Credential that means you have a running NATS Server ready to be used.

* Grab a copy of the [NATS CLI](https://github.com/nats-io/jetstream/releases) and configure it with your
endpoint. To be practical let's use `contexts` that you can store and easily select the relevant context. Check more
details [here](https://docs.nats.io/using-nats/nats-tools/nats_cli#configuration-contexts).

```shell
nats context save example --server nats://nats.mnq.fr-par.scw.cloud:4222 --description 'Prod.Net Server'
```

* The output should look like this:

```shell
NATS Configuration Context "example"

Description: Prod.Net Server
Server URLs: nats://nats.mnq.fr-par.scw.cloud:4222
Path: /Your/path/context/example.json
```

* Try to select your configuration using the NATS CLI:

```shell
nats context select
? Select a Context [Use arrows to move, type to filter]
> example
```

* Finally, configure the CLI with the namespace credentials.

```shell
NATS Configuration Context "example"

Description: Prod.Net Server
Server URLs: nats://nats.mnq.fr-par.scw.cloud:4222
Credentials: /Your/path/secret/admin.creds (OK)
Path: /Your/path/context/example.json
```

* You are ready to use the
NATS [JetStream Provider](https://registry.terraform.io/providers/nats-io/jetstream/latest/docs):

```hcl
resource "scaleway_mnq_credential" "main" {
# Your config
provider "jetstream" {
servers = scaleway_mnq_nats_account.account.endpoint
credential_data = scaleway_mnq_nats_credentials.creds.file
}

provider "jetstream" {
servers = scaleway_mnq_namespace.main.endpoint
credentials = "path/ngs_stream_admin.creds"
# credential_data = "<SCW_CREDENTIAL_AS_STRING>"
# credential_data = scaleway_mnq_credential.main.nats_credentials[0].content
// Use any jetstream resources
resource "jetstream_stream" "ORDERS" {
name = "ORDERS"
subjects = ["ORDERS.*"]
storage = "file"
max_age = 60 * 60 * 24 * 365
}
```
2 changes: 2 additions & 0 deletions docs/resources/mnq_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This Terraform configuration creates and manage a Scaleway MNQ credential associ
For additional details, kindly refer to our [website](https://www.scaleway.com/en/docs/serverless/messaging/) and
the [API documentation](https://developers.scaleway.com/en/products/messaging_and_queuing/api/v1alpha1/#post-67608e)

~> NOTE: This resource refers to the old version of the MNQ API. You should use new resources dedicated to your protocol. [SQS](mnq_sqs_credentials.md), [NATS](mnq_nats_credentials.md).

## Examples

### NATS credential
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/mnq_namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Creates and manages Scaleway Messaging and queuing Namespace.
For further information please check
our [documentation](https://pkg.go.dev/github.com/scaleway/scaleway-sdk-go@master/api/mnq/v1alpha1#pkg-index)

~> NOTE: This resource refers to the old version of the MNQ API. You should use new resources dedicated to your protocol. [SQS](mnq_sqs.md), [NATS](mnq_nats_account.md).


## Examples

### Basic
Expand Down
50 changes: 50 additions & 0 deletions docs/resources/mnq_nats_account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
subcategory: "Messaging and Queuing"
page_title: "Scaleway: scaleway_mnq_nats_account"
---

# scaleway_mnq_nats_account

Creates and manages Scaleway Messaging and queuing Nats Accounts.
For further information please check
our [documentation](https://www.scaleway.com/en/docs/serverless/messaging/reference-content/nats-overview/)

## Examples

### Basic

```hcl
resource "scaleway_mnq_nats_account" "main" {
name = "nats-account"
}
```

## Arguments Reference

The following arguments are supported:

- `name` - (Optional) The unique name of the nats account.

- `region` - (Defaults to [provider](../index.md#region) `region`). The [region](../guides/regions_and_zones.md#regions)
in which the account should be created.

- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the
account is associated with.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the account

~> **Important:** Messaging and Queueing nats accounts' IDs are [regional](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{region}/{id}`, e.g. `fr-par/11111111-1111-1111-1111-111111111111`

- `endpoint` - The endpoint of the NATS service for this account.

## Import

Namespaces can be imported using the `{region}/{id}`, e.g.

```bash
$ terraform import scaleway_mnq_namespace.main fr-par/11111111111111111111111111111111
```
53 changes: 53 additions & 0 deletions docs/resources/mnq_nats_credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
subcategory: "Messaging and Queuing"
page_title: "Scaleway: scaleway_mnq_nats_credentials"
---

# scaleway_mnq_nats_credentials

Creates and manages Scaleway Messaging and queuing Nats Credentials.
For further information please check
our [documentation](https://www.scaleway.com/en/docs/serverless/messaging/reference-content/nats-overview/)

## Examples

### Basic

```hcl
resource "scaleway_mnq_nats_account" "main" {
name = "nats-account"
Codelax marked this conversation as resolved.
Show resolved Hide resolved
}

resource "scaleway_mnq_nats_credentials" "main" {
account_id = scaleway_mnq_nats_account.main.id
}
```

## Arguments Reference

The following arguments are supported:

- `account_id` - (Required) The ID of the nats account the credentials are generated from

- `name` - (Optional) The unique name of the nats credentials.

- `region` - (Defaults to [provider](../index.md#region) `region`). The [region](../guides/regions_and_zones.md#regions)
in which the account exists.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the credentials

~> **Important:** Messaging and Queueing nats credentials' IDs are [regional](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{region}/{id}`, e.g. `fr-par/11111111-1111-1111-1111-111111111111`

- `file` - The content of the credentials file.

## Import

Namespaces can be imported using the `{region}/{id}`, e.g.

```bash
$ terraform import scaleway_mnq_nats_credentials.main fr-par/11111111111111111111111111111111
```
2 changes: 2 additions & 0 deletions docs/resources/mnq_queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Creates and manages Scaleway Messaging and Queuing queues.

For more information about MNQ, see [the documentation](https://www.scaleway.com/en/developers/api/messaging-and-queuing/).

~> NOTE: This resource refers to the old version of the MNQ API. You should use new resources dedicated to your protocol. [SQS](mnq_sqs_queue.md), [NATS](../guides/mnq_with_nats_terraform_provider.md).

## Examples

### NATS
Expand Down
53 changes: 53 additions & 0 deletions docs/resources/mnq_sqs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
subcategory: "Messaging and Queuing"
page_title: "Scaleway: scaleway_mnq_sqs"
---

# scaleway_mnq_sqs

Activate Scaleway Messaging and queuing SQS for a project.
For further information please check
our [documentation](https://www.scaleway.com/en/docs/serverless/messaging/reference-content/sqs-overview/)

## Examples

### Basic

```hcl
// For default project in default region
resource "scaleway_mnq_sqs" "main" {}

// For specific project in default region
resource "scaleway_mnq_sqs" "for_project" {
project_id = scaleway_account_project.main.id
}
```

## Arguments Reference

The following arguments are supported:


- `region` - (Defaults to [provider](../index.md#region) `region`). The [region](../guides/regions_and_zones.md#regions)
in which sqs will be enabled.

- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the sqs will be enabled for.


## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the project

~> **Important:** Messaging and Queueing sqs' IDs are [regional](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{region}/{id}`, e.g. `fr-par/11111111-1111-1111-1111-111111111111`

- `endpoint` - The endpoint of the SQS service for this project.

## Import

SQS status can be imported using the `{region}/{project_id}`, e.g.

```bash
$ terraform import scaleway_mnq_sqs.main fr-par/11111111111111111111111111111111
```
Loading
Loading