You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/deployment-environments/how-to-configure-extensibility-model-custom-image.md
+130-2Lines changed: 130 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,15 +73,14 @@ Creating a custom container image allows you to customize your deployments to fi
73
73
74
74
After you complete the image customization, you can build the image and push it to your container registry by using a script provided by Microsoft to automate the process.
Rather than building your custom image and pushing it to a container registry yourself, you can use a script to build and push it to a specified container registry.
You can take one of the following approaches to use container images with ADE:
114
+
-**Create a container image leveraging a GitHub workflow:** To start with, you can use the published GitHub workflow from the Leveraging ADE's Extensibility Model With Terraform repository.
115
+
-**Create a custom container image:** You can create a workflow that creates a Terraform specific image customized with all the software, settings, and configuration that you need.
116
+
117
+
118
+
## Create a container image leveraging a GitHub workflow
119
+
Creating a custom container image allows you to customize your deployments to fit your requirements. You can create custom images based on the ADE standard images.
120
+
121
+
After you complete the image customization, you must build the image and push it to your container registry.
122
+
123
+
You can build and push the image manually, or use a script provided by Microsoft to automate the process.
124
+
125
+
The published GitHub Action helps to build and push an image to an Azure Container Registry (ACR). You can reference a provided ACR image link within an environment definition in ADE to deploy or delete an environment with the provided image.
126
+
127
+
To create an image configured for ADE, follow these steps:
128
+
1. Create a custom image based on a GitHub workflow.
129
+
1. Install desired packages.
130
+
1. Configure operation shell scripts.
131
+
1. Create operation shell scripts that use the Terraform CLI.
132
+
133
+
**1. Create a custom image based on a GitHub workflow**
134
+
135
+
Use the [published repository](https://github.com/Azure/ade-extensibility-model-terraform/blob/main/README.md#azure-deployment-environments---leveraging-ades-extensibility-model-with-terraform) to take advantage of the GitHub workflow. The repository contains ADE-compatible sample image components, including a Dockerfile and shell scripts for deploying and deleting environments using Terraform IaC templates. This sample code helps you create your own container image.
136
+
137
+
138
+
**2. Install required packages**
139
+
In this step, you install any packages you require in your image, including Terraform. You can install the Terraform CLI to an executable location so that it can be used in your deployment and deletion scripts.
140
+
141
+
Here's an example of that process, installing version 1.7.5 of the Terraform CLI:
142
+
143
+
```azure cli
144
+
RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/1.7.5/terraform_1.7.5_linux_amd64.zip
145
+
RUN unzip terraform.zip && rm terraform.zip
146
+
RUN mv terraform /usr/bin/terraform
147
+
```
148
+
149
+
> [!Tip]
150
+
> You can get the download URL for your preferred version of the Terraform CLI from [Hashicorp releases](https://aka.ms/deployment-environments/terraform-cli-zip).
151
+
152
+
153
+
**3. Configure operation shell scripts**
154
+
155
+
Within the standard images, operations are determined and executed based on the operation name. Currently, the two operation names supported are *deploy* and *delete*.
156
+
157
+
To set up your custom image to utilize this structure, specify a folder at the level of your Dockerfile named *scripts*, and specify two files, *deploy.sh*, and *delete.sh*. The deploy shell script runs when your environment is created or redeployed, and the delete shell script runs when your environment is deleted. You can see examples of shell scripts in the repository under the [Runner-Images folder for the ARM-Bicep](https://github.com/Azure/deployment-environments/tree/main/Runner-Images/ARM-Bicep) image.
158
+
159
+
To ensure these shell scripts are executable, add the following lines to your Dockerfile:
160
+
161
+
```docker
162
+
COPY scripts/* /scripts/
163
+
RUN find /scripts/ -type f -iname "*.sh" -exec dos2unix '{}' '+'
164
+
RUN find /scripts/ -type f -iname "*.sh" -exec chmod +x {} \;
165
+
```
166
+
167
+
**4. Create operation shell scripts that use the Terraform CLI**
168
+
169
+
There are three steps to deploy infrastructure via Terraform:
170
+
1.`terraform init` - initializes the Terraform CLI to perform actions within the working directory
171
+
1.`terraform plan` - develops a plan based on the incoming Terraform infrastructure files and variables, and any existing state files, and develops steps needed to create or update infrastructure specified in the *.tf* files
172
+
1.`terraform apply` - applies the plan to create new or update existing infrastructure in Azure
173
+
174
+
During the core image's entrypoint, any existing state files are pulled into the container and the directory saved under the environment variable ```$ADE_STORAGE```. Additionally, any parameters set for the current environment stored under the variable ```$ADE_OPERATION_PARAMETERS```. In order to access the existing state file, and set your variables within a *.tfvars.json* file, run the following commands:
Additionally, to utilize ADE privileges to deploy infrastructure inside your subscription, your script needs to use the Managed Service Identity (MSI) when provisioning infrastructure by using the Terraform AzureRM provider. If your deployment needs special permissions to complete your deployment, such as particular roles, assign those permissions to the project environment type's identity that is being used for your environment deployment. ADE sets the relevant environment variables, such as the client, tenant, and subscription IDs within the core image's entrypoint, so run the following commands to ensure the provider uses the ADE MSI:
184
+
```bash
185
+
export ARM_USE_MSI=true
186
+
export ARM_CLIENT_ID=$ADE_CLIENT_ID
187
+
export ARM_TENANT_ID=$ADE_TENANT_ID
188
+
export ARM_SUBSCRIPTION_ID=$ADE_SUBSCRIPTION_ID
189
+
```
190
+
191
+
If you have other variables to reference within your template that aren't specified in your environment's parameters, set environment variables using the prefix *TF_VAR*. A list of provided ADE environment variables is provided [Azure Deployment Environment CLI variables reference](./reference-deployment-environment-variables.md). An example of those commands could be;
Now, you can run the steps listed previously to initialize the Terraform CLI, generate a plan for provisioning infrastructure, and apply a plan during your deployment script:
202
+
```bash
203
+
terraform init
204
+
terraform plan -no-color -compact-warnings -refresh=true -lock=true -state=$EnvironmentState -out=$EnvironmentPlan -var-file="$EnvironmentVars"
During your deletion script, you can add the `destroy` flag to your plan generation to delete the existing resources, as shown in the following example:
209
+
```bash
210
+
terraform init
211
+
terraform plan -no-color -compact-warnings -destroy -refresh=true -lock=true -state=$EnvironmentState -out=$EnvironmentPlan -var-file="$EnvironmentVars"
Finally, to make the outputs of your deployment uploaded and accessible when accessing your environment via the Azure CLI, transform the output object from Terraform to the ADE-specified format through the JQ package. Set the value to the $ADE_OUTPUTS environment variable, as shown in the following example:
0 commit comments