Skip to content

Commit 9da54ad

Browse files
authored
Chore: install terraform in devcontainer (#3417)
2 parents 71354ef + 195fae4 commit 9da54ad

9 files changed

Lines changed: 36 additions & 27 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM benefits_client:latest
22

3+
# should match the version specified in terraform/pipeline/deploy.yml
4+
ENV TF_VERSION="1.13.4"
5+
36
USER root
47

58
# install apt packages using the archives and lists cache
@@ -10,7 +13,13 @@ RUN --mount=type=cache,id=apt-archives,sharing=locked,target=/var/cache/apt/arch
1013
curl -sL https://aka.ms/InstallAzureCLIDeb | bash && \
1114
# install webp CLI
1215
# https://developers.google.com/speed/webp/download
13-
apt install locales webp -y
16+
apt install locales webp -y && \
17+
# install Terraform
18+
# https://developer.hashicorp.com/terraform/tutorials/docker-get-started/install-cli#install-terraform
19+
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip && \
20+
unzip terraform_${TF_VERSION}_linux_amd64.zip && \
21+
chmod +x terraform && \
22+
mv terraform /usr/local/bin/
1423

1524
# VSCode will use en_US for git operations, so make it available in the container
1625
# https://github.com/microsoft/vscode/pull/210506

.vscode/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
"python.testing.pytestEnabled": true,
2525
"python.testing.unittestEnabled": false,
2626
"[terraform]": {
27-
"editor.defaultFormatter": "hashicorp.terraform"
27+
"editor.defaultFormatter": "hashicorp.terraform",
28+
"editor.formatOnSave": true
2829
},
2930
"[terraform-vars]": {
30-
"editor.defaultFormatter": "hashicorp.terraform"
31+
"editor.defaultFormatter": "hashicorp.terraform",
32+
"editor.formatOnSave": true
3133
},
3234
"workbench.editorAssociations": {
3335
"*.db": "sqlite-viewer.option"

docs/explanation/infrastructure.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,14 @@ Use the following shorthand for conveying the Resource Type as part of the Resou
147147
### Set up for local development
148148

149149
1. [Get access to the Azure account through the DevSecOps team.](#getting-started)
150-
1. Install dependencies:
151-
152-
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
153-
- [Terraform](https://www.terraform.io/downloads) - see exact version in [`deploy.yml`](https://github.com/cal-itp/benefits/blob/main/terraform/pipeline/deploy.yml)
154-
150+
1. Rebuild and launch the [dev container](development/README.md)
151+
1. Navigate to the [`terraform/`](https://github.com/cal-itp/benefits/tree/main/terraform) directory.
155152
1. [Authenticate using the Azure CLI](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/azure_cli).
156153

157154
```sh
158155
az login
159156
```
160157

161-
1. Outside the [dev container](development/README.md), navigate to the [`terraform/`](https://github.com/cal-itp/benefits/tree/main/terraform) directory.
162158
1. [Initialize Terraform.](https://www.terraform.io/cli/commands/init) You can also use this script later to switch between [environments](#environments).
163159

164160
```sh
@@ -181,7 +177,8 @@ When configuration changes to infrastructure resources are needed, they should b
181177
1. [Submit the changes via pull request.](development/commits-branches-merging.md)
182178

183179
!!! info "Azure tags"
184-
For Azure resources, you need to [ignore changes](https://www.terraform.io/language/meta-arguments/lifecycle#ignore_changes) to tags, since they are [automatically created by an Azure Policy managed by CDT](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-policies).
180+
181+
For Azure resources, you need to [ignore changes](https://www.terraform.io/language/meta-arguments/lifecycle#ignore_changes) to tags, since they are [automatically created by an Azure Policy managed by CDT](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-policies).
185182

186183
```hcl
187184
lifecycle {

terraform/.terraform.lock.hcl

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[Documentation](https://docs.calitp.org/benefits/deployment/infrastructure/)
1+
[Documentation](https://docs.calitp.org/benefits/explanation/infrastructure/)

terraform/app_service.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ resource "azurerm_linux_web_app" "main" {
2323
virtual_network_subnet_id = local.subnet_id
2424

2525
site_config {
26-
ftps_state = "Disabled"
27-
vnet_route_all_enabled = true
26+
ftps_state = "Disabled"
27+
vnet_route_all_enabled = true
2828

2929
# https://github.com/hashicorp/terraform-provider-azurerm/issues/25244
30-
ip_restriction_default_action = "Allow"
31-
scm_ip_restriction_default_action = "Allow"
30+
ip_restriction_default_action = "Allow"
31+
scm_ip_restriction_default_action = "Allow"
3232
}
3333

3434
identity {

terraform/email.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ locals {
77
# Determine the correct sender domain based on the environment.
88
# If is_prod is true, use the custom domain; otherwise, use the Azure-managed domain.
99
sender_domain = local.is_prod ? azurerm_email_communication_service_domain.custom[0].mail_from_sender_domain : azurerm_email_communication_service_domain.azure_managed[0].mail_from_sender_domain
10-
sender_email = "DoNotReply@${local.sender_domain}"
10+
sender_email = "DoNotReply@${local.sender_domain}"
1111
}
1212

1313
resource "azurerm_key_vault_secret" "azure_communication_connection_string" {

terraform/environment.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
locals {
2-
is_prod = terraform.workspace == "default"
3-
is_test = terraform.workspace == "test"
4-
is_dev = !(local.is_prod || local.is_test)
5-
env_name = local.is_prod ? "prod" : terraform.workspace
6-
env_letter = upper(substr(local.env_name, 0, 1))
7-
hostname = local.is_prod ? "benefits.calitp.org" : "${local.env_name}-benefits.calitp.org"
8-
secret_prefix = "@Microsoft.KeyVault(VaultName=KV-CDT-PUB-CALITP-${local.env_letter}-001;SecretName="
2+
is_prod = terraform.workspace == "default"
3+
is_test = terraform.workspace == "test"
4+
is_dev = !(local.is_prod || local.is_test)
5+
env_name = local.is_prod ? "prod" : terraform.workspace
6+
env_letter = upper(substr(local.env_name, 0, 1))
7+
hostname = local.is_prod ? "benefits.calitp.org" : "${local.env_name}-benefits.calitp.org"
8+
secret_prefix = "@Microsoft.KeyVault(VaultName=KV-CDT-PUB-CALITP-${local.env_letter}-001;SecretName="
99
}
1010

1111
data "azurerm_resource_group" "main" {

terraform/storage.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ resource "azurerm_backup_policy_file_share" "policy" {
6565
}
6666

6767
resource "azurerm_storage_share" "data" {
68-
name = "benefits-data"
69-
storage_account_id = azurerm_storage_account.main.id
70-
quota = 5
71-
enabled_protocol = "SMB"
68+
name = "benefits-data"
69+
storage_account_id = azurerm_storage_account.main.id
70+
quota = 5
71+
enabled_protocol = "SMB"
7272
acl {
7373
id = "benefits-data-rwdl"
7474
access_policy {

0 commit comments

Comments
 (0)