Skip to content

Commit

Permalink
New Data Source: azurerm_cdn_profile
Browse files Browse the repository at this point in the history
```
$ acctests azurerm TestAccDataSourceAzureRMCdnProfile_
=== RUN   TestAccDataSourceAzureRMCdnProfile_basic
--- PASS: TestAccDataSourceAzureRMCdnProfile_basic (186.29s)
=== RUN   TestAccDataSourceAzureRMCdnProfile_withTags
--- PASS: TestAccDataSourceAzureRMCdnProfile_withTags (181.88s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	368.201s
```
  • Loading branch information
tombuildsstuff committed Mar 12, 2018
1 parent 2e17e20 commit f1e0d8f
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
63 changes: 63 additions & 0 deletions azurerm/data_source_cdn_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package azurerm

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmCdnProfile() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmCdnProfileRead,

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

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"location": locationForDataSourceSchema(),

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

"tags": tagsForDataSourceSchema(),
},
}
}

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

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

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
}
return fmt.Errorf("Error making Read request on Azure CDN Profile %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("location", azureRMNormalizeLocation(*resp.Location))

if sku := resp.Sku; sku != nil {
d.Set("sku", string(sku.Name))
}

flattenAndSetTags(d, resp.Tags)

return nil
}
100 changes: 100 additions & 0 deletions azurerm/data_source_cdn_profile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package azurerm

import (
"fmt"
"testing"

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

func TestAccDataSourceAzureRMCdnProfile_basic(t *testing.T) {
ri := acctest.RandInt()
location := testLocation()
config := testAccDataSourceAzureRMCdnProfile_basic(ri, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMCdnProfileDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnProfileExists("data.azurerm_cdn_profile.test"),
),
},
},
})
}

func TestAccDataSourceAzureRMCdnProfile_withTags(t *testing.T) {
resourceName := "data.azurerm_cdn_profile.test"
ri := acctest.RandInt()
location := testLocation()
preConfig := testAccDataSourceAzureRMCdnProfile_withTags(ri, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMCdnProfileDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnProfileExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"),
resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"),
),
},
},
})
}

func testAccDataSourceAzureRMCdnProfile_basic(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_cdn_profile" "test" {
name = "acctestcdnprof%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard_Verizon"
}
data "azurerm_cdn_profile" "test" {
name = "${azurerm_cdn_profile.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
`, rInt, location, rInt)
}

func testAccDataSourceAzureRMCdnProfile_withTags(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_cdn_profile" "test" {
name = "acctestcdnprof%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard_Verizon"
tags {
environment = "Production"
cost_center = "MSFT"
}
}
data "azurerm_cdn_profile" "test" {
name = "${azurerm_cdn_profile.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
`, rInt, location, rInt)
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_app_service_plan": dataSourceAppServicePlan(),
"azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(),
"azurerm_client_config": dataSourceArmClientConfig(),
"azurerm_cdn_profile": dataSourceArmCdnProfile(),
"azurerm_dns_zone": dataSourceArmDnsZone(),
"azurerm_eventhub_namespace": dataSourceEventHubNamespace(),
"azurerm_image": dataSourceArmImage(),
Expand Down
4 changes: 4 additions & 0 deletions website/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<a href="/docs/providers/azurerm/d/builtin_role_definition.html">azurerm_builtin_role_definition</a>
</li>

<li<%= sidebar_current("docs-azurerm-datasource-cdn-profile") %>>
<a href="/docs/providers/azurerm/d/cdn_profile.html">azurerm_cdn_profile</a>
</li>

<li<%= sidebar_current("docs-azurerm-datasource-client-config") %>>
<a href="/docs/providers/azurerm/d/client_config.html">azurerm_client_config</a>
</li>
Expand Down
38 changes: 38 additions & 0 deletions website/docs/d/cdn_profile.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_cdn_profile"
sidebar_current: "docs-azurerm-datasource-cdn-profile"
description: |-
Gets information about a CDN Profile
---

# Data Source: azurerm_cdn_profile

Use this data source to access information about a CDN Profile.

## Example Usage

```hcl
data "azurerm_cdn_profile" "test" {
name = "myfirstcdnprofile"
resource_group_name = "example-resources"
}
output "cdn_profile_id" {
value = "${data.azurerm_cdn_profile.test.id}"
}
```

## Argument Reference

* `name` - (Required) The name of the CDN Profile.

* `resource_group_name` - The name of the resource group in which the CDN Profile exists.

## Attributes Reference

* `location` - The Azure Region where the resource exists.

* `sku` - The pricing related information of current CDN profile.

* `tags` - A mapping of tags to assign to the resource.

0 comments on commit f1e0d8f

Please sign in to comment.