Skip to content

Commit

Permalink
update per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmimsft committed Jul 24, 2024
1 parent b492f4a commit 161a733
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:

```
```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
```

Expand Down

0 comments on commit 161a733

Please sign in to comment.