From 9cc01132a21af4f37e359ba4fdc77d62804abf28 Mon Sep 17 00:00:00 2001 From: "alexander.miehe" Date: Tue, 17 Dec 2024 12:29:57 +0100 Subject: [PATCH] PLT-1057 - Setup module --- .github/CODEOWNERS | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 2 +- README.md | 45 +++++++++++++++++++++++++++----------- main.tf | 5 +++++ output.tf | 5 +++++ variables.tf | 12 ++++++++++ versions.tf | 8 ++++++- 8 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 main.tf create mode 100644 output.tf create mode 100644 variables.tf diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ec25d53..df69b44 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @Flaconi/devops +* @Flaconi/devops @Flaconi/platform @Flaconi/ci diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b087fbe..8123d6c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -59,4 +59,4 @@ jobs: git diff --quiet || { echo "Build Changes"; git diff; git status; false; } env: TARGET: ${{ matrix.target }} - RETRIES: 20 + RETRIES: 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b888ae3..9cb714a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,4 +47,4 @@ jobs: } retry make test env: - RETRIES: 20 + RETRIES: 1 diff --git a/README.md b/README.md index da64134..d54bcb5 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ -# terraform-module-template -Template for Terraform modules - - +# terraform-algolia-api-keys + +That module allows to create algolia api keys + +[![lint](https://github.com/flaconi/terraform-algolia-api-keys/workflows/lint/badge.svg)](https://github.com/flaconi/terraform-algolia-api-keys/actions?query=workflow%3Alint) +[![test](https://github.com/flaconi/terraform-algolia-api-keys/workflows/test/badge.svg)](https://github.com/flaconi/terraform-algolia-api-keys/actions?query=workflow%3Atest) +[![Tag](https://img.shields.io/github/tag/flaconi/terraform-algolia-api-keys.svg)](https://github.com/flaconi/terraform-algolia-api-keys/releases) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) For requirements regarding module structure: [style-guide-terraform.md](https://github.com/Flaconi/devops-docs/blob/master/doc/conventions/style-guide-terraform.md) @@ -18,7 +17,9 @@ For requirements regarding module structure: [style-guide-terraform.md](https:// ## Providers -No providers. +| Name | Version | +|------|---------| +| [algolia](#provider\_algolia) | 0.6.0 | @@ -27,7 +28,8 @@ No providers. | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | ~> 1.3 | +| [terraform](#requirement\_terraform) | >= 1.5 | +| [algolia](#requirement\_algolia) | 0.6.0 | @@ -38,14 +40,31 @@ No required inputs. ## Optional Inputs -No optional inputs. +The following input variables are optional (have default values): + +### [api\_keys](#input\_api\_keys) + +Description: Map of API Keys + +Type: + +```hcl +map(object({ + description = string, + acl = set(string) + })) +``` + +Default: `{}` ## Outputs -No outputs. +| Name | Description | +|------|-------------| +| [api\_keys](#output\_api\_keys) | Created API Keys through terraform | @@ -53,4 +72,4 @@ No outputs. **[MIT License](LICENSE)** -Copyright (c) 2023 **[Flaconi GmbH](https://github.com/flaconi)** +Copyright (c) 2024 **[Flaconi GmbH](https://github.com/flaconi)** diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..72d6b4d --- /dev/null +++ b/main.tf @@ -0,0 +1,5 @@ +resource "algolia_api_key" "this" { + for_each = var.api_keys + acl = each.value.acl + description = each.value.description +} diff --git a/output.tf b/output.tf new file mode 100644 index 0000000..b28e982 --- /dev/null +++ b/output.tf @@ -0,0 +1,5 @@ +output "api_keys" { + description = "Created API Keys through terraform" + value = algolia_api_key.this + sensitive = true +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..499ac68 --- /dev/null +++ b/variables.tf @@ -0,0 +1,12 @@ +variable "api_keys" { + type = map(object({ + description = string, + acl = set(string) + })) + default = {} + description = "Map of API Keys" + validation { + condition = alltrue(flatten([for key in var.api_keys : [for p in key.acl : contains(["search", "browse", "addObject", "deleteObject", "listIndexes", "deleteIndex", "settings", "analytics", "recommendation", "usage", "nluReadAnswers", "logs", "seeUnretrievableAttributes"], p)]])) + error_message = "Only the following permissions are allowed: search, browse, addObject, deleteObject, listIndexes, deleteIndex, settings, analytics, recommendation, usage, nluReadAnswers, logs, seeUnretrievableAttributes" + } +} diff --git a/versions.tf b/versions.tf index e6b4cbd..d6e3e20 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,9 @@ terraform { - required_version = "~> 1.3" + required_providers { + algolia = { + source = "k-yomo/algolia" + version = "0.6.0" + } + } + required_version = ">= 1.5" }