How to create azure container instance using terraform
In our last?post ?we have see what is azure container instances and its features with where we can use it. Also sort demo about how to create the azure container instance from azure portal. But in real time it will be always recommended to create via some automation code. In that, lets see how to create the azure container instance via Terraform. We will be creating following flow, which will be helpful for most of the cases.
As per diagram, In this we are going to create azure files storage and then we will be proceeding to create the azure container instance.
Storage
Let’s create an Azure Storage Account, with a File share using terraform.
Below code you can find on our?github repo ?also. Here are the details for your reference.
resource "azurerm_storage_account" "aci_storage" {
name = "foxutechacistorage"
resource_group_name = var.resource_group_name
location = var.location
account_tier = "Standard"
account_replication_type = "LRS"
min_tls_version = "TLS1_2"
}
resource "azurerm_storage_share" "container_share" {
name = "aci-data"
storage_account_name = azurerm_storage_account.aci_storage.name
quota = 100
}
Please note, in this post we assumed you have?existing resource group?on azure, otherwise please create on before proceeding here. In this post “foxutech” is the resource group name.
领英推荐
Also note, in case if your organization has restriction to port 445, as per some security restriction, this will be blocked. In this your azure container may fail in private network. In this post we will be using azure, but it is always aware the possible causes. As this will be fails the container instance to mount the volume. Also please check port 443 is open, as ACI uses https to pull images, if you block that then you will soon find out that you can’t pull anything down from your registry.
Final note here is that the application in Jenkins and as all you know it uses port 8080 for application and 50000 for agent. You will see this on the terraform file.
Azure Container Instance
Okay all set now, lets see the terraform file for creating the azure container instance. Please note most of the values I have variablized and stored on variables.tf file. As this will help to avoid any changes on the main.tf file.
In this you can see the image name, instance CPU and memory, ports are described, feel free the changed as per your application need. We maynot add the environment variables and commands, as it was not needed in this use-case. If you wish to use, you can add like the port block and point it.
Continue reading on How to create azure container instance using terraform - FoxuTech