This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
90 lines (75 loc) · 2.8 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
locals {
environment = "${terraform.workspace == "default" ? "test" : terraform.workspace}"
}
resource "azurerm_resource_group" "ansible_management" {
name = "${var.name_prefix}-ansible-mgmt-${local.environment}-rg"
location = "${var.location}"
tags = {
Environment = "${local.environment}"
ManagedBy = "TF"
}
}
data "azurerm_subnet" "existing_subnet" {
name = "${var.existing_subnet_name}"
virtual_network_name = "${var.existing_vnet_name}"
resource_group_name = "${var.existing_rg_for_vnet}"
}
resource "azurerm_public_ip" "ansible_mgmt_public_ip" {
name = "${var.name_prefix}-ansible-mgmt-pip-${local.environment}"
resource_group_name = "${azurerm_resource_group.ansible_management.name}"
public_ip_address_allocation = "static"
location = "${var.location}"
tags = {
Environment = "${local.environment}"
ManagedBy = "TF"
}
}
resource "azurerm_network_interface" "ansible_management" {
name = "${var.name_prefix}-ansible-mgmt-${local.environment}"
resource_group_name = "${azurerm_resource_group.ansible_management.name}"
location = "${var.location}"
ip_configuration {
name = "${var.name_prefix}-ansible-ipconfig-${local.environment}"
subnet_id = "${data.azurerm_subnet.existing_subnet.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${azurerm_public_ip.ansible_mgmt_public_ip.id}"
}
tags = {
Environment = "${local.environment}"
ManagedBy = "TF"
}
}
resource "azurerm_virtual_machine" "ansible_management_node" {
name = "${var.name_prefix}-ansible-mgmt-${local.environment}"
resource_group_name = "${azurerm_resource_group.ansible_management.name}"
location = "${var.location}"
network_interface_ids = ["${azurerm_network_interface.ansible_management.id}"]
vm_size = "${var.vm_size}"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "${var.name_prefix}-ansible-mgmt-osdisk-${local.environment}"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "${var.name_prefix}-ansible-${local.environment}"
admin_username = "${var.vm_username}"
admin_password = "${var.vm_password}"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
Environment = "${local.environment}"
ManagedBy = "TF"
role = "ansible-management"
ssh_ip = "${azurerm_public_ip.ansible_mgmt_public_ip.ip_address}"
ssh_user = "${var.vm_username}"
Name = "${var.name_prefix}-ansible-${local.environment}"
}
}