Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Resource: azurerm_express_route_circuit_authorization #992

Merged
merged 2 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ type ArmClient struct {
// Networking
applicationGatewayClient network.ApplicationGatewaysClient
applicationSecurityGroupsClient network.ApplicationSecurityGroupsClient
expressRouteAuthsClient network.ExpressRouteCircuitAuthorizationsClient
expressRouteCircuitClient network.ExpressRouteCircuitsClient
ifaceClient network.InterfacesClient
loadBalancerClient network.LoadBalancersClient
Expand Down Expand Up @@ -688,6 +689,10 @@ func (c *ArmClient) registerNetworkingClients(endpoint, subscriptionId string, a
c.configureClient(&appSecurityGroupsClient.Client, auth)
c.applicationSecurityGroupsClient = appSecurityGroupsClient

expressRouteAuthsClient := network.NewExpressRouteCircuitAuthorizationsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&expressRouteAuthsClient.Client, auth)
c.expressRouteAuthsClient = expressRouteAuthsClient

expressRouteCircuitsClient := network.NewExpressRouteCircuitsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&expressRouteCircuitsClient.Client, auth)
c.expressRouteCircuitClient = expressRouteCircuitsClient
Expand Down
31 changes: 31 additions & 0 deletions azurerm/import_arm_express_route_circuit_authorization_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMExpressRouteCircuitAuthorization_importBasic(t *testing.T) {
resourceName := "azurerm_express_route_circuit_authorization.test"

ri := acctest.RandInt()
config := testAccAzureRMExpressRouteCircuitAuthorization_basic(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMExpressRouteCircuitAuthorizationDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(),
"azurerm_eventhub_namespace": resourceArmEventHubNamespace(),
"azurerm_express_route_circuit": resourceArmExpressRouteCircuit(),
"azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(),
"azurerm_function_app": resourceArmFunctionApp(),
"azurerm_image": resourceArmImage(),
"azurerm_iothub": resourceArmIotHub(),
Expand Down
8 changes: 8 additions & 0 deletions azurerm/resource_arm_express_route_circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/hashicorp/terraform/helper/validation"
)

var expressRouteCircuitResourceName = "azurerm_express_route_circuit"

func resourceArmExpressRouteCircuit() *schema.Resource {
return &schema.Resource{
Create: resourceArmExpressRouteCircuitCreateOrUpdate,
Expand Down Expand Up @@ -136,6 +138,9 @@ func resourceArmExpressRouteCircuitCreateOrUpdate(d *schema.ResourceData, meta i
Tags: expandedTags,
}

azureRMLockByName(name, expressRouteCircuitResourceName)
defer azureRMUnlockByName(name, expressRouteCircuitResourceName)

future, err := client.CreateOrUpdate(ctx, resGroup, name, erc)
if err != nil {
return fmt.Errorf("Error Creating/Updating ExpressRouteCircuit %q (Resource Group %q): %+v", name, resGroup, err)
Expand Down Expand Up @@ -203,6 +208,9 @@ func resourceArmExpressRouteCircuitDelete(d *schema.ResourceData, meta interface
return fmt.Errorf("Error Parsing Azure Resource ID: %+v", err)
}

azureRMLockByName(name, expressRouteCircuitResourceName)
defer azureRMUnlockByName(name, expressRouteCircuitResourceName)

future, err := client.Delete(ctx, resourceGroup, name)
if err != nil {
return err
Expand Down
153 changes: 153 additions & 0 deletions azurerm/resource_arm_express_route_circuit_authorization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package azurerm

import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func resourceArmExpressRouteCircuitAuthorization() *schema.Resource {
return &schema.Resource{
Create: resourceArmExpressRouteCircuitAuthorizationCreateUpdate,
Read: resourceArmExpressRouteCircuitAuthorizationRead,
Delete: resourceArmExpressRouteCircuitAuthorizationDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"resource_group_name": resourceGroupNameSchema(),

"express_route_circuit_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"authorization_key": {
Type: schema.TypeString,
Computed: true,
},

"authorization_use_status": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func resourceArmExpressRouteCircuitAuthorizationCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).expressRouteAuthsClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
circuitName := d.Get("express_route_circuit_name").(string)

properties := network.ExpressRouteCircuitAuthorization{
AuthorizationPropertiesFormat: &network.AuthorizationPropertiesFormat{},
}

azureRMLockByName(circuitName, expressRouteCircuitResourceName)
defer azureRMUnlockByName(circuitName, expressRouteCircuitResourceName)

future, err := client.CreateOrUpdate(ctx, resourceGroup, circuitName, name, properties)
if err != nil {
return fmt.Errorf("Error Creating/Updating Express Route Circuit Authorization %q (Circuit %q / Resource Group %q): %+v", name, circuitName, resourceGroup, err)
}

err = future.WaitForCompletion(ctx, client.Client)
if err != nil {
return fmt.Errorf("Error waiting for Express Route Circuit Authorization %q (Circuit %q / Resource Group %q) to finish creating/updating: %+v", name, circuitName, resourceGroup, err)
}

read, err := client.Get(ctx, resourceGroup, circuitName, name)
if err != nil {
return fmt.Errorf("Error retrieving Express Route Circuit Authorization %q (Circuit %q / Resource Group %q): %+v", name, circuitName, resourceGroup, err)
}

d.SetId(*read.ID)

return resourceArmExpressRouteCircuitAuthorizationRead(d, meta)
}

func resourceArmExpressRouteCircuitAuthorizationRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).expressRouteAuthsClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}

resourceGroup := id.ResourceGroup
circuitName := id.Path["expressRouteCircuits"]
name := id.Path["authorizations"]

resp, err := client.Get(ctx, resourceGroup, circuitName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving Express Route Circuit Authorization %q (Circuit %q / Resource Group %q): %+v", name, circuitName, resourceGroup, err)
}

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("express_route_circuit_name", circuitName)

if props := resp.AuthorizationPropertiesFormat; props != nil {
d.Set("authorization_key", props.AuthorizationKey)
d.Set("authorization_use_status", string(props.AuthorizationUseStatus))
}

return nil
}

func resourceArmExpressRouteCircuitAuthorizationDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).expressRouteAuthsClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}

resourceGroup := id.ResourceGroup
circuitName := id.Path["expressRouteCircuits"]
name := id.Path["authorizations"]

azureRMLockByName(circuitName, expressRouteCircuitResourceName)
defer azureRMUnlockByName(circuitName, expressRouteCircuitResourceName)

future, err := client.Delete(ctx, resourceGroup, circuitName, name)
if err != nil {
if response.WasNotFound(future.Response()) {
return nil
}

return fmt.Errorf("Error deleting Express Route Circuit Authorization %q (Circuit %q / Resource Group %q): %+v", name, circuitName, resourceGroup, err)
}

err = future.WaitForCompletion(ctx, client.Client)
if err != nil {
if response.WasNotFound(future.Response()) {
return nil
}

return fmt.Errorf("Error waiting for Express Route Circuit Authorization %q (Circuit %q / Resource Group %q) to be deleted: %+v", name, circuitName, resourceGroup, err)
}

return nil
}
Loading