Skip to main content

Subnets

 


A few days ago, in the previous post, we saw how to create a VCN. Today we are going to see how to create a subnet.

A subnet is nothing more or less than a division of the VCN. A subnet can be contained in a single AD or be common to the entire region (recommended option).

To deploy a DB or a compute instance, it is necessary to have previously created a subnet, to place it there and to take an IP within its range. It is also important to note that within the same VCN, the IP ranges of the subnets cannot overlap.

A subnet can be public if you want to present the resources to the Internet or private if you do not. To access these resources, resources such as bastions, VPNs or Fastconnect must be used. In later posts we will go into more detail about all of these pieces in more detail.

As usual, we are going to look at different ways of creating a VCN in OCI:

  • Manually from OCI Console

Access a previously created VCN, in which we want to deploy the subnet.

In the subnet section, click on the "Create subnet" button.


Fill the required information:



  • With Terraform code
Use Infrastructure as Code to deploy it:

resource "oci_core_subnet" "test_subnet" {
    #Required
    cidr_block = var.subnet_cidr_block
    compartment_id = var.compartment_id
    vcn_id = oci_core_vcn.test_vcn.id

    #Optional
    availability_domain = var.subnet_availability_domain
    defined_tags = {"Operations.CostCenter"= "42"}
    dhcp_options_id = oci_core_dhcp_options.test_dhcp_options.id
    display_name = var.subnet_display_name
    dns_label = var.subnet_dns_label
    freeform_tags = {"Department"= "Finance"}
    ipv6cidr_block = var.subnet_ipv6cidr_block
    ipv6cidr_blocks = var.subnet_ipv6cidr_blocks
    prohibit_internet_ingress = var.subnet_prohibit_internet_ingress
    prohibit_public_ip_on_vnic = var.subnet_prohibit_public_ip_on_vnic
    route_table_id = oci_core_route_table.test_route_table.id
    security_list_ids = var.subnet_security_list_ids
}

Code obtained from the official Terraform documentation:

  • OCICLI
It is also to use the OCI API to create resources:

oci network subnet create --cidr-block [text] -c [text] --vcn-id [text]


To see all available options:



Popular posts from this blog

Infrastructure as Code

In some of the previous posts we have seen how to deploy some resources with Terraform. Terraform is an Infrastructure-as-Code (IaC) tool that allows to manage, version and maintain your infrastructure programmatically in OCI. But... What is Infrastructure as Code?   So, let's start with the concept of Infrastructure as Code (IaC). Infrastructure as Code, abbreviated as IaC, allows us to manage and provision infrastructure through code, rather than manual processes . This approach offers numerous advantages:   The first advantage is deployment automation . You won't need to manually prepare or manage operating systems, servers, storage, or any other components. Everything becomes automated.   Another benefit is the speed of implementation and deployment due to this automation.   It also reduces the risk of errors by utilizing templates for deployments and eliminating manual processes.   Lastly, using IaC ensures consistent environment crea...

Security Best Practices in Oracle Cloud Infrastructure (OCI)

  Today we are going to talk about security in OCI, indicating some Best Practices. As organizations increasingly adopt cloud technologies, ensuring robust security measures becomes paramount. Oracle Cloud Infrastructure (OCI) offers a comprehensive suite of tools and services to help secure your cloud environment. Here are some best practices to enhance your security posture on OCI. Identity and Access Management (IAM) One of the foundational elements of OCI security is Identity and Access Management (IAM). IAM allows you to control who has access to your cloud resources and what actions they can perform. Best practices include: Principle of Least Privilege: Grant users the minimum level of access necessary for their roles. Avoid assigning broad privileges like Administrator or Root unless absolutely required. Use Groups and Policies: Create groups for users with similar roles and assign policies to these groups rather than to individual users. This simplifies management and e...