Skip to content

Commit 7673610

Browse files
committed
feat: starterkit for azure vm
1 parent b084f47 commit 7673610

File tree

10 files changed

+507
-20
lines changed

10 files changed

+507
-20
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Azure Virtual Machine Starterkit Backplane
2+
3+
There is no terraform for starterkit backplane.
4+
5+
You need to manually create an API Key in meshStack and fill in the variables in the imported definition.
6+
7+
## How to create an API Key
8+
9+
> **Note**: you need to have Organization Admin permission in meshStack to create an API Key with admin rights.
10+
11+
1. In the Admin Area, go to "Access Control" > "API Keys"
12+
2. Create a new API Key with the required permissions for managing:
13+
- Projects
14+
- Tenants
15+
- Building Blocks
16+
3. Copy the key ID to MESHSTACK_API_KEY and secret to MESHSTACK_API_SECRET
17+
18+
## Required Building Block Definitions
19+
20+
This starterkit requires the following building block definition to be configured in your meshStack:
21+
22+
1. **Azure Virtual Machine Building Block**: The actual VM provisioning building block
23+
- Ensure it's configured to work with your Azure platform
24+
- Note the definition version UUID for the starterkit configuration
25+
26+
## Configuration
27+
28+
When configuring the starterkit as a building block definition in meshStack:
29+
30+
1. Set the appropriate platform support (Azure)
31+
2. Configure all required input variables
32+
3. Link to the correct Azure VM building block definition
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
name: Azure Virtual Machine Starterkit
3+
supportedPlatforms:
4+
- azure
5+
description: |
6+
The Azure Virtual Machine Starterkit provides application teams with a pre-configured Azure environment. It includes a dedicated project, an Azure tenant, and a virtual machine for quick provisioning and testing.
7+
---
8+
9+
# Azure Virtual Machine Starterkit Building Block
10+
11+
This documentation is intended as a reference documentation for cloud foundation or platform engineers using this module.
12+
13+
## Overview
14+
15+
The Azure VM Starterkit building block automates the creation of a complete Azure virtual machine environment including:
16+
17+
- **meshStack Project**: A dedicated project for organizing and managing the VM resources
18+
- **Azure Tenant**: An Azure subscription tenant configured with the specified landing zone
19+
- **Virtual Machine Building Block**: Automatically deploys an Azure VM with chosen specifications
20+
21+
## Features
22+
23+
- Single unified project (no dev/prod separation)
24+
- Flexible VM configuration (Linux or Windows)
25+
- Optional public IP assignment
26+
- Automatic project admin assignment for the creator
27+
- Customizable project tags
28+
29+
## Use Cases
30+
31+
- Quick VM provisioning for development or testing
32+
- Sandbox environments for experimentation
33+
- Training and learning environments
34+
- Proof-of-concept workloads
35+
- CI/CD build agents
36+
37+
<!-- BEGIN_TF_DOCS -->
38+
## Requirements
39+
40+
| Name | Version |
41+
|------|---------|
42+
| <a name="requirement_meshstack"></a> [meshstack](#requirement\_meshstack) | 0.9.0 |
43+
44+
## Modules
45+
46+
No modules.
47+
48+
## Resources
49+
50+
| Name | Type |
51+
|------|------|
52+
| [meshstack_building_block_v2.azure_vm](https://registry.terraform.io/providers/meshcloud/meshstack/0.9.0/docs/resources/building_block_v2) | resource |
53+
| [meshstack_project.vm_project](https://registry.terraform.io/providers/meshcloud/meshstack/0.9.0/docs/resources/project) | resource |
54+
| [meshstack_project_user_binding.creator_admin](https://registry.terraform.io/providers/meshcloud/meshstack/0.9.0/docs/resources/project_user_binding) | resource |
55+
| [meshstack_tenant_v4.vm_tenant](https://registry.terraform.io/providers/meshcloud/meshstack/0.9.0/docs/resources/tenant_v4) | resource |
56+
57+
## Inputs
58+
59+
| Name | Description | Type | Default | Required |
60+
|------|-------------|------|---------|:--------:|
61+
| <a name="input_azure_vm_definition_version_uuid"></a> [azure\_vm\_definition\_version\_uuid](#input\_azure\_vm\_definition\_version\_uuid) | UUID of the Azure Virtual Machine building block definition version. | `string` | n/a | yes |
62+
| <a name="input_creator"></a> [creator](#input\_creator) | Information about the creator of the resources who will be assigned Project Admin role | <pre>object({<br> type = string<br> identifier = string<br> displayName = string<br> username = optional(string)<br> email = optional(string)<br> euid = optional(string)<br> })</pre> | n/a | yes |
63+
| <a name="input_full_platform_identifier"></a> [full\_platform\_identifier](#input\_full\_platform\_identifier) | Full platform identifier of the Azure platform. | `string` | n/a | yes |
64+
| <a name="input_landing_zone_identifier"></a> [landing\_zone\_identifier](#input\_landing\_zone\_identifier) | Azure Landing zone identifier for the tenant. | `string` | n/a | yes |
65+
| <a name="input_name"></a> [name](#input\_name) | This name will be used for the created project and VM | `string` | n/a | yes |
66+
| <a name="input_project_tags_yaml"></a> [project\_tags\_yaml](#input\_project\_tags\_yaml) | YAML configuration for project tags. Expected structure:<pre>yaml<br>key1:<br> - "value1"<br> - "value2"<br>key2:<br> - "value3"</pre> | `string` | `"{}"` | no |
67+
| <a name="input_vm_admin_password"></a> [vm\_admin\_password](#input\_vm\_admin\_password) | The admin password for Windows VM (required for Windows). | `string` | `null` | no |
68+
| <a name="input_vm_admin_username"></a> [vm\_admin\_username](#input\_vm\_admin\_username) | The admin username for the VM. | `string` | `"azureuser"` | no |
69+
| <a name="input_vm_enable_public_ip"></a> [vm\_enable\_public\_ip](#input\_vm\_enable\_public\_ip) | Whether to create and assign a public IP address to the VM. | `bool` | `false` | no |
70+
| <a name="input_vm_location"></a> [vm\_location](#input\_vm\_location) | The Azure region where the VM will be deployed. | `string` | `"westeurope"` | no |
71+
| <a name="input_vm_os_type"></a> [vm\_os\_type](#input\_vm\_os\_type) | The operating system type (Linux or Windows). | `string` | `"Linux"` | no |
72+
| <a name="input_vm_size"></a> [vm\_size](#input\_vm\_size) | The size of the virtual machine. | `string` | `"Standard_B1s"` | no |
73+
| <a name="input_vm_ssh_public_key"></a> [vm\_ssh\_public\_key](#input\_vm\_ssh\_public\_key) | SSH public key for Linux VM authentication (required for Linux). | `string` | `null` | no |
74+
| <a name="input_workspace_identifier"></a> [workspace\_identifier](#input\_workspace\_identifier) | The identifier of the meshStack workspace | `string` | n/a | yes |
75+
76+
## Outputs
77+
78+
| Name | Description |
79+
|------|-------------|
80+
| <a name="output_project_name"></a> [project\_name](#output\_project\_name) | Name of the created meshStack project |
81+
| <a name="output_summary"></a> [summary](#output\_summary) | Summary with next steps and insights into created resources |
82+
| <a name="output_tenant_uuid"></a> [tenant\_uuid](#output\_tenant\_uuid) | UUID of the created Azure tenant |
83+
| <a name="output_vm_building_block_uuid"></a> [vm\_building\_block\_uuid](#output\_vm\_building\_block\_uuid) | UUID of the Azure VM building block |
84+
<!-- END_TF_DOCS -->
85+
86+
## Configuration Examples
87+
88+
### Basic Linux VM
89+
90+
```hcl
91+
module "vm_starterkit" {
92+
source = "./modules/azure/azure-virtual-machine/starterkit/buildingblock"
93+
94+
workspace_identifier = "my-workspace"
95+
name = "my-dev-vm"
96+
full_platform_identifier = "azure.my-platform"
97+
landing_zone_identifier = "my-landing-zone"
98+
99+
# Building block UUID (obtain from your meshStack setup)
100+
azure_vm_definition_version_uuid = "..."
101+
102+
creator = {
103+
type = "User"
104+
identifier = "user123"
105+
displayName = "John Doe"
106+
username = "jdoe"
107+
}
108+
109+
vm_os_type = "Linux"
110+
vm_size = "Standard_B2s"
111+
vm_location = "westeurope"
112+
vm_ssh_public_key = file("~/.ssh/id_rsa.pub")
113+
vm_enable_public_ip = true
114+
}
115+
```
116+
117+
### Windows VM
118+
119+
```hcl
120+
module "vm_starterkit" {
121+
source = "./modules/azure/azure-virtual-machine/starterkit/buildingblock"
122+
123+
workspace_identifier = "my-workspace"
124+
name = "my-win-vm"
125+
full_platform_identifier = "azure.my-platform"
126+
landing_zone_identifier = "my-landing-zone"
127+
128+
# Building block UUID
129+
azure_vm_definition_version_uuid = "..."
130+
131+
creator = {
132+
type = "User"
133+
identifier = "user456"
134+
displayName = "Jane Smith"
135+
username = "jsmith"
136+
}
137+
138+
vm_os_type = "Windows"
139+
vm_size = "Standard_D2s_v3"
140+
vm_location = "northeurope"
141+
vm_admin_password = var.windows_admin_password
142+
vm_enable_public_ip = true
143+
}
144+
```
145+
146+
## Notes
147+
148+
- The resource group will be automatically created by the Azure VM building block
149+
- Ensure SSH public key is provided for Linux VMs
150+
- Ensure admin password is provided for Windows VMs
151+
- Public IP is disabled by default for security
152+
- Project tags can be customized using YAML format
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
locals {
2+
# Create a purely alphanumeric identifier from the display name
3+
# Remove special characters, convert to lowercase, and replace spaces/hyphens with nothing
4+
identifier = lower(replace(replace(var.name, "/[^a-zA-Z0-9\\s\\-\\_]/", ""), "/[\\s\\-\\_]+/", "-"))
5+
6+
# Decode project tags YAML configuration
7+
project_tags_config = yamldecode(var.project_tags_yaml)
8+
}
9+
10+
resource "meshstack_project" "vm_project" {
11+
metadata = {
12+
name = local.identifier
13+
owned_by_workspace = var.workspace_identifier
14+
}
15+
spec = {
16+
display_name = var.name
17+
tags = local.project_tags_config
18+
}
19+
}
20+
21+
resource "meshstack_project_user_binding" "creator_admin" {
22+
count = var.creator.type == "User" && var.creator.username != null ? 1 : 0
23+
24+
metadata = {
25+
name = uuid()
26+
}
27+
28+
role_ref = {
29+
name = "Project Admin"
30+
}
31+
32+
target_ref = {
33+
owned_by_workspace = var.workspace_identifier
34+
name = meshstack_project.vm_project.metadata.name
35+
}
36+
37+
subject = {
38+
name = var.creator.username
39+
}
40+
}
41+
42+
resource "meshstack_tenant_v4" "vm_tenant" {
43+
metadata = {
44+
owned_by_workspace = var.workspace_identifier
45+
owned_by_project = meshstack_project.vm_project.metadata.name
46+
}
47+
48+
spec = {
49+
platform_identifier = var.full_platform_identifier
50+
landing_zone_identifier = var.landing_zone_identifier
51+
}
52+
}
53+
54+
resource "meshstack_building_block_v2" "azure_vm" {
55+
spec = {
56+
building_block_definition_version_ref = {
57+
uuid = var.azure_vm_definition_version_uuid
58+
}
59+
target_ref = {
60+
kind = "meshTenant"
61+
uuid = meshstack_tenant_v4.vm_tenant.metadata.uuid
62+
}
63+
display_name = "Azure Virtual Machine"
64+
inputs = {
65+
vm_name = {
66+
value_string = local.identifier
67+
}
68+
location = {
69+
value_string = var.vm_location
70+
}
71+
os_type = {
72+
value_string = var.vm_os_type
73+
}
74+
vm_size = {
75+
value_string = var.vm_size
76+
}
77+
admin_username = {
78+
value_string = var.vm_admin_username
79+
}
80+
enable_public_ip = {
81+
value_bool = var.vm_enable_public_ip
82+
}
83+
ssh_public_key = {
84+
value_string = var.vm_os_type == "Linux" ? var.vm_ssh_public_key : null
85+
}
86+
admin_password = {
87+
value_string = var.vm_os_type == "Windows" ? var.vm_admin_password : null
88+
}
89+
}
90+
}
91+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
output "project_name" {
2+
description = "Name of the created meshStack project"
3+
value = meshstack_project.vm_project.metadata.name
4+
}
5+
6+
output "tenant_uuid" {
7+
description = "UUID of the created Azure tenant"
8+
value = meshstack_tenant_v4.vm_tenant.metadata.uuid
9+
}
10+
11+
output "vm_building_block_uuid" {
12+
description = "UUID of the Azure VM building block"
13+
value = meshstack_building_block_v2.azure_vm.metadata.uuid
14+
}
15+
16+
output "summary" {
17+
description = "Summary with next steps and insights into created resources"
18+
value = <<-EOT
19+
# Azure Virtual Machine Starter Kit
20+
21+
✅ **Your environment is ready!**
22+
23+
This starter kit has set up the following resources in workspace `${var.workspace_identifier}`:
24+
25+
@project[${meshstack_project.vm_project.metadata.owned_by_workspace}.${meshstack_project.vm_project.metadata.name}]\
26+
&nbsp;&nbsp;&nbsp;&nbsp;@tenant[${meshstack_tenant_v4.vm_tenant.metadata.uuid}]\
27+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@buildingblock[${meshstack_building_block_v2.azure_vm.metadata.uuid}]
28+
29+
---
30+
31+
## What's Included
32+
33+
- **Azure Project**: A dedicated project for your virtual machine resources
34+
- **Azure Tenant**: An Azure subscription tenant with your chosen landing zone
35+
- **Virtual Machine**: ${var.vm_os_type} VM (${var.vm_size}) in ${var.vm_location}
36+
37+
---
38+
39+
## VM Details
40+
41+
- **VM Name**: ${local.identifier}
42+
- **Operating System**: ${var.vm_os_type}
43+
- **Size**: ${var.vm_size}
44+
- **Region**: ${var.vm_location}
45+
- **Public IP**: ${var.vm_enable_public_ip ? "Enabled" : "Disabled"}
46+
- **Admin Username**: ${var.vm_admin_username}
47+
48+
---
49+
50+
## Next Steps
51+
52+
### 1. Access Your VM
53+
${var.vm_os_type == "Linux" && var.vm_enable_public_ip ? "- Connect via SSH using your provided SSH key" : ""}
54+
${var.vm_os_type == "Windows" && var.vm_enable_public_ip ? "- Connect via RDP using the admin credentials" : ""}
55+
${!var.vm_enable_public_ip ? "- Connect through Azure Bastion or VPN (no public IP assigned)" : ""}
56+
57+
### 2. View Azure Resources
58+
- [Access Azure Tenant](/#/w/${var.workspace_identifier}/p/${meshstack_project.vm_project.metadata.name}/i/${var.full_platform_identifier}/overview)
59+
60+
### 3. Manage Project Access
61+
- Invite team members via meshStack:
62+
- [Project Access Management](/#/w/${var.workspace_identifier}/p/${meshstack_project.vm_project.metadata.name}/access-management/role-mapping/overview)
63+
64+
---
65+
66+
## Security Recommendations
67+
68+
1. **SSH Keys**: Rotate SSH keys regularly if using Linux
69+
2. **Network Access**: Review NSG rules and restrict access as needed
70+
3. **Updates**: Keep your VM updated with latest security patches
71+
4. **Monitoring**: Enable Azure Monitor for VM performance and health tracking
72+
73+
---
74+
75+
🎉 Your Azure VM is ready to use!
76+
EOT
77+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
provider "meshstack" {}

0 commit comments

Comments
 (0)