-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Data Source:
azurerm_cdn_profile
``` $ 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
1 parent
2e17e20
commit f1e0d8f
Showing
5 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |