Skip to content

Commit

Permalink
chore: tf state (#47)
Browse files Browse the repository at this point in the history
* chore: tf state

* fix: ci
  • Loading branch information
eugbyte authored Sep 22, 2024
1 parent ec9bde8 commit 89cf0ff
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 20 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
branches:
- main

permissions:
id-token: write
contents: read

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -65,16 +69,25 @@ jobs:
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Validate Azure CLI can be used
run: az --version
- name: Terraform validate and plan
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
- name: Terraform validate
run: |
cd infra/Terraform
terraform init
terraform validate
- name: Terraform plan
run: |
cd infra/Terraform
terraform plan
# Apply step can be skipped for pull requests
- name: Terraform apply
if: github.ref == 'refs/heads/main'
run: cd infra/Terraform && terraform apply -auto-approve
run: cd infra/Terraform && terraform apply -auto-approve
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ through the locations so save on delivery cost, stopping at common collection po
Regardless, I think it is still an idea worth exploring.</sub>

## Live demo
[Store on Wheels website](https://ca-storeonwheels-prod-sea.wittymushroom-fed3288b.southeastasia.azurecontainerapps.io)
[Store on Wheels website](https://ca-storeonwheels-prod-sea--mqygmr1.wittymushroom-fed3288b.southeastasia.azurecontainerapps.io)

The loading time may be slow as the container app is on a free tier and subjected to cold starts.
The loading time may be slow as the container app is on the cheapest tier and subjected to cold starts.

## Preview locally
`make start`
Expand Down
26 changes: 13 additions & 13 deletions infra/Terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions infra/Terraform/azure-storage.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Create a Storage account
resource "azurerm_storage_account" "terraform_state" {
name = "ststoreonwheelsprodsea"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"

tags = {
environment = "my-terraform-env"
}
}

# Create a Storage container
resource "azurerm_storage_container" "terraform_state" {
name = "stc-storeonwheels-prod-sea"
storage_account_name = azurerm_storage_account.terraform_state.name
container_access_type = "private"
}
2 changes: 1 addition & 1 deletion infra/Terraform/container-app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ resource "azurerm_container_app" "app" {
traffic_weight {
latest_revision = true
# ws connection not distributed to message queues yet, so it has to be 100%
percentage = 100
percentage = 100
}
}
}
8 changes: 8 additions & 0 deletions infra/Terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ terraform {
version = "=3.52.0"
}
}
# comment out when needing to initialize the storage account for the first time to start the .tfstate
backend "azurerm" {
resource_group_name = "rg-storeonwheels-prod-sea"
storage_account_name = "ststoreonwheelsprodsea"
container_name = "stc-storeonwheels-prod-sea"
key = "terraform.tfstate"
}
}

provider "azurerm" {
Expand All @@ -16,6 +23,7 @@ resource "azurerm_resource_group" "rg" {
name = "rg-storeonwheels-prod-sea"
location = "Southeast Asia"
}

resource "azurerm_log_analytics_workspace" "analytics" {
name = "log-storeonwheels-prod-sea"
location = azurerm_resource_group.rg.location
Expand Down

0 comments on commit 89cf0ff

Please sign in to comment.