providers.tf
Check the IBM Provider page for the latest version available.
terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = "1.49.0"
}
}
}
provider "ibm" {
region = var.region
}
variables.tf
variable "prefix" {
description = "Prefix for all resources"
type = string
}
variable "region" {
description = "Region for all resources"
type = string
}
variable "resource_group" {
description = "Resource group for all resources"
type = string
}
variable "owner" {
description = "Owner of all resources"
type = string
}
variable "classic_access" {
description = "Classic access for all resources"
type = bool
default = false
}
variable "address_prefix_management" {
description = "Address prefix management for all resources"
type = string
default = "auto"
}
main.tf
locals {
zones = length(data.ibm_is_zones.regional.zones)
vpc_zones = {
for zone in range(local.zones) : zone => {
zone = "${var.region}-${zone + 1}"
}
}
tags = [
"region:${var.region}",
"owner:${var.owner}",
"tf_workspace:${terraform.workspace}"
]
}
data "ibm_is_zones" "regional" {
region = var.region
}
data "ibm_resource_group" "group" {
name = var.resource_group
}
resource "ibm_is_vpc" "vpc" {
name = "${var.prefix}-vpc"
resource_group = data.ibm_resource_group.group.id
classic_access = var.classic_access
address_prefix_management = var.address_prefix_management
default_network_acl_name = "${var.prefix}-default-acl"
default_security_group_name = "${var.prefix}-default-sg"
default_routing_table_name = "${var.prefix}-default-rt"
tags = local.tags
}