From 4add8fe49d9f7ed64ad5a09d1409ae7cf40d7c9b Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Tue, 23 Jul 2024 20:44:55 -0700 Subject: [PATCH 1/9] add howto doc for tf custom provider config --- .../terraform/howto-custom-provider/index.md | 86 +++++++++++++++++ .../snippets/env-complete.bicep | 55 +++++++++++ .../howto-custom-provider/snippets/env.bicep | 95 +++++++++++++++++++ .../snippets/postgres.tf | 0 4 files changed, 236 insertions(+) create mode 100644 docs/content/guides/recipes/terraform/howto-custom-provider/index.md create mode 100644 docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep create mode 100644 docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep create mode 100644 docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md new file mode 100644 index 000000000..c97ee767b --- /dev/null +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md @@ -0,0 +1,86 @@ +--- +type: docs +title: "How-To: Configure custom Terraform Providers" +linkTitle: "Configure custom Terraform Providers" +description: "Learn how to setup your Radius environment to configure custom Terraform Providers and deploy recipes." +weight: 500 +categories: "How-To" +aliases : ["/guides/recipes/terraform/howto-custom-provider"] +tags: ["recipes", "terraform", "provider"] +--- + +This how-to guide will describe how to: + +- Configure a custom Terraform Provider and use it in a Terraform recipe. +In this example we're going to configure a PostgreSQL Terraform provider in a Radius environment and deploy a recipe. +Ref: [Documentation for cyrilgdn/postgresql provider](https://registry.terraform.io/providers/cyrilgdn/postgresql/latest/docs) + +### Prerequisites + +Before you get started, you'll need to make sure you have the following tools and resources: + +- [rad CLI]({{< ref "installation#step-1-install-the-rad-cli" >}}) +- [Radius Bicep VSCode extension]({{< ref "installation#step-2-install-the-vs-code-extension" >}}) +- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) +- [Radius initialized with `rad init`]({{< ref howto-environment >}}) + + +## Step 1: Define a secretStore resource and store any sensitive information needed for the custom provider. + +Configure a [Radius Secret Store]({{< ref "/guides/author-apps/secrets/overview" >}}) with any sensitive information needed as input configuration for the custom Terraform Provider. Define the namespace for the cluster that will contain your [Kubernetes Secret](https://kubernetes.io/docs/concepts/configuration/secret/) with the `resource` property. + +> While this example shows a Radius-managed secret store where Radius creates the underlying secrets infrastructure, you can also bring your own existing secrets. Refer to the [secrets documentation]({{< ref "/guides/author-apps/secrets/overview" >}}) for more information. + +Create a Bicep file `env.bicep`, import Radius, and define your resource: + +{{< rad file="snippets/env.bicep" embed=true marker="//SECRETSTORE" >}} + +> In this example, we're creating a secret with keys `username` and `password` as sensitive inputs required by the Terraform Provider `cyrilgdn/postgresql`. + +## Step 2: Configure Terraform Provider configuration + +`recipeConfig/terraform/providers` allows the user to setup configurations for one or multiple Terraform Providers. For more information refer to the [Radius Environment schema]({{< ref environment-schema >}}) page. + +In your `env.bicep` file add an Environment resource, along with Recipe configuration which leverages the previously defined secret store for certain configuration fields. +In this example we're also passing in `host` as an environment variable to highlight use cases where, depending on provider configuration requirements, users can pass environment variables to the terraform runtime. + +{{< rad file="snippets/env.bicep" embed=true marker="//ENV" >}} + +## Step 3: Define Terraform Recipe + +Create a Terraform recipe which deploys a postgreSQL database instance using custom Terraform provider `cyrilgdn/postgresql` + +{{< rad file="snippets/postgres.tf" embed=true marker="//ENV" >}} + +## Step 4: Add a Terraform Recipe to Env + +Update your Environment with a Terraform Recipe. + +{{< rad file="snippets/env-complete.bicep" embed=true marker="//ENV" markdownConfig="{linenos=table,hl_lines=[\"22-30\"],linenostart=30,lineNos=false}" >}} + +## Step 5: Deploy your Radius Environment + +Deploy your new Radius Environment: + +``` +rad deploy ./env.bicep -p username=****** -p password=****** +``` + +## Done + +Your Radius Environment is now ready to deploy your Radius Recipes that utilize resources associated with configured custom providers. For more information on Radius Recipes visit the [Recipes overview page]({{< ref "/guides/recipes/overview" >}}). + +## Cleanup + +You can delete a Radius Environment by running the following command: + +``` +rad env delete my-env +``` + +## Further reading + +- [Recipes overview]({{< ref "/guides/recipes/overview" >}}) +- [Radius Environments]({{< ref "/guides/deploy-apps/environments/overview" >}}) +- [`rad recipe CLI reference`]({{< ref rad_recipe >}}) +- [`rad env CLI reference`]({{< ref rad_env >}}) \ No newline at end of file diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep new file mode 100644 index 000000000..49f7822a0 --- /dev/null +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep @@ -0,0 +1,55 @@ +//SECRETSTORE +import radius as radius + +@description('Required value, refers to the personal access token or password of the git platform') +@secure() +param pat string + +resource secretStoreGit 'Applications.Core/secretStores@2023-10-01-preview' = { + name: 'my-git-secret-store' + properties: { + resource: 'my-secret-namespace/github' + type: 'generic' + data: { + pat: { + value: pat + } + } + } +} +//SECRETSTORE + +//ENV +resource env 'Applications.Core/environments@2023-10-01-preview' = { + name: 'my-env' + properties: { + compute: { + kind: 'kubernetes' + namespace: 'my-namespace' + } + recipeConfig: { + terraform: { + authentication: { + git: { + pat: { + // The hostname of your git platform, such as 'dev.azure.com' or 'github.com' + 'github.com':{ + secret: secretStoreGit.id + } + } + } + } + } + } + recipes: { + 'Applications.Datastores/redisCaches': { + default: { + templateKind: 'terraform' + // Git template path + templatePath:'git::https://github.com/my-org/my-repo' + } + } + } + } +} +//ENV diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep new file mode 100644 index 000000000..000e05f4d --- /dev/null +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep @@ -0,0 +1,95 @@ +//SECRETSTORE +import radius as radius + +@description('username for postgres db') +@secure() +param username string + +@description('password for postgres db') +@secure() +param password string + +resource pgsSecretStore 'Applications.Core/secretStores@2023-10-01-preview' = { + name: 'my-secret-store' + properties: { + resource: 'my-secret-namespace/my-secret-store' + type: 'generic' + data: { + username: { + value: username + } + password: { + value: password + } + } + } +} +//SECRETSTORE + +//ENV +resource env 'Applications.Core/environments@2023-10-01-preview' = { + name: 'my-env' + properties: { + compute: { + kind: 'kubernetes' + namespace: 'my-namespace' + } + recipeConfig: { + terraform: { + authentication: { + git: { + pat: { + // The hostname of your git platform, such as 'dev.azure.com' or 'github.com' + 'github.com':{ + secret: secretStoreGit.id + } + } + } + } + } + } + } +} + +resource env 'Applications.Core/environments@2023-10-01-preview' = { + name: 'my-env' + properties: { + compute: { + kind: 'kubernetes' + resourceId: 'self' + namespace: 'my-namespace' + } + recipeConfig: { + terraform:{ + providers:{ + postgresql:[{ + sslmode: 'disable' + port: 5432 + secrets: { + username: { + source: pgsSecretStore.id + key: username + } + password: { + source: pgsSecretStore.id + key: password + } + } + }] + } + } + env: { + PGHOST: 'postgres.corerp-resources-terraform-pg-app.svc.cluster.local' + } + } + recipes: { + 'Applications.Core/extenders': { + defaultpostgres: { + templateKind: 'terraform' + templatePath: 'git::https://github.com/lakshmimsft/lak-temp-public//postgres2' + } + } + } + } +} +//ENV diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf new file mode 100644 index 000000000..e69de29bb From b492f4aacbc02ad608970a389eae95c26eda0eed Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Tue, 23 Jul 2024 22:04:36 -0700 Subject: [PATCH 2/9] unsaved files --- .github/config/en-custom.txt | 4 + .../snippets/env-complete.bicep | 53 +++++++---- .../howto-custom-provider/snippets/env.bicep | 36 +------- .../snippets/postgres.tf | 89 +++++++++++++++++++ 4 files changed, 130 insertions(+), 52 deletions(-) diff --git a/.github/config/en-custom.txt b/.github/config/en-custom.txt index e17688da1..a9781bb81 100644 --- a/.github/config/en-custom.txt +++ b/.github/config/en-custom.txt @@ -1249,3 +1249,7 @@ azwi Entra ServiceAccounts pluggable +cyrilgdn +secretStore +postgreSQL +postgres diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep index 49f7822a0..74c16a5fa 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep @@ -1,18 +1,25 @@ //SECRETSTORE import radius as radius -@description('Required value, refers to the personal access token or password of the git platform') +@description('username for postgres db') @secure() -param pat string +param username string -resource secretStoreGit 'Applications.Core/secretStores@2023-10-01-preview' = { - name: 'my-git-secret-store' +@description('password for postgres db') +@secure() +param password string + +resource pgsSecretStore 'Applications.Core/secretStores@2023-10-01-preview' = { + name: 'my-secret-store' properties: { - resource: 'my-secret-namespace/github' + resource: 'my-secret-namespace/my-secret-store' type: 'generic' data: { - pat: { - value: pat + username: { + value: username + } + password: { + value: password } } } @@ -25,27 +32,37 @@ resource env 'Applications.Core/environments@2023-10-01-preview' = { properties: { compute: { kind: 'kubernetes' + resourceId: 'self' namespace: 'my-namespace' } recipeConfig: { - terraform: { - authentication: { - git: { - pat: { - // The hostname of your git platform, such as 'dev.azure.com' or 'github.com' - 'github.com':{ - secret: secretStoreGit.id + terraform:{ + providers:{ + postgresql:[{ + sslmode: 'disable' + port: 5432 + secrets: { + username: { + source: pgsSecretStore.id + key: username + } + password: { + source: pgsSecretStore.id + key: password } } - } + }] } } + env: { + PGHOST: 'postgres.corerp-resources-terraform-pg-app.svc.cluster.local' + } } recipes: { - 'Applications.Datastores/redisCaches': { - default: { + 'Applications.Core/extenders': { + defaultpostgres: { templateKind: 'terraform' - // Git template path + // Recipe template path templatePath:'git::https://github.com/my-org/my-repo' } } diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep index 000e05f4d..74f1c3b01 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep @@ -1,11 +1,11 @@ //SECRETSTORE import radius as radius -@description('username for postgres db') +@description('username for PostgreSQL db') @secure() param username string -@description('password for postgres db') +@description('password for PostgreSQL db') @secure() param password string @@ -27,30 +27,6 @@ resource pgsSecretStore 'Applications.Core/secretStores@2023-10-01-preview' = { //SECRETSTORE //ENV -resource env 'Applications.Core/environments@2023-10-01-preview' = { - name: 'my-env' - properties: { - compute: { - kind: 'kubernetes' - namespace: 'my-namespace' - } - recipeConfig: { - terraform: { - authentication: { - git: { - pat: { - // The hostname of your git platform, such as 'dev.azure.com' or 'github.com' - 'github.com':{ - secret: secretStoreGit.id - } - } - } - } - } - } - } -} - resource env 'Applications.Core/environments@2023-10-01-preview' = { name: 'my-env' properties: { @@ -82,14 +58,6 @@ resource env 'Applications.Core/environments@2023-10-01-preview' = { PGHOST: 'postgres.corerp-resources-terraform-pg-app.svc.cluster.local' } } - recipes: { - 'Applications.Core/extenders': { - defaultpostgres: { - templateKind: 'terraform' - templatePath: 'git::https://github.com/lakshmimsft/lak-temp-public//postgres2' - } - } - } } } //ENV diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf index e69de29bb..527eaae05 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf @@ -0,0 +1,89 @@ +terraform { + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + version = ">= 2.0" + } + postgresql = { + source = "cyrilgdn/postgresql" + version = "1.16.0" + } + } +} + +variable "context" { + description = "This variable contains Radius recipe context." + type = any +} + +variable "password" { + description = "The password for the PostgreSQL database" + type = string +} + +resource "kubernetes_deployment" "postgres" { + metadata { + name = "postgres" + namespace = var.context.runtime.kubernetes.namespace + } + + spec { + selector { + match_labels = { + app = "postgres" + } + } + + template { + metadata { + labels = { + app = "postgres" + } + } + + spec { + container { + image = "postgres:latest" + name = "postgres" + + env { + name = "POSTGRES_PASSWORD" + value = var.password + } + + port { + container_port = 5432 + } + } + } + } + } +} + +resource "kubernetes_service" "postgres" { + metadata { + name = "postgres" + namespace = var.context.runtime.kubernetes.namespace + } + + spec { + selector = { + app = "postgres" + } + + port { + port = 5432 + target_port = 5432 + } + } +} + +resource "time_sleep" "wait_20_seconds" { + depends_on = [kubernetes_service.postgres] + create_duration = "20s" +} + +resource postgresql_database "pg_db_test" { + depends_on = [time_sleep.wait_20_seconds] + name = "pg_db_test" +} \ No newline at end of file From 150c9912e09e2997f0b02c47bf465b77e0555c44 Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Wed, 24 Jul 2024 11:00:12 -0700 Subject: [PATCH 3/9] update per comments --- .../terraform/howto-custom-provider/index.md | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md index c97ee767b..e0d1836f9 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md @@ -1,19 +1,21 @@ --- type: docs title: "How-To: Configure custom Terraform Providers" -linkTitle: "Configure custom Terraform Providers" -description: "Learn how to setup your Radius environment to configure custom Terraform Providers and deploy recipes." +linkTitle: "Custom Terraform Providers" +description: "Learn how to setup your Radius environment with custom Terraform Providers and deploy recipes." weight: 500 categories: "How-To" aliases : ["/guides/recipes/terraform/howto-custom-provider"] -tags: ["recipes", "terraform", "provider"] +tags: ["recipes", "terraform"] --- This how-to guide will describe how to: -- Configure a custom Terraform Provider and use it in a Terraform recipe. -In this example we're going to configure a PostgreSQL Terraform provider in a Radius environment and deploy a recipe. -Ref: [Documentation for cyrilgdn/postgresql provider](https://registry.terraform.io/providers/cyrilgdn/postgresql/latest/docs) +- Configure a custom [Terraform provider](https://registry.terraform.io/browse/providers) in a Radius environment. +- Configure credentials to authenticate into the Terraform provider. +- Consume the terraform modules from a custom Terraform provider and use it in a Terraform recipe. + +In this example we're going to configure a [PostgreSQL Terraform provider](https://registry.terraform.io/providers/cyrilgdn/postgresql/latest/docs) in a Radius environment and deploy a recipe. ### Prerequisites @@ -23,58 +25,58 @@ Before you get started, you'll need to make sure you have the following tools an - [Radius Bicep VSCode extension]({{< ref "installation#step-2-install-the-vs-code-extension" >}}) - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - [Radius initialized with `rad init`]({{< ref howto-environment >}}) +- [Recipes overview]({{< ref "/guides/recipes/overview" >}}) - -## Step 1: Define a secretStore resource and store any sensitive information needed for the custom provider. +## Step 1: Define a secretStore resource for the custom provider Configure a [Radius Secret Store]({{< ref "/guides/author-apps/secrets/overview" >}}) with any sensitive information needed as input configuration for the custom Terraform Provider. Define the namespace for the cluster that will contain your [Kubernetes Secret](https://kubernetes.io/docs/concepts/configuration/secret/) with the `resource` property. > While this example shows a Radius-managed secret store where Radius creates the underlying secrets infrastructure, you can also bring your own existing secrets. Refer to the [secrets documentation]({{< ref "/guides/author-apps/secrets/overview" >}}) for more information. -Create a Bicep file `env.bicep`, import Radius, and define your resource: +Create a Bicep file `env.bicep` with the secretStore resource: {{< rad file="snippets/env.bicep" embed=true marker="//SECRETSTORE" >}} -> In this example, we're creating a secret with keys `username` and `password` as sensitive inputs required by the Terraform Provider `cyrilgdn/postgresql`. +> In this example, we're creating a secret with keys `username` and `password` as sensitive data required to authenticate into the Terraform Provider `cyrilgdn/postgresql`. -## Step 2: Configure Terraform Provider configuration +## Step 2: Configure Terraform Provider -`recipeConfig/terraform/providers` allows the user to setup configurations for one or multiple Terraform Providers. For more information refer to the [Radius Environment schema]({{< ref environment-schema >}}) page. +`recipeConfig/terraform/providers` allows you to setup configurations for one or multiple Terraform Providers. For more information refer to the [Radius Environment schema]({{< ref environment-schema >}}) page. -In your `env.bicep` file add an Environment resource, along with Recipe configuration which leverages the previously defined secret store for certain configuration fields. -In this example we're also passing in `host` as an environment variable to highlight use cases where, depending on provider configuration requirements, users can pass environment variables to the terraform runtime. +In your `env.bicep` file add an Environment resource, along with Recipe configuration which leverages properties from the previously defined secret store. +In this example you're also passing in `host` as an environment variable to highlight use cases where, depending on provider configuration requirements, users can pass environment variables to the Terraform runtime. {{< rad file="snippets/env.bicep" embed=true marker="//ENV" >}} -## Step 3: Define Terraform Recipe +## Step 3: Define a Terraform Recipe Create a Terraform recipe which deploys a postgreSQL database instance using custom Terraform provider `cyrilgdn/postgresql` {{< rad file="snippets/postgres.tf" embed=true marker="//ENV" >}} -## Step 4: Add a Terraform Recipe to Env +## Step 4: Add a Terraform Recipe to the environment -Update your Environment with a Terraform Recipe. +Update your Environment with the Terraform Recipe. {{< rad file="snippets/env-complete.bicep" embed=true marker="//ENV" markdownConfig="{linenos=table,hl_lines=[\"22-30\"],linenostart=30,lineNos=false}" >}} ## Step 5: Deploy your Radius Environment -Deploy your new Radius Environment: +Deploy your new Radius Environment passing in values for `username` and `password` needed to authenticate into the provider. The superuser for this PostgreSQL recipe is `postgres` which is the expected input for `username`: -``` +```bash rad deploy ./env.bicep -p username=****** -p password=****** ``` ## Done -Your Radius Environment is now ready to deploy your Radius Recipes that utilize resources associated with configured custom providers. For more information on Radius Recipes visit the [Recipes overview page]({{< ref "/guides/recipes/overview" >}}). +Your Radius Environment is now configured with a custom Terraform provider which you can use to deploy Radius Terraform recipes. For more information on Radius Recipes visit the [Recipes overview page]({{< ref "/guides/recipes/overview" >}}). ## Cleanup -You can delete a Radius Environment by running the following command: +You can delete the Radius Environment by running the following command: -``` +```bash rad env delete my-env ``` From 981e4e69f59a553e375bffcc59066954605a2799 Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Wed, 24 Jul 2024 14:40:49 -0700 Subject: [PATCH 4/9] update for conflicts --- .github/config/en-custom.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/config/en-custom.txt b/.github/config/en-custom.txt index a9781bb81..346709829 100644 --- a/.github/config/en-custom.txt +++ b/.github/config/en-custom.txt @@ -1249,6 +1249,11 @@ azwi Entra ServiceAccounts pluggable +envSecrets +RecipeConfigPropertiesEnvSecrets +ProviderConfigPropertiesSecrets +SecretReference +v0.36 cyrilgdn secretStore postgreSQL From d952c4b511cefe35e7f3190c1a7796825af18ab5 Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Wed, 24 Jul 2024 14:46:50 -0700 Subject: [PATCH 5/9] extra space --- .github/config/en-custom.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/config/en-custom.txt b/.github/config/en-custom.txt index 302cb828e..548ed327c 100644 --- a/.github/config/en-custom.txt +++ b/.github/config/en-custom.txt @@ -1257,5 +1257,4 @@ v0.36 cyrilgdn secretStore postgreSQL -postgres - +postgres \ No newline at end of file From b7ce3eda99f1c48f53c9c00a618c0805a980da81 Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Wed, 24 Jul 2024 14:48:45 -0700 Subject: [PATCH 6/9] extra space --- .github/config/en-custom.txt | 1 - .../snippets/env-complete.bicep | 34 +++++++++---------- .../howto-custom-provider/snippets/env.bicep | 32 ++++++++--------- .../snippets/postgres.tf | 10 +++--- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/.github/config/en-custom.txt b/.github/config/en-custom.txt index 548ed327c..79552ae2a 100644 --- a/.github/config/en-custom.txt +++ b/.github/config/en-custom.txt @@ -1253,7 +1253,6 @@ envSecrets RecipeConfigPropertiesEnvSecrets ProviderConfigPropertiesSecrets SecretReference -v0.36 cyrilgdn secretStore postgreSQL diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep index 74c16a5fa..d66f62bd2 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env-complete.bicep @@ -36,26 +36,26 @@ resource env 'Applications.Core/environments@2023-10-01-preview' = { namespace: 'my-namespace' } recipeConfig: { - terraform:{ - providers:{ - postgresql:[{ - sslmode: 'disable' - port: 5432 - secrets: { - username: { - source: pgsSecretStore.id - key: username + terraform: { + providers: { + postgresql: [ { + sslmode: 'disable' + port: 5432 + secrets: { + username: { + source: pgsSecretStore.id + key: username + } + password: { + source: pgsSecretStore.id + key: password + } } - password: { - source: pgsSecretStore.id - key: password - } - } - }] + } ] } } env: { - PGHOST: 'postgres.corerp-resources-terraform-pg-app.svc.cluster.local' + PGHOST: 'postgres.corerp-resources-terraform-pg-app.svc.cluster.local' } } recipes: { @@ -63,7 +63,7 @@ resource env 'Applications.Core/environments@2023-10-01-preview' = { defaultpostgres: { templateKind: 'terraform' // Recipe template path - templatePath:'git::https://github.com/my-org/my-repo' + templatePath: 'git::https://github.com/my-org/my-repo' } } } diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep index 74f1c3b01..bfc672312 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/env.bicep @@ -36,26 +36,26 @@ resource env 'Applications.Core/environments@2023-10-01-preview' = { namespace: 'my-namespace' } recipeConfig: { - terraform:{ - providers:{ - postgresql:[{ - sslmode: 'disable' - port: 5432 - secrets: { - username: { - source: pgsSecretStore.id - key: username + terraform: { + providers: { + postgresql: [ { + sslmode: 'disable' + port: 5432 + secrets: { + username: { + source: pgsSecretStore.id + key: username + } + password: { + source: pgsSecretStore.id + key: password + } } - password: { - source: pgsSecretStore.id - key: password - } - } - }] + } ] } } env: { - PGHOST: 'postgres.corerp-resources-terraform-pg-app.svc.cluster.local' + PGHOST: 'postgres.corerp-resources-terraform-pg-app.svc.cluster.local' } } } diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf index 527eaae05..422147ba0 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/snippets/postgres.tf @@ -13,7 +13,7 @@ terraform { variable "context" { description = "This variable contains Radius recipe context." - type = any + type = any } variable "password" { @@ -79,11 +79,11 @@ resource "kubernetes_service" "postgres" { } resource "time_sleep" "wait_20_seconds" { - depends_on = [kubernetes_service.postgres] + depends_on = [kubernetes_service.postgres] create_duration = "20s" } -resource postgresql_database "pg_db_test" { +resource "postgresql_database" "pg_db_test" { depends_on = [time_sleep.wait_20_seconds] - name = "pg_db_test" -} \ No newline at end of file + name = "pg_db_test" +} From 967b4d9449c6568b87ae4ade79062527480da83b Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Wed, 24 Jul 2024 16:23:25 -0700 Subject: [PATCH 7/9] further comments --- .../terraform/howto-custom-provider/index.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md index e0d1836f9..89ae04d7a 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md @@ -2,7 +2,7 @@ type: docs title: "How-To: Configure custom Terraform Providers" linkTitle: "Custom Terraform Providers" -description: "Learn how to setup your Radius environment with custom Terraform Providers and deploy recipes." +description: "Learn how to setup your Radius environment with custom Terraform Providers and deploy Recipes." weight: 500 categories: "How-To" aliases : ["/guides/recipes/terraform/howto-custom-provider"] @@ -13,9 +13,9 @@ This how-to guide will describe how to: - Configure a custom [Terraform provider](https://registry.terraform.io/browse/providers) in a Radius environment. - Configure credentials to authenticate into the Terraform provider. -- Consume the terraform modules from a custom Terraform provider and use it in a Terraform recipe. +- Consume the Terraform modules from a custom Terraform provider and use it in a Terraform recipe. -In this example we're going to configure a [PostgreSQL Terraform provider](https://registry.terraform.io/providers/cyrilgdn/postgresql/latest/docs) in a Radius environment and deploy a recipe. +In this example you're going to configure a [PostgreSQL Terraform provider](https://registry.terraform.io/providers/cyrilgdn/postgresql/latest/docs) in a Radius Environment and deploy a Recipe. ### Prerequisites @@ -37,20 +37,19 @@ Create a Bicep file `env.bicep` with the secretStore resource: {{< rad file="snippets/env.bicep" embed=true marker="//SECRETSTORE" >}} -> In this example, we're creating a secret with keys `username` and `password` as sensitive data required to authenticate into the Terraform Provider `cyrilgdn/postgresql`. +> In this example, you're creating a secret with keys `username` and `password` as sensitive data required to authenticate into the Terraform Provider `cyrilgdn/postgresql`. ## Step 2: Configure Terraform Provider `recipeConfig/terraform/providers` allows you to setup configurations for one or multiple Terraform Providers. For more information refer to the [Radius Environment schema]({{< ref environment-schema >}}) page. -In your `env.bicep` file add an Environment resource, along with Recipe configuration which leverages properties from the previously defined secret store. -In this example you're also passing in `host` as an environment variable to highlight use cases where, depending on provider configuration requirements, users can pass environment variables to the Terraform runtime. +In your `env.bicep` file add an Environment resource, along with Recipe configuration which leverages properties from the previously defined secret store. In this example you're also passing in `host` as an environment variable to highlight use cases where, depending on provider configuration requirements, users can pass environment variables to the Terraform runtime. {{< rad file="snippets/env.bicep" embed=true marker="//ENV" >}} ## Step 3: Define a Terraform Recipe -Create a Terraform recipe which deploys a postgreSQL database instance using custom Terraform provider `cyrilgdn/postgresql` +Create a Terraform recipe which deploys a PostgreSQL database instance using custom Terraform provider `cyrilgdn/postgresql`. {{< rad file="snippets/postgres.tf" embed=true marker="//ENV" >}} @@ -62,7 +61,7 @@ Update your Environment with the Terraform Recipe. ## Step 5: Deploy your Radius Environment -Deploy your new Radius Environment passing in values for `username` and `password` needed to authenticate into the provider. The superuser for this PostgreSQL recipe is `postgres` which is the expected input for `username`: +Deploy your new Radius Environment passing in values for `username` and `password` needed to authenticate into the provider. The superuser for this PostgreSQL Recipe is `postgres` which is the expected input for `username`: ```bash rad deploy ./env.bicep -p username=****** -p password=****** @@ -70,7 +69,7 @@ rad deploy ./env.bicep -p username=****** -p password=****** ## Done -Your Radius Environment is now configured with a custom Terraform provider which you can use to deploy Radius Terraform recipes. For more information on Radius Recipes visit the [Recipes overview page]({{< ref "/guides/recipes/overview" >}}). +Your Radius Environment is now configured with a custom Terraform Provider which you can use to deploy Radius Terraform Recipes. For more information on Radius Recipes visit the [Recipes overview page]({{< ref "/guides/recipes/overview" >}}). ## Cleanup From db45625c53db0d58eed9a45b578b0c3e9be96df8 Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Wed, 24 Jul 2024 16:32:14 -0700 Subject: [PATCH 8/9] capitalizing Environment --- .../guides/recipes/terraform/howto-custom-provider/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md index 89ae04d7a..5feb385ab 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md @@ -2,7 +2,7 @@ type: docs title: "How-To: Configure custom Terraform Providers" linkTitle: "Custom Terraform Providers" -description: "Learn how to setup your Radius environment with custom Terraform Providers and deploy Recipes." +description: "Learn how to setup your Radius Environment with custom Terraform Providers and deploy Recipes." weight: 500 categories: "How-To" aliases : ["/guides/recipes/terraform/howto-custom-provider"] @@ -11,7 +11,7 @@ tags: ["recipes", "terraform"] This how-to guide will describe how to: -- Configure a custom [Terraform provider](https://registry.terraform.io/browse/providers) in a Radius environment. +- Configure a custom [Terraform provider](https://registry.terraform.io/browse/providers) in a Radius Environment. - Configure credentials to authenticate into the Terraform provider. - Consume the Terraform modules from a custom Terraform provider and use it in a Terraform recipe. @@ -53,7 +53,7 @@ Create a Terraform recipe which deploys a PostgreSQL database instance using cus {{< rad file="snippets/postgres.tf" embed=true marker="//ENV" >}} -## Step 4: Add a Terraform Recipe to the environment +## Step 4: Add a Terraform Recipe to the Environment Update your Environment with the Terraform Recipe. From eec5e556952d3e56905fbf39be2db4d9e150a1ef Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Thu, 25 Jul 2024 09:30:26 -0700 Subject: [PATCH 9/9] one more change --- .../guides/recipes/terraform/howto-custom-provider/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md index 5feb385ab..b14e2ee32 100644 --- a/docs/content/guides/recipes/terraform/howto-custom-provider/index.md +++ b/docs/content/guides/recipes/terraform/howto-custom-provider/index.md @@ -43,7 +43,7 @@ Create a Bicep file `env.bicep` with the secretStore resource: `recipeConfig/terraform/providers` allows you to setup configurations for one or multiple Terraform Providers. For more information refer to the [Radius Environment schema]({{< ref environment-schema >}}) page. -In your `env.bicep` file add an Environment resource, along with Recipe configuration which leverages properties from the previously defined secret store. In this example you're also passing in `host` as an environment variable to highlight use cases where, depending on provider configuration requirements, users can pass environment variables to the Terraform runtime. +In your `env.bicep` file add an Environment resource, along with Recipe configuration which leverages properties from the previously defined secret store. In this example you're also passing in `host` as an environment variable to highlight use cases where, depending on provider configuration requirements, users can pass environment variables to the Terraform recipes runtime. {{< rad file="snippets/env.bicep" embed=true marker="//ENV" >}}