Skip to content

Commit

Permalink
fix(triggers): update sqs func trigger mnq api (#62)
Browse files Browse the repository at this point in the history
Co-authored-by: Miguel Escribano <mescribano@scaleway.com>
Co-authored-by: norbjd <norbjd@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 14, 2023
1 parent d4dcb23 commit 4512798
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 58 deletions.
46 changes: 17 additions & 29 deletions functions/python-sqs-trigger-async-worker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
scaleway = {
source = "scaleway/scaleway"
version = ">= 2.12"
version = ">= 2.31"
}
archive = {
source = "hashicorp/archive"
Expand Down Expand Up @@ -61,11 +61,11 @@ resource "scaleway_function" "front" {
max_scale = 1

secret_environment_variables = {
SQS_ACCESS_KEY = scaleway_mnq_credential.main.sqs_sns_credentials.0.access_key
SQS_SECRET_KEY = scaleway_mnq_credential.main.sqs_sns_credentials.0.secret_key
SQS_ENDPOINT = replace(scaleway_mnq_queue.main.sqs.0.endpoint, "{region}", scaleway_mnq_namespace.main.region)
SQS_QUEUE_URL = scaleway_mnq_queue.main.sqs.0.url
SQS_REGION = scaleway_mnq_namespace.main.region
SQS_ACCESS_KEY = scaleway_mnq_sqs_credentials.main.access_key
SQS_SECRET_KEY = scaleway_mnq_sqs_credentials.main.secret_key
SQS_ENDPOINT = replace(scaleway_mnq_sqs_queue.main.endpoint, "{region}", scaleway_mnq_sqs_queue.main.region)
SQS_QUEUE_URL = scaleway_mnq_sqs_queue.main.url
SQS_REGION = scaleway_mnq_sqs_queue.main.region
}
}

Expand All @@ -85,40 +85,28 @@ resource "scaleway_function" "worker" {
}

# SQS trigger resources
resource "scaleway_mnq_sqs_credentials" "main" {
name = "serverless-examples-python-sqs-trigger"

resource "scaleway_mnq_namespace" "main" {
name = "serverless-examples"
protocol = "sqs_sns"
}

resource "scaleway_mnq_credential" "main" {
name = "serverless-examples-python-sqs-trigger"
namespace_id = scaleway_mnq_namespace.main.id
sqs_sns_credentials {
permissions {
can_publish = true
can_receive = true
can_manage = true
}
permissions {
can_publish = true
can_receive = true
can_manage = true
}
}

resource "scaleway_mnq_queue" "main" {
namespace_id = scaleway_mnq_namespace.main.id
name = "python-sqs-trigger-hello-world"
resource "scaleway_mnq_sqs_queue" "main" {
name = "python-sqs-async-worker"

sqs {
access_key = scaleway_mnq_credential.main.sqs_sns_credentials.0.access_key
secret_key = scaleway_mnq_credential.main.sqs_sns_credentials.0.secret_key
}
access_key = scaleway_mnq_sqs_credentials.main.access_key
secret_key = scaleway_mnq_sqs_credentials.main.secret_key
}

resource "scaleway_function_trigger" "main" {
function_id = scaleway_function.worker.id
name = "my-trigger"
sqs {
namespace_id = scaleway_mnq_namespace.main.id
queue = scaleway_mnq_queue.main.name
queue = scaleway_mnq_sqs_queue.main.name
}
}

Expand Down
46 changes: 17 additions & 29 deletions functions/python-sqs-trigger-hello-world/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
scaleway = {
source = "scaleway/scaleway"
version = ">= 2.12"
version = ">= 2.31"
}
archive = {
source = "hashicorp/archive"
Expand Down Expand Up @@ -41,61 +41,49 @@ resource "scaleway_function" "main" {

# SQS trigger resources

resource "scaleway_mnq_namespace" "main" {
name = "serverless-examples"
protocol = "sqs_sns"
}

resource "scaleway_mnq_credential" "main" {
name = "serverless-examples"
namespace_id = scaleway_mnq_namespace.main.id
sqs_sns_credentials {
permissions {
can_publish = true
can_receive = true
can_manage = true
}
resource "scaleway_mnq_sqs_credentials" "main" {
permissions {
can_publish = true
can_receive = true
can_manage = true
}
}

resource "scaleway_mnq_queue" "main" {
namespace_id = scaleway_mnq_namespace.main.id
name = "python-sqs-trigger-hello-world"
resource "scaleway_mnq_sqs_queue" "main" {
name = "python-sqs-trigger-hello-world"

sqs {
access_key = scaleway_mnq_credential.main.sqs_sns_credentials.0.access_key
secret_key = scaleway_mnq_credential.main.sqs_sns_credentials.0.secret_key
}
access_key = scaleway_mnq_sqs_credentials.main.access_key
secret_key = scaleway_mnq_sqs_credentials.main.secret_key
}

resource "scaleway_function_trigger" "main" {
function_id = scaleway_function.main.id
name = "my-trigger"
sqs {
namespace_id = scaleway_mnq_namespace.main.id
queue = scaleway_mnq_queue.main.name
queue = scaleway_mnq_sqs_queue.main.name
}
}

# Outputs to send messages to the queue

output "sqs_access_key" {
value = scaleway_mnq_credential.main.sqs_sns_credentials.0.access_key
value = scaleway_mnq_sqs_credentials.main.access_key
sensitive = true
}

output "sqs_secret_key" {
value = scaleway_mnq_credential.main.sqs_sns_credentials.0.secret_key
value = scaleway_mnq_sqs_credentials.main.secret_key
sensitive = true
}

output "sqs_endpoint" {
value = replace(scaleway_mnq_queue.main.sqs.0.endpoint, "{region}", scaleway_mnq_namespace.main.region)
value = replace(scaleway_mnq_sqs_queue.main.endpoint, "{region}", scaleway_mnq_sqs_queue.main.region)
}

output "sqs_region" {
value = scaleway_mnq_namespace.main.region
value = scaleway_mnq_sqs_queue.main.region
}

output "sqs_queue_url" {
value = scaleway_mnq_queue.main.sqs.0.url
value = scaleway_mnq_sqs_queue.main.url
}

0 comments on commit 4512798

Please sign in to comment.