This is an automated email from the ASF dual-hosted git repository.

omartushevskyi pushed a commit to branch DLAB-1467
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/DLAB-1467 by this push:
     new e19aec1  [DLAB-1467]: Added terraform scripts for deploying DLab 
endpoint
e19aec1 is described below

commit e19aec1fa6fcb912e27d4654b37c81e2b86e91cb
Author: Oleh Martushevskyi <oleh_martushevs...@epam.com>
AuthorDate: Tue Feb 4 11:25:41 2020 +0200

    [DLAB-1467]: Added terraform scripts for deploying DLab endpoint
---
 .../terraform/azure/endpoint/main/instance.tf      | 71 ++++++++++++++++++++++
 .../terraform/azure/endpoint/main/network.tf       | 40 +++++++++++-
 .../terraform/azure/endpoint/main/outputs.tf       | 30 ++++-----
 .../terraform/azure/endpoint/main/sg.tf            | 68 +++++++++++++++++++++
 .../terraform/azure/endpoint/main/variables.tf     | 12 +++-
 5 files changed, 203 insertions(+), 18 deletions(-)

diff --git 
a/infrastructure-provisioning/terraform/azure/endpoint/main/instance.tf 
b/infrastructure-provisioning/terraform/azure/endpoint/main/instance.tf
new file mode 100644
index 0000000..546cb10
--- /dev/null
+++ b/infrastructure-provisioning/terraform/azure/endpoint/main/instance.tf
@@ -0,0 +1,71 @@
+# *****************************************************************************
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# 
******************************************************************************
+
+locals {
+  endpoint_instance_name      = 
"${var.service_base_name}-${var.endpoint_id}-endpoint"
+  endpoint_instance_disk_name = 
"${var.service_base_name}-${var.endpoint_id}-endpoint-disk"
+  endpoimt_image              = split(var.ami, "_")
+}
+
+data "tls_public_key" "enpoint_key" {
+  private_key_pem = file(var.key_path)
+}
+
+resource "azurerm_virtual_machine" "endpoint_instance" {
+  name                          = local.endpoint_instance_name
+  location                      = 
data.azurerm_resource_group.data-endpoint-resource-group.location
+  resource_group_name           = 
data.azurerm_resource_group.data-endpoint-resource-group.name
+  network_interface_ids         = azurerm_network_interface.endpoint-nif.id
+  vm_size                       = var.endpoint_instance_shape
+  delete_os_disk_on_termination = true
+
+  storage_image_reference {
+    publisher = local.endpoimt_image[0]
+    offer     = local.endpoimt_image[1]
+    sku       = local.endpoimt_image[2]
+    version   = "latest"
+  }
+  storage_os_disk {
+    os_type = "Linux"
+    name              = local.endpoint_instance_disk_name
+    create_option     = "FromImage"
+    disk_size_gb      = var.endpoint_volume_size
+    managed_disk_type = "Premium_LRS"
+  }
+  os_profile {
+    computer_name  = local.endpoint_instance_name
+    admin_username = "ubuntu"
+  }
+  os_profile_linux_config {
+    disable_password_authentication = false
+    ssh_keys {
+      key_data = data.tls_public_key.enpoint_key.public_key_openssh
+      path = "/home/${var.dlab_user_name}/.ssh/authorized_keys"
+    }
+  }
+
+  tags = {
+    Name                              = local.endpoint_instance_name
+    "${local.additional_tag[0]}"      = local.additional_tag[1]
+    "${var.tag_resource_id}"          = 
"${var.service_base_name}:${local.endpoint_instance_name}"
+    "${var.service_base_name}-Tag"    = local.endpoint_instance_name
+  }
+}
\ No newline at end of file
diff --git 
a/infrastructure-provisioning/terraform/azure/endpoint/main/network.tf 
b/infrastructure-provisioning/terraform/azure/endpoint/main/network.tf
index 7c60b10..c14be83 100644
--- a/infrastructure-provisioning/terraform/azure/endpoint/main/network.tf
+++ b/infrastructure-provisioning/terraform/azure/endpoint/main/network.tf
@@ -21,10 +21,10 @@
 
 locals {
   endpoint_subnet_name       = 
"${var.service_base_name}-${var.endpoint_id}-subnet"
-  endpoint_sg_name           = "${var.service_base_name}-${var.endpoint_id}-sg"
   endpoint_vpc_name          = "${var.service_base_name}-endpoint-vpc"
   additional_tag             = split(":", var.additional_tag)
   endpoint_ip_name           = 
"${var.service_base_name}-${var.endpoint_id}-eip"
+  endpoint_nif_name          = 
"${var.service_base_name}-${var.endpoint_id}-nif"
 }
 
 resource "azurerm_virtual_network" "endpoint-network" {
@@ -59,4 +59,40 @@ data "azurerm_subnet" "data-endpoint-subnet" {
   name                 = var.subnet_id == "" ? 
azurerm_subnet.endpoint-subnet.0.name : var.subnet_id
   virtual_network_name = 
data.azurerm_virtual_network.data-endpoint-network.name
   resource_group_name  = 
data.azurerm_resource_group.data-endpoint-resource-group.name
-}
\ No newline at end of file
+}
+
+resource "azurerm_public_ip" "endpoint-static-ip" {
+  name                = local.endpoint_ip_name
+  location            = var.region
+  resource_group_name = 
data.azurerm_resource_group.data-endpoint-resource-group.name
+  allocation_method   = "Static"
+
+  tags = {
+    Name                              = local.endpoint_ip_name
+    "${local.additional_tag[0]}"      = local.additional_tag[1]
+    "${var.tag_resource_id}"          = 
"${var.service_base_name}:${local.endpoint_ip_name}"
+    "${var.service_base_name}-Tag"    = local.endpoint_ip_name
+  }
+}
+
+resource "azurerm_network_interface" "endpoint-nif" {
+  name                      = local.endpoint_nif_name
+  location                  = 
data.azurerm_resource_group.data-endpoint-resource-group.location
+  resource_group_name       = 
data.azurerm_resource_group.data-endpoint-resource-group.name
+  network_security_group_id = azure_security_group.enpoint-sg.id
+
+  ip_configuration {
+    name                          = "configuration"
+    subnet_id                     = data.azurerm_subnet.data-endpoint-subnet.id
+    private_ip_address_allocation = "Static"
+    public_ip_address_id          = azurerm_public_ip.endpoint-static-ip.id
+    private_ip_address_version    = "IPv4"
+  }
+
+  tags = {
+    Name                              = local.endpoint_nif_name
+    "${local.additional_tag[0]}"      = local.additional_tag[1]
+    "${var.tag_resource_id}"          = 
"${var.service_base_name}:${local.endpoint_nif_name}"
+    "${var.service_base_name}-Tag"    = local.endpoint_nif_name
+  }
+}
diff --git 
a/infrastructure-provisioning/terraform/azure/endpoint/main/outputs.tf 
b/infrastructure-provisioning/terraform/azure/endpoint/main/outputs.tf
index 183c7ce..fe09d3e 100644
--- a/infrastructure-provisioning/terraform/azure/endpoint/main/outputs.tf
+++ b/infrastructure-provisioning/terraform/azure/endpoint/main/outputs.tf
@@ -19,18 +19,18 @@
 #
 # 
******************************************************************************
 
-//output "endpoint_eip_address" {
-//  value = aws_eip.endpoint_eip.public_ip
-//}
-//
-//output "subnet_id" {
-//  value = data.aws_subnet.data_subnet.id
-//}
-//
-//output "vpc_id" {
-//  value = data.aws_vpc.data_vpc.id
-//}
-//
-//output "ssn_k8s_sg_id" {
-//  value = aws_security_group.endpoint_sec_group.id
-//}
\ No newline at end of file
+output "endpoint_eip_address" {
+  value = azurerm_public_ip.endpoint-static-ip.ip_address
+}
+
+output "subnet_id" {
+  value = data.azurerm_subnet.data-endpoint-subnet.name
+}
+
+output "vpc_id" {
+  value = data.azurerm_virtual_network.data-endpoint-network.name
+}
+
+output "ssn_k8s_sg_id" {
+  value = azure_security_group.enpoint-sg.id
+}
\ No newline at end of file
diff --git a/infrastructure-provisioning/terraform/azure/endpoint/main/sg.tf 
b/infrastructure-provisioning/terraform/azure/endpoint/main/sg.tf
new file mode 100644
index 0000000..63f11c5
--- /dev/null
+++ b/infrastructure-provisioning/terraform/azure/endpoint/main/sg.tf
@@ -0,0 +1,68 @@
+# *****************************************************************************
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# 
******************************************************************************
+
+locals {
+   endpoint_sg_name = "${var.service_base_name}-${var.endpoint_id}-sg"
+}
+
+resource "azure_security_group" "enpoint-sg" {
+  name     = local.endpoint_sg_name
+  location = var.region
+}
+
+resource "azure_security_group_rule" "inbound-1" {
+  name                       = "inbound-1"
+  security_group_names       = [azure_security_group.enpoint-sg.name]
+  type                       = "Inbound"
+  action                     = "Allow"
+  priority                   = 100
+  source_address_prefix      = "*"
+  source_port_range          = "*"
+  destination_address_prefix = "*"
+  destination_port_range     = "22"
+  protocol                   = "TCP"
+}
+
+resource "azure_security_group_rule" "inbound-2" {
+  name                       = "inbound-2"
+  security_group_names       = [azure_security_group.enpoint-sg.name]
+  type                       = "Inbound"
+  action                     = "Allow"
+  priority                   = 200
+  source_address_prefix      = "*"
+  source_port_range          = "*"
+  destination_address_prefix = "*"
+  destination_port_range     = "8084"
+  protocol                   = "TCP"
+}
+
+resource "azure_security_group_rule" "outbound-1" {
+  name                       = "outbound-1"
+  security_group_names       = [azure_security_group.enpoint-sg.name]
+  type                       = "Outbound"
+  action                     = "Allow"
+  priority                   = 100
+  source_address_prefix      = "*"
+  source_port_range          = "*"
+  destination_address_prefix = "*"
+  destination_port_range     = "*"
+  protocol                   = "*"
+}
diff --git 
a/infrastructure-provisioning/terraform/azure/endpoint/main/variables.tf 
b/infrastructure-provisioning/terraform/azure/endpoint/main/variables.tf
index 1ed010d..b7b855f 100644
--- a/infrastructure-provisioning/terraform/azure/endpoint/main/variables.tf
+++ b/infrastructure-provisioning/terraform/azure/endpoint/main/variables.tf
@@ -51,4 +51,14 @@ variable "subnet_id" {
   default = ""
 }
 
-variable "subnet_cidr" {}
\ No newline at end of file
+variable "subnet_cidr" {}
+
+variable "endpoint_instance_shape" {}
+
+variable "ami" {
+  default = "Canonical_UbuntuServer_16.04-LTS"
+}
+
+variable "endpoint_volume_size" {}
+
+variable "key_path" {}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org
For additional commands, e-mail: commits-h...@dlab.apache.org

Reply via email to