-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify terraform configuration #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,45 @@ | ||
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII) | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
} | ||
sops = { | ||
source = "carlpett/sops" | ||
} | ||
} | ||
} | ||
provider "azurerm" { | ||
features {} | ||
} | ||
# Sops secrets | ||
data "sops_file" "ghaf_infra" { | ||
source_file = "secrets.yaml" | ||
} | ||
# Backend for storing tfstate (see ./azure-storage) | ||
terraform { | ||
backend "azurerm" { | ||
resource_group_name = "ghaf-infra-storage" | ||
storage_account_name = "ghafinfrastatestorage" | ||
container_name = "ghaf-infra-tfstate-container" | ||
key = "ghaf-infra.tfstate" | ||
} | ||
} | ||
# Resource group | ||
resource "azurerm_resource_group" "ghaf_infra_tf_dev" { | ||
name = "ghaf-infra-tf-dev" | ||
location = var.resource_group_location | ||
location = "swedencentral" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to add this hardcoding now? Before long we need this configurable (for the uae deployment). |
||
} | ||
# Create VN | ||
# Virtual Network | ||
resource "azurerm_virtual_network" "ghaf_infra_tf_vnet" { | ||
name = "ghaf-infra-tf-vnet" | ||
address_space = ["10.0.0.0/16"] | ||
location = var.resource_group_location | ||
location = azurerm_resource_group.ghaf_infra_tf_dev.location | ||
resource_group_name = azurerm_resource_group.ghaf_infra_tf_dev.name | ||
} | ||
# Create Subnet | ||
# Subnet | ||
resource "azurerm_subnet" "ghaf_infra_tf_subnet" { | ||
name = "ghaf-infra-tf-subnet" | ||
resource_group_name = azurerm_resource_group.ghaf_infra_tf_dev.name | ||
|
@@ -23,7 +49,7 @@ resource "azurerm_subnet" "ghaf_infra_tf_subnet" { | |
# Network interface | ||
resource "azurerm_network_interface" "ghaf_infra_tf_network_interface" { | ||
name = "ghaf-infratf286-z1" | ||
location = var.resource_group_location | ||
location = azurerm_resource_group.ghaf_infra_tf_dev.location | ||
resource_group_name = azurerm_resource_group.ghaf_infra_tf_dev.name | ||
ip_configuration { | ||
name = "my_nic_configuration" | ||
|
@@ -32,25 +58,25 @@ resource "azurerm_network_interface" "ghaf_infra_tf_network_interface" { | |
public_ip_address_id = azurerm_public_ip.ghaf_infra_tf_public_ip.id | ||
} | ||
} | ||
# Create Availability Set | ||
# Availability Set | ||
resource "azurerm_availability_set" "ghaf_infra_tf_availability_set" { | ||
name = "ghaf-infra-tf-availability-set" | ||
location = var.resource_group_location | ||
location = azurerm_resource_group.ghaf_infra_tf_dev.location | ||
resource_group_name = azurerm_resource_group.ghaf_infra_tf_dev.name | ||
platform_fault_domain_count = 2 | ||
platform_update_domain_count = 2 | ||
} | ||
# Create Public IPs | ||
# Public IPs | ||
resource "azurerm_public_ip" "ghaf_infra_tf_public_ip" { | ||
name = "ghaf-infra-tf-public-ip" | ||
location = var.resource_group_location | ||
location = azurerm_resource_group.ghaf_infra_tf_dev.location | ||
resource_group_name = azurerm_resource_group.ghaf_infra_tf_dev.name | ||
allocation_method = "Dynamic" | ||
} | ||
# Create Network Security Group and rule | ||
# Network Security Group and Rule | ||
resource "azurerm_network_security_group" "ghaf_infra_tf_nsg" { | ||
name = "ghaf-infra-tf-nsg" | ||
location = var.resource_group_location | ||
location = azurerm_resource_group.ghaf_infra_tf_dev.location | ||
resource_group_name = azurerm_resource_group.ghaf_infra_tf_dev.name | ||
security_rule { | ||
name = "SSH" | ||
|
@@ -64,10 +90,10 @@ resource "azurerm_network_security_group" "ghaf_infra_tf_nsg" { | |
destination_address_prefix = "*" | ||
} | ||
} | ||
# Create Linux Virtual Machine | ||
# Example Linux Virtual Machine | ||
resource "azurerm_linux_virtual_machine" "ghafinfra_tf" { | ||
name = "ghafinfratf" | ||
location = var.resource_group_location | ||
location = azurerm_resource_group.ghaf_infra_tf_dev.location | ||
resource_group_name = azurerm_resource_group.ghaf_infra_tf_dev.name | ||
availability_set_id = azurerm_availability_set.ghaf_infra_tf_availability_set.id | ||
network_interface_ids = [ | ||
|
@@ -86,11 +112,12 @@ resource "azurerm_linux_virtual_machine" "ghafinfra_tf" { | |
sku = "22_04-lts-gen2" | ||
version = "latest" | ||
} | ||
admin_username = "karim" | ||
admin_username = data.sops_file.ghaf_infra.data["vm_admin_name"] | ||
disable_password_authentication = true | ||
admin_ssh_key { | ||
username = "karim" | ||
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDe5L8iOqhNPsYz5eh9Bz/URYguG60JjMGmKG0wwLIb6Gf2M8Txzk24ESGbMR/F5RYsV1yWYOocL47ngDWQIbO6MGJ7ftUr7slWoUA/FSVwh/jsG681mRqIuJXjKM/YQhBkI9k6+eVxRfLDTs5XZfbwdm7T4aP8ZI2609VY0guXfa/F7DSE1BxN7IJMn0CWLQJanBpoYUxqyQXCUXgljMokdPjTrqAxlBluMsVTP+ZKDnjnpHcVE/hCKk5BxaU6K97OdeIOOEWXAd6uEHssomjtU7+7dhiZzjhzRPKDiSJDF9qtIw50kTHz6ZTdH8SAZmu0hsS6q8OmmDTAnt24dFJV karim@nixos" | ||
username = data.sops_file.ghaf_infra.data["vm_admin_name"] | ||
# Azure requires RSA keys: | ||
# https://learn.microsoft.com/troubleshoot/azure/virtual-machines/ed25519-ssh-keys | ||
public_key = data.sops_file.ghaf_infra.data["vm_admin_rsa_pub"] | ||
} | ||
|
||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Earlier change added "/" to the end of 'cd' command, this one drops it. Make those consistent.