Skip to content

Commit

Permalink
added data source Labs for AWS and Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
imrannayer committed Jun 29, 2021
1 parent 75ecada commit af569fa
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 8 deletions.
17 changes: 17 additions & 0 deletions AWS/Labs/10-data-source/A-vpc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
provider "aws" {
region = "us-east-1"
# access_key = "my-access-key"
# secret_key = "my-secret-key"
}

resource "aws_vpc" "vpc_network" {
cidr_block = "10.10.0.0/16"

tags = {
Name = "my-tf-vpc-network"
}
}

output "vpc_id" {
value = aws_vpc.vpc_network.id
}
51 changes: 51 additions & 0 deletions AWS/Labs/10-data-source/B-subnet/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
provider "aws" {
region = "us-east-1"
# access_key = "my-access-key"
# secret_key = "my-secret-key"
}

##################
# Reference Remote state file to get output values

data "aws_vpc" "vpc" {
#id = "${var.vpc_id}"
filter {
name = "tag-key"
values = ["Name"]
}
filter {
name = "tag-value"
values = ["my-tf-vpc-network"]
}
}

resource "aws_subnet" "subnet1" {
cidr_block = "10.10.1.0/24"

tags = {
Name = "my-tf-vpc-subnet1"
}

# Refer to vpc ID
vpc_id = data.aws_vpc.vpc.id
}

###########################


## Following example shows how to use terraform cidrsubnet function
## cidrsubnet(prefix, newbits, netnum)
## newbits is the number of additional bits with which to extend the prefix. For example, if given a prefix ending in /16 and a newbits value of 8, the resulting subnet address will have length /24
## netnum is a whole number that can be represented as a binary integer with no more than newbits binary digits, which will be used to populate the additional bits added to the prefix


# resource "aws_subnet" "subnet2" {
# cidr_block = cidrsubnet(data.aws_vpc.vpc.cidr_block, 8, 10)

# tags = {
# Name = "my-tf-vpc-subnet2"
# }

# # Refer to vpc ID
# vpc_id = data.aws_vpc.vpc.id
# }
8 changes: 0 additions & 8 deletions Azure/Labs/05-remote_state/A-rg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ resource "azurerm_resource_group" "rg" {
location = "southcentralus"
}

# resource "azurerm_virtual_network" "vnet" {
# name = "my-tf-vnet-network"
# location = "southcentralus"
# address_space = ["10.10.0.0/16"]

# resource_group_name = azurerm_resource_group.rg.name
# }

output rg_name {
value = azurerm_resource_group.rg.name
}
16 changes: 16 additions & 0 deletions Azure/Labs/10-data-source/A-rg/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
provider "azurerm" {
# subscription_id = "your_subscription_id"
# client_id = "your_appId"
# client_secret = "your_password"
# tenant_id = "your_tenant_id"
features {}
}

resource "azurerm_resource_group" "rg" {
name = "my-tf-rg"
location = "southcentralus"
}

output rg_name {
value = azurerm_resource_group.rg.name
}
20 changes: 20 additions & 0 deletions Azure/Labs/10-data-source/B-vnet/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
provider "azurerm" {
# subscription_id = "your_subscription_id"
# client_id = "your_appId"
# client_secret = "your_password"
# tenant_id = "your_tenant_id"
features {}
}

data "azurerm_resource_group" "rg" {
name = "my-tf-rg"
}

resource "azurerm_virtual_network" "vnet" {
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name

name = "my-tf-vnet-network"
address_space = ["10.10.0.0/16"]

}

0 comments on commit af569fa

Please sign in to comment.