Skip to content

Commit

Permalink
#11 added azureipam_reservation_cidr to allow to specify cidr to reserve
Browse files Browse the repository at this point in the history
  • Loading branch information
fnietoga committed Sep 14, 2024
1 parent ce34c6f commit e930c92
Show file tree
Hide file tree
Showing 17 changed files with 681 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
+ data resource `azureipam_blocks` to get a list of all blocks in the specified space with related information.
+ resource `azureipam_external` to allow to associate an external network to the target space and block.
+ data resource `azureipam_blocks` to get a list of all external networks associated with a space and block.
+ resource `azureipam_reservation_cidr` to allow to create reservation specifying the cidr, space and block.

### Modified (Breaking Change)
+ resource `azureipam_reservation` now allow to specify a block list. The list is evaluated in the order provider
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ data "external" "get_access_token" {
provider "azureipam" {
api_url = local.ipam_url
token = data.external.get_access_token.result.accessToken
skip_cert_verification = false
skip_cert_verification = true //ONLY recommended for development environments
}
```

Expand Down
71 changes: 71 additions & 0 deletions docs/resources/reservation_cidr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
page_title: "azureipam_reservation_cidr Resource - azureipam"
subcategory: ""
description: |-
The reservation resource allows you to create a IPAM reservation in the specific space and block with a fixed cidr.
---

# azureipam_reservation_cidr (Resource)

The reservation resource allows you to create a IPAM reservation in the specific space and block with a fixed cidr.

## Example Usage

```terraform
# Deploy the azurerm vnet
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "Australia East"
}
resource "azurerm_virtual_network" "example" {
name = "example-network"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
address_space = [azureipam_reservation_cidr.new.cidr]
tags = azureipam_reservation_cidr.new.tags ##Don't forget to add the auto-generated `X-IPAM-RES-ID` tag to the vnet.
}
# Create a CIDR reservation specifying a custom cidr
resource "azureipam_reservation_cidr" "new" {
space = "au"
block = "AustraliaEast"
specific_cidr = "10.82.4.0/24"
description = "this is a test"
}
output "created" {
value = azureipam_reservation_cidr.new
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `block` (String) List with the names of blocks in the specified space in which the reservation is to be create. The list is evaluated in the order provider. Changing this forces a new resource to be created.
- `space` (String) Name of the existing space in the IPAM application. Changing this forces a new resource to be created.

### Optional

- `description` (String) Description text that describe the reservation, that will be added as an additional tag.
- `specific_cidr` (String) The specific CIDR to reserve, in cidr notation. At least one of size or specific_cidr attribute must be specified. Not allowed if more than one block is specified.

### Read-Only

- `cidr` (String) The assigned and reserved range, in cidr notation.
- `created_by` (String) Email or identification of user that created the reservation.
- `created_on` (String) The date and time that the reservacion was created.
- `id` (String) The unique identifier of the generated reservation.
- `settled_by` (String) Email or identification of user that settled the reservation.
- `settled_on` (String) The date and time that the reservacion was settled.
- `status` (String) Status of the reservation, a 'wait' status indicates that is waiting for the related vnet creation
- `tags` (Map of String) Auto-generated tags for the reservation. Particular relevance the 'X-IPAM-RES-ID' tag, since it must be included in the vnet creation in order that the IPAM solution automatically considers the reservation as completed.

## Import

Reservations can be imported using the ID of the IPAM reservation, e.g.

```shell
terraform import azureipam_reservation_cidr.new 95s5RH8HS38Y6k37vuGLQu
```
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
terraform {
required_providers {
azureipam = {
version = "~>1.1"
version = "~>2.0"
source = "xtratuscloud/azureipam"
}
}
Expand Down
24 changes: 24 additions & 0 deletions examples/resources/azureipam_reservation_cidr/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Deploy the azurerm vnet
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "Australia East"
}
resource "azurerm_virtual_network" "example" {
name = "example-network"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name

address_space = [azureipam_reservation_cidr.new.cidr]
tags = azureipam_reservation_cidr.new.tags ##Don't forget to add the auto-generated `X-IPAM-RES-ID` tag to the vnet.
}

# Create a CIDR reservation specifying a custom cidr
resource "azureipam_reservation_cidr" "new" {
space = "au"
block = "AustraliaEast"
specific_cidr = "10.82.4.0/24"
description = "this is a test"
}
output "created" {
value = azureipam_reservation_cidr.new
}
3 changes: 2 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (p *azureIpamProvider) DataSources(ctx context.Context) []func() datasource
NewReservationsDataSource,
NewSpacesDataSource,
NewBlocksDataSource,
NewSpacesDataSource,
NewExternalsDataSource,
}
}

Expand All @@ -194,6 +194,7 @@ func (p *azureIpamProvider) Resources(ctx context.Context) []func() resource.Res
NewSpaceResource,
NewBlockResource,
NewExternalResource,
NewReservationCidrResource,
}
}

Expand Down
3 changes: 2 additions & 1 deletion internal/provider/reservation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func (r *reservationResource) Create(ctx context.Context, req resource.CreateReq
plan.Space.ValueString(),
*blocks,
plan.Description.ValueStringPointer(),
int(plan.Size.ValueInt32()),
plan.Size.ValueInt32Pointer(),
nil,
plan.ReverseSearch.ValueBool(),
plan.SmallestCidr.ValueBool(),
)
Expand Down
Loading

0 comments on commit e930c92

Please sign in to comment.