Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jdubois committed Sep 12, 2023
1 parent c7cbef4 commit ad8cda5
Show file tree
Hide file tree
Showing 18 changed files with 29,327 additions and 0 deletions.
28,838 changes: 28,838 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Terraform ###
*.tfstate
*.tfstate.backup
*.tfstate.lock.info
.terraform/
41 changes: 41 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Terraform configuration

This configuration has been generated by [https://nubesgen.com/](https://nubesgen.com/).

You can regenerate it by running:

```
curl "http://localhost:8080/demo.tgz?iactool=TERRAFORM&region=westeurope&application=APP_SERVICE.basic&runtime=SPRING&database=POSTGRESQL.basic&addons=application_insights" | tar -xzvf -
```

Resources:
- [NubesGen documentation](https://docs.nubesgen.com)
- [What is NubesGen?](https://docs.nubesgen.com/what-is-nubesgen/overview/)
- [NubesGen source code on GitHub](https://github.com/microsoft/NubesGen)

## Running Terraform

[Terraform](https://www.terraform.io/) is used to automate infrastructure configuration.

As you didn't select the [NubesGen GitOps option](https://docs.nubesgen.com/gitops/gitops-quick-start/), you need to install and run Terraform manually.

Full documentation is available at [Getting started with Terraform](https://docs.nubesgen.com/getting-started/terraform/), here is a quick version:

- Install [Terraform](https://www.terraform.io/) for your platform.
- Install the [Azure CLI](https://aka.ms/nubesgen-install-az-cli) and authenticate using `az login`
- In the current directory, initialize Terraform: `terraform init`
- Apply the current Terraform configuration: `terraform apply`

Once your Terraform configuration has been applied, you can go to the [Azure Portal](https://aka.ms/nubesgen-portal) to check your resources.

## Resources

### Terraform documentation

- [Terraform Azure provider documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs)

### Azure naming conventions

- [Recommended abbreviations for Azure resource types](https://aka.ms/nubesgen-recommended-abbreviations)
- [Naming rules and restrictions for Azure resources](https://aka.ms/nubesgen-naming-rules)
- [Example names for common Azure resource types](https://aka.ms/nubesgen-caf-example-names)
70 changes: 70 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.72.0"
}
azurecaf = {
source = "aztfmod/azurecaf"
version = "1.2.26"
}
}
}

provider "azurerm" {
features {}
}

locals {
// If an environment is set up (dev, test, prod...), it is used in the application name
environment = var.environment == "" ? "dev" : var.environment
}

resource "azurecaf_name" "resource_group" {
name = var.application_name
resource_type = "azurerm_resource_group"
suffixes = [local.environment]
}

resource "azurerm_resource_group" "main" {
name = azurecaf_name.resource_group.result
location = var.location

tags = {
"terraform" = "true"
"environment" = local.environment
"application-name" = var.application_name
"nubesgen-version" = "0.16.1-SNAPSHOT"
}
}

module "application" {
source = "./modules/app-service"
resource_group = azurerm_resource_group.main.name
application_name = var.application_name
environment = local.environment
location = var.location

database_url = module.database.database_url
database_username = module.database.database_username
database_password = module.database.database_password

azure_application_insights_instrumentation_key = module.application-insights.azure_application_insights_instrumentation_key
}

module "database" {
source = "./modules/postgresql"
resource_group = azurerm_resource_group.main.name
application_name = var.application_name
environment = local.environment
location = var.location
high_availability= false
}

module "application-insights" {
source = "./modules/application-insights"
resource_group = azurerm_resource_group.main.name
application_name = var.application_name
environment = local.environment
location = var.location
}
8 changes: 8 additions & 0 deletions terraform/modules/app-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Terraform module for Azure App Service configuration

This module configures a Azure App Service instance with Terraform.

## Resources

[Azure App Service pricing](https://aka.ms/nubesgen-app-service-pricing)
[Terraform Azure App Service reference](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service)
73 changes: 73 additions & 0 deletions terraform/modules/app-service/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
terraform {
required_providers {
azurecaf = {
source = "aztfmod/azurecaf"
version = "1.2.26"
}
}
}

resource "azurecaf_name" "app_service_plan" {
name = var.application_name
resource_type = "azurerm_app_service_plan"
suffixes = [var.environment]
}

# This creates the plan that the service use
resource "azurerm_service_plan" "application" {
name = azurecaf_name.app_service_plan.result
resource_group_name = var.resource_group
location = var.location

sku_name = "B1"
os_type = "Linux"

tags = {
"environment" = var.environment
"application-name" = var.application_name
}
}

resource "azurecaf_name" "app_service" {
name = var.application_name
resource_type = "azurerm_app_service"
suffixes = [var.environment]
}

# This creates the service definition
resource "azurerm_linux_web_app" "application" {
name = azurecaf_name.app_service.result
resource_group_name = var.resource_group
location = var.location
service_plan_id = azurerm_service_plan.application.id
https_only = true

tags = {
"environment" = var.environment
"application-name" = var.application_name
}

site_config {
application_stack {
java_server = "JAVA"
java_server_version = "17"
java_version = "17"
}
always_on = true
ftps_state = "FtpsOnly"
}

app_settings = {
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false"

// Monitoring with Azure Application Insights
"APPINSIGHTS_INSTRUMENTATIONKEY" = var.azure_application_insights_instrumentation_key

# These are app specific environment variables
"SPRING_PROFILES_ACTIVE" = "prod,azure"

"SPRING_DATASOURCE_URL" = "jdbc:postgresql://${var.database_url}"
"SPRING_DATASOURCE_USERNAME" = var.database_username
"SPRING_DATASOURCE_PASSWORD" = var.database_password
}
}
14 changes: 14 additions & 0 deletions terraform/modules/app-service/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "application_url" {
value = "https://${azurerm_linux_web_app.application.default_hostname}"
description = "The Web application URL."
}

output "application_fqdn" {
value = azurerm_linux_web_app.application.default_hostname
description = "The Web application fully qualified domain name (FQDN)."
}

output "application_caf_name" {
value = azurecaf_name.app_service.result
description = "The application name generated by the Azure Cloud Adoption Framework."
}
40 changes: 40 additions & 0 deletions terraform/modules/app-service/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
variable "resource_group" {
type = string
description = "The resource group"
}

variable "application_name" {
type = string
description = "The name of your application"
}

variable "environment" {
type = string
description = "The environment (dev, test, prod...)"
default = "dev"
}

variable "location" {
type = string
description = "The Azure region where all resources in this example should be created"
}

variable "database_url" {
type = string
description = "The URL to the database"
}

variable "database_username" {
type = string
description = "The database username"
}

variable "database_password" {
type = string
description = "The database password"
}

variable "azure_application_insights_instrumentation_key" {
type = string
description = "The Azure Application Insights instrumentation key"
}
8 changes: 8 additions & 0 deletions terraform/modules/application-insights/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Terraform module for Azure Application Insights configuration

This module configures an Azure Application Insights instance with Terraform.

## Resources

[What is Azure Application Insights](https://aka.ms/nubesgen-app-insights)
[Terraform Azure Application Insights reference](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights)
26 changes: 26 additions & 0 deletions terraform/modules/application-insights/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
terraform {
required_providers {
azurecaf = {
source = "aztfmod/azurecaf"
version = "1.2.26"
}
}
}

resource "azurecaf_name" "application_insights" {
name = var.application_name
resource_type = "azurerm_application_insights"
suffixes = [var.environment]
}

resource "azurerm_application_insights" "application_insights" {
name = azurecaf_name.application_insights.result
location = var.location
resource_group_name = var.resource_group
application_type = "java"

tags = {
"environment" = var.environment
"application-name" = var.application_name
}
}
9 changes: 9 additions & 0 deletions terraform/modules/application-insights/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "azure_application_insights_instrumentation_key" {
value = azurerm_application_insights.application_insights.instrumentation_key
description = "The Azure Application Insights instrumentation key"
}

output "azure_application_insights_connection_string" {
value = azurerm_application_insights.application_insights.connection_string
description = "The Azure Application Insights connection string"
}
23 changes: 23 additions & 0 deletions terraform/modules/application-insights/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable "resource_group" {
type = string
description = "The resource group"
default = ""
}

variable "application_name" {
type = string
description = "The name of your application"
default = ""
}

variable "environment" {
type = string
description = "The environment (dev, test, prod...)"
default = "dev"
}

variable "location" {
type = string
description = "The Azure region where all resources in this example should be created"
default = ""
}
8 changes: 8 additions & 0 deletions terraform/modules/postgresql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Terraform module for PostgreSQL database configuration

This module configures a PostgreSQL database with Terraform.

## Resources

[Azure PostgreSQL Flexible Server pricing](https://azure.microsoft.com/pricing/details/postgresql/flexible-server/)
[Terraform Azure PostgreSQL Flexible Server reference](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server)
Loading

0 comments on commit ad8cda5

Please sign in to comment.