Skip to content

Commit 649503b

Browse files
authored
Merge pull request microsoft#2 from jcorioland/jcorioland/contrib
AzureRM Terraform Provider Contribution Guide
2 parents 69b2da1 + e6612d2 commit 649503b

File tree

6 files changed

+147
-0
lines changed

6 files changed

+147
-0
lines changed

provider/CONTRIBUTE.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Contribute to Terraform AzureRM provider
2+
3+
This document describe how you can get ready to contribute to the [AzureRM Terraform provider](https://github.com/terraform-providers/terraform-provider-azurerm).
4+
5+
## Setup your system
6+
7+
### Terraform
8+
9+
You need to install Terraform on your dev environment. You can downlaod it from [this page](https://www.terraform.io/downloads.html).
10+
11+
### Go tools
12+
13+
Terraform is developed using Go Programming Language. You need to install Go Programming Language **1.11.x** to be able to build and debug the provider locally.
14+
You can download it from [this page](https://golang.org/dl/) and find the installation instructions for your system [here](https://golang.org/doc/install#install)
15+
16+
Then you can test your environment following the instructions on [this page](https://golang.org/doc/install#testing).
17+
18+
### Check your environment variables
19+
20+
As with many Go project, AzureRM Terraform provider rely on your GOPATH environment variable. You may want to make sure it is well configured for your system, reading [this page](https://github.com/golang/go/wiki/SettingGOPATH).
21+
22+
### Visual Studio Code
23+
24+
You can use the IDE you love, but in this documentation we will describe how to contribute to the Terraform AzureRM provider using Visual Studio Code. You can download it for your system from [this page](https://code.visualstudio.com/Download).
25+
26+
Once installed, download the Go extension for VS Code:
27+
28+
![VS Code Go Extension](assets/ms-vscode-go.png)
29+
30+
Once installed, open VS Code and look for the `Go: Install/Update Tools` in the command palette, a select all the tools:
31+
32+
![Install Go Tools](assets/code-install-go-tools.png)
33+
34+
![Install Go Tools - All](assets/code-install-go-tools-all.png)
35+
36+
![Install Go Tools - Wait](assets/code-install-go-tools-wait.png)
37+
38+
### Specific requirements for Windows users
39+
40+
If you are running Windows, then you need to install Git Bash and Make for Windows. Check the dedicated section on Terraform on Azure repository [here](https://github.com/terraform-providers/terraform-provider-azurerm#windows-specific-requirements).
41+
42+
## Get the sources
43+
44+
First, go to the [AzureRM Terraform provider](https://github.com/terraform-providers/terraform-provider-azurerm) project page and fork the repository into your GitHub account.
45+
46+
Once done, you need to clone your fork into the `$GOPATH/src/github.com/terraform-providers/terraform-provider-azurerm` folder.
47+
48+
## Build the sources
49+
50+
You can check that everything is OK by building the AzureRM provider:
51+
52+
```bash
53+
cd $GOPATH/src/github.com/terraform-providers/terraform-provider-azurerm
54+
make build
55+
```
56+
57+
Once completed, the binary of the AzureRM provider should be available in the `$GOPATH/bin` directory.
58+
59+
*Note: on Windows, you need to use Git Bash*
60+
61+
More information [here](https://github.com/terraform-providers/terraform-provider-azurerm#developing-the-provider).
62+
63+
## Work with your local build
64+
65+
Once you have built a new version of the AzureRM Terraform provider, you can use it locally.
66+
To use your local version, the first thing to do is a `terraform init`, as usual, to inialize your terraform working directory.
67+
68+
The init operation will download the AzureRM Provider for you. You can just remove it, and replace it with your local copy.
69+
70+
Do a `terraform init` again and you're done ! :-)
71+
72+
## Debug the AzureRM provider using Visual Studio Code and Delve
73+
74+
It is possible to use Visual Studio Code and Delve (the Golang debugger) to debug the AzureRM provider.
75+
The easiest way to debug Terraform AzureRM Provider is to execute the acceptances unit test with the Delve debugger attached. Acceptance tests are tests that are written for every resources and data sources and that will really execute the code to an Azure subscription, to validate everything is working well.
76+
77+
First, to be able to connect to Azure, you need to create a service principal using the following command:
78+
79+
```bash
80+
az ad sp create-for-rbac --role=Contributor --scope=/subscriptions/<YOUR_SUBSCRIPTION_ID>
81+
```
82+
83+
Then, you need to create a `.launch.json` file inside the `.vscode` folder at the root of the Terraform AzureRM provider directory (create the `.vscode` folder if it does not exist).
84+
85+
Copy the following content into the file:
86+
87+
```json
88+
{
89+
// Use IntelliSense to learn about possible attributes.
90+
// Hover to view descriptions of existing attributes.
91+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
92+
"version": "0.2.0",
93+
"configurations": [
94+
{
95+
"name": "Launch test function",
96+
"type": "go",
97+
"request": "launch",
98+
"mode": "test",
99+
"program": "${workspaceRoot}/azurerm/resource_arm_container_registry_test.go",
100+
"args": [
101+
"-test.v",
102+
"-test.run",
103+
"TestAccAzureRMContainerRegistry_geoReplication"
104+
],
105+
"envFile": "${workspaceRoot}/.vscode/private.env",
106+
"showLog": true
107+
},
108+
]
109+
}
110+
```
111+
112+
The configuration above allows to start debugging a Terraform resource, by launching one or more acceptance test:
113+
114+
- The `program` property indicates the file you want to debug
115+
- The last entry of the `args` property, here `TestAccAzureRMContainerRegistry_geoReplication` represents th test to launch. You can use regex to run multiple tests (ex: `TestAccAzureRMContainerRegistry_*`)
116+
- The `envFile` property defines the path to get the environment variables file (mainly Azure credentials) that needs to be used to run the acceptance test.
117+
118+
Create the `private.env` file into the `.vscode` folder and fill it with the following environment variables:
119+
120+
```
121+
ARM_CLIENT_ID=<YOUR_SERVICE_PRINCIPAL_CLIENT_ID>
122+
ARM_CLIENT_SECRET=<YOUR_SERVICE_PRINCIPAL_CLIENT_SECRET>
123+
ARM_SUBSCRIPTION_ID=<YOUR_AZURE_SUBSCRIPTION_ID>
124+
ARM_TENANT_ID=<YOUR_AZURE_TENANT_ID>
125+
ARM_TEST_LOCATION=<AZURE_LOCATION_1>
126+
ARM_TEST_LOCATION_ALT=<AZURE_LOCATION_2>
127+
TF_ACC=1
128+
```
129+
130+
*Note: it is possible to customize the logging level of Terraform. It might be super useful in some situations. It can be done by setting the `TF_LOG` environment variable. Refer to [the official debugging documentation](https://www.terraform.io/docs/internals/debugging.html) for more details.*
131+
132+
Once done, you can just press F5 and the debug will start! You can place breakpoints in your code to do step by step debugging:
133+
134+
![Install Go Tools - Wait](assets/code-debug-breakpoint.png)
135+
136+
*Note: the first time your start the debug, it can take a while, you need to be patient :-)*
137+
138+
## Other
139+
140+
### Slack
141+
142+
You can request an invite to access the Terraform on Azure Slack [here](https://join.slack.com/t/terraform-azure/shared_invite/enQtNDMzNjQ5NzcxMDc3LTJkZTJhNTg3NTE5ZTdjZjFhMThmMTVmOTg5YWJkMDU1YTMzN2YyOWJmZGM3MGI4OTQ0ODQxNTEyNjdjMDAxMjM).
143+
144+
### Configuring Terraform on Windows 10 Linux Sub-System
145+
146+
It is also possible to configure Terraform to be run from the Windows 10 Linux Sub-System (WSL). Check [this blog post](https://techcommunity.microsoft.com/t5/Azure-Developer-Community-Blog/Configuring-Terraform-on-Windows-10-Linux-Sub-System/ba-p/393845) for more information.
147+
208 KB
Loading
96 KB
Loading
37.8 KB
Loading
8.75 KB
Loading

provider/assets/ms-vscode-go.png

128 KB
Loading

0 commit comments

Comments
 (0)