Terraform: Deploy Azure Load Balancer

这篇具有很好参考价值的文章主要介绍了Terraform: Deploy Azure Load Balancer。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Deploy a Public Load Balancer

In this section, we will deploy a Public Load Balancer with Backend Pool consisting of two Azure Virtual Machines. These VMs will host a simple web page configured by using a custom script extension for Nginx web service. We will perform complete deployment using Terraform.

Public Load Balancer Lab Setup

This is how our architecture will look after the deployment is completed.

Terraform: Deploy Azure Load Balancer,Azure,terraform,azure,flask

Create and Deploy Terraform script文章来源地址https://www.toymoban.com/news/detail-844900.html

  1. Create a directory and make it as your current directory.
    mkdir load-balancer-demo
    cd load-balancer-demo
  2. Create a file named providers.tf and paste the configuration below. Here we have configured azurerm as Terraform provider for creating and managing our Azure resources.
    terraform {
      required_version = ">=0.12"

      required_providers {
        azapi = {
          source  = "azure/azapi"
          version = "~>1.5"
        }
        azurerm = {
          source  = "hashicorp/azurerm"
          version = "~>2.0"
        }
        random = {
          source  = "hashicorp/random"
          version = "~>3.0"
        }
      }
    }

    provider "azurerm" {
      features {}
    }
  3. Create a file named variables.tf and paste the configuration below. We declare all the variables that we intend to use in our Terraform deployment in the variables.tf file. You could modify the default values as per your choice or naming convention for Azure resources.
    variable "resource_group_location" {
      type        = string
      default     = "eastus"
      description = "Location of the resource group."
    }

    variable "resource_group_name" {
      type        = string
      default     = "test-group"
      description = "Name of the resource group."
    }

    variable "username" {
      type        = string
      default     = "microsoft"
      description = "The username for the local account that will be created on the new VM."
    }

    variable "password" {
      type        = string
      default     = "Microsoft@123"
      description = "The passoword for the local account that will be created on the new VM."
    }

    variable "virtual_network_name" {
      type        = string
      default     = "test-vnet"
      description = "Name of the Virtual Network."
    }

    variable "subnet_name" {
      type        = string
      default     = "test-subnet"
      description = "Name of the subnet."
    }

    variable public_ip_name {
      type        = string
      default     = "test-public-ip"
      description = "Name of the Public IP."
    }

    variable network_security_group_name {
      type        = string
      default     = "test-nsg"
      description = "Name of the Network Security Group."
    }

    variable "network_interface_name" {
      type        = string
      default     = "test-nic"
      description = "Name of the Network Interface."  
    }

    variable "virtual_machine_name" {
      type        = string
      default     = "test-vm"
      description = "Name of the Virtual Machine."
    }

    variable "virtual_machine_size" {
      type        = string
      default     = "Standard_B2s"
      description = "Size or SKU of the Virtual Machine."
    }

    variable "disk_name" {
      type        = string
      default     = "test-disk"
      description = "Name of the OS disk of the Virtual Machine."
    }

    variable "redundancy_type" {
      type        = string
      default     = "Standard_LRS"
      description = "Storage redundancy type of the OS disk."
    }

    variable "load_balancer_name" {
      type        = string
      default     = "test-lb"
      description = "Name of the Load Balancer."
    }
  4. Create a file named main.tf and paste the configuration below. The main.tf is our configuration file where we use to deploy our Azure resources.
    #Create Resource Group
    resource "azurerm_resource_group" "my_resource_group" {
      location = var.resource_group_location
      name     = var.resource_group_name
    }

    # Create Virtual Network
    resource "azurerm_virtual_network" "my_virtual_network" {
      name                = var.virtual_network_name
      address_space       = ["10.0.0.0/16"]
      location            = azurerm_resource_group.my_resource_group.location
      resource_group_name = azurerm_resource_group.my_resource_group.name
    }

    # Create a subnet in the Virtual Network
    resource "azurerm_subnet" "my_subnet" {
      name                 = var.subnet_name
      resource_group_name  = azurerm_resource_group.my_resource_group.name
      virtual_network_name = azurerm_virtual_network.my_virtual_network.name
      address_prefixes     = ["10.0.1.0/24"]
    }

    # Create Network Security Group and rules
    resource "azurerm_network_security_group" "my_nsg" {
      name                = var.network_security_group_name
      location            = azurerm_resource_group.my_resource_group.location
      resource_group_name = azurerm_resource_group.my_resource_group.na

到了这里,关于Terraform: Deploy Azure Load Balancer的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Terraform 系列-Terraform 简介

    👉 Terraform 系列文章 最近在使用 Terraform 来置备 OCI 的 Always Free Tier, 发现它非常好用。总结学习下:Terraform 的基础知识。 Terraform 是一种 基础架构即代码(IaC) 工具,可让您安全高效地构建、更改云和本地资源并对其进行 版本控制 。 HashiCorp Terraform 是一种基础架构即代码工具

    2023年04月12日
    浏览(25)
  • 【Terraform学习】Terraform_count使用(Terraform配置语言学习)

    一、简单使用:对于一些需要起多个重复的实例有用 当我们在Terraform 模板里面创建资源的时候,如果有多个重复的资源,我们可以通过count来指定个数,他会自动执行一个类似for loop的循环,然后我们可以通过count.index 来指向他每次循环的索引值。从编程的思维来理解,就是

    2024年02月12日
    浏览(27)
  • 【Terraform学习】使用 Terraform 创建Amazon VPC(Terraform-AWS最佳实战学习)

    前提条件 安装 Terraform : 地址 下载仓库代码模版 本实验代码 位于  task_vpc  文件夹中 。 变量文件  variables.tf   在上面的代码中,您将 声明 , aws_access_key , aws_secret_key 和  区域变量 。 terraform.tfvar    在上面的代码中,您将 定义变量的值 。 main.tf     在上面的代码中,

    2024年02月11日
    浏览(33)
  • 【Terraform学习】使用 Terraform创建DynamoDB添加项目(Terraform-AWS最佳实战学习)

     本站以分享各种运维经验和运维所需要的技能为主 《python》:python零基础入门学习 《shell》:shell学习 《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战 《k8》暂未更新 《docker学习》暂未更新 《ceph学习》ceph日常问题解决分享 《日志收集》ELK+各种中间件 《运

    2024年02月10日
    浏览(28)
  • 【Terraform学习】使用 Terraform 托管 S3 静态网站(Terraform-AWS最佳实战学习)

    前提条件 安装 Terraform : 地址 下载仓库代码模版 本实验代码 位于  task_s3  文件夹中 。 变量文件  variables.tf    在上面的代码中,您将 声明 , aws_access_key , aws_secret_key 和 区域变量 。 声明站点变量 ,站点的 根域和子域 。在上面的代码中 添加网站的 domain值 和 submain值

    2024年02月11日
    浏览(28)
  • 【Terraform学习】使用 Terraform创建 S3 存储桶事件(Terraform-AWS最佳实战学习)

      本站以分享各种运维经验和运维所需要的技能为主 《python》:python零基础入门学习 《shell》:shell学习 《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战 《k8》暂未更新 《docker学习》暂未更新 《ceph学习》ceph日常问题解决分享 《日志收集》ELK+各种中间件 《运

    2024年02月10日
    浏览(26)
  • 【Terraform学习】使用 Terraform 创建应用程序负载均衡器(Terraform-AWS最佳实战学习)

    前提条件 安装 Terraform : 地址 下载仓库代码模版 本实验代码 位于  task_elb  文件夹中 。 变量文件  variables.tf        在上面的代码中,您将 声明 , aws_access_key , aws_secret_key 和  区域变量 。 terraform.tfvars       在上面的代码中,您将 定义变量的值 。 main.tf        在

    2024年02月10日
    浏览(31)
  • 【Terraform学习】使用 Terraform创建Lambda函数启动EC2(Terraform-AWS最佳实战学习)

     本站以分享各种运维经验和运维所需要的技能为主 《python》:python零基础入门学习 《shell》:shell学习 《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战 《k8》暂未更新 《docker学习》暂未更新 《ceph学习》ceph日常问题解决分享 《日志收集》ELK+各种中间件 《运

    2024年02月11日
    浏览(35)
  • 【Terraform学习】保护敏感变量(Terraform配置语言学习)

    创建 EC2 IAM 角色 导航到 IAM 在 左侧菜单 中,单击 角色  。单击 创建角色 该按钮以 创建新的 IAM 角色 。 在创建角色部分,为角色选择 可信实体类型 : AWS 服务 使用案例:EC2     单击 下一步 添加权限:现在,您可以看到 策略列表 。按名称 AdministratorAccess 搜索权限并添加。

    2024年02月13日
    浏览(22)
  • 【Terraform学习】使用 Terraform 从 EC2 实例访问 S3 存储桶(Terraform-AWS最佳实战学习)

    前提条件 安装 Terraform : 地址 下载仓库代码模版 本实验代码 位于  task_ec2_s3connet  文件夹中 。 变量文件  variables.tf     在上面的代码中,您将 声明 , aws_access_key , aws_secret_key 和 区域变量 。 声明存储桶名称变量 。 terraform.tfvars   在上面的代码中,您将 定义变量的值

    2024年02月11日
    浏览(29)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包