Skip to content

Commit

Permalink
Merge pull request #2 from terraform-providers/master
Browse files Browse the repository at this point in the history
get latest source
  • Loading branch information
ritesh-modi authored Oct 20, 2020
2 parents 790b11e + 9d67a6f commit c75d945
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

IMPROVEMENTS:

* Data Source: `azurerm_shared_image_version` - exposing `os_disk_image_size_gb` [GH-8904]
* `azurerm_app_configuration` - support for the `identity` block [GH-8875]
* `azurerm_cosmosdb_sql_container` - support for composite indexes [GH-8792]
* `azurerm_mssql_database` - do not set longterm and shortterm retention policies when using the `DW` SKUs [GH-8899]
* `azurerm_mysql_firewall_rule` - validating the `start_ip_address` and `end_ip_address` fields are IP Addresses [GH-8948]
* `azurerm_redis_firewall_rule` - validating the `start_ip` and `end_ip` fields are IP Addresses [GH-8948]
* `azurerm_search_service` - support for the `identity` block [GH-8907]
* `azurerm_sql_firewall_rule` - adding validation for the `start_ip_address` and `end_ip_address` fields [GH-8935]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ func resourceArmAppConfiguration() *schema.Resource {

"location": azure.SchemaLocation(),

"identity": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(appconfiguration.SystemAssigned),
}, false),
},
"principal_id": {
Type: schema.TypeString,
Computed: true,
},
"tenant_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

// the API changed and now returns the rg in lowercase
// revert when https://github.com/Azure/azure-sdk-for-go/issues/6606 is fixed
"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(),
Expand Down Expand Up @@ -199,6 +224,8 @@ func resourceArmAppConfigurationCreate(d *schema.ResourceData, meta interface{})
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

parameters.Identity = expandAppConfigurationIdentity(d.Get("identity").([]interface{}))

future, err := client.Create(ctx, resourceGroup, name, parameters)
if err != nil {
return fmt.Errorf("Error creating App Configuration %q (Resource Group %q): %+v", name, resourceGroup, err)
Expand Down Expand Up @@ -239,6 +266,10 @@ func resourceArmAppConfigurationUpdate(d *schema.ResourceData, meta interface{})
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if d.HasChange("identity") {
parameters.Identity = expandAppConfigurationIdentity(d.Get("identity").([]interface{}))
}

future, err := client.Update(ctx, id.ResourceGroup, id.Name, parameters)
if err != nil {
return fmt.Errorf("Error updating App Configuration %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
Expand Down Expand Up @@ -308,6 +339,10 @@ func resourceArmAppConfigurationRead(d *schema.ResourceData, meta interface{}) e
d.Set("secondary_read_key", accessKeys.secondaryReadKey)
d.Set("secondary_write_key", accessKeys.secondaryWriteKey)

if err := d.Set("identity", flattenAppConfigurationIdentity(resp.Identity)); err != nil {
return fmt.Errorf("Error setting `identity`: %+v", err)
}

return tags.FlattenAndSet(d, resp.Tags)
}

Expand Down Expand Up @@ -408,3 +443,39 @@ func flattenAppConfigurationAccessKey(input appconfiguration.APIKey) []interface
},
}
}

func expandAppConfigurationIdentity(identities []interface{}) *appconfiguration.ResourceIdentity {
if len(identities) == 0 {
return &appconfiguration.ResourceIdentity{
Type: appconfiguration.None,
}
}
identity := identities[0].(map[string]interface{})
identityType := appconfiguration.IdentityType(identity["type"].(string))
return &appconfiguration.ResourceIdentity{
Type: identityType,
}
}
func flattenAppConfigurationIdentity(identity *appconfiguration.ResourceIdentity) []interface{} {
if identity == nil || identity.Type == appconfiguration.None {
return []interface{}{}
}

principalId := ""
if identity.PrincipalID != nil {
principalId = *identity.PrincipalID
}

tenantId := ""
if identity.TenantID != nil {
tenantId = *identity.TenantID
}

return []interface{}{
map[string]interface{}{
"type": string(identity.Type),
"principal_id": principalId,
"tenant_id": tenantId,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,61 @@ func TestAccAppConfigurationResource_complete(t *testing.T) {
})
}

func TestAccAppConfigurationResource_identity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_configuration", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAppConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAppConfigurationResource_identity(data),
Check: resource.ComposeTestCheckFunc(
testCheckAppConfigurationExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAppConfigurationResource_identityUpdated(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_configuration", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAppConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAppConfigurationResource_standard(data),
Check: resource.ComposeTestCheckFunc(
testCheckAppConfigurationExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAppConfigurationResource_identity(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "identity.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"),
resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.tenant_id"),
),
},
data.ImportStep(),
{
Config: testAppConfigurationResource_standard(data),
Check: resource.ComposeTestCheckFunc(
testCheckAppConfigurationExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAppConfigurationResource_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_configuration", "test")

Expand Down Expand Up @@ -248,6 +303,34 @@ resource "azurerm_app_configuration" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAppConfigurationResource_identity(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_configuration" "test" {
name = "testaccappconf%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "standard"
identity {
type = "SystemAssigned"
}
tags = {
environment = "development"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAppConfigurationResource_completeUpdated(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func dataSourceArmSharedImageVersion() *schema.Resource {
Computed: true,
},

"os_disk_image_size_gb": {
Type: schema.TypeInt,
Computed: true,
},

"target_region": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -133,6 +138,12 @@ func dataSourceArmSharedImageVersionRead(d *schema.ResourceData, meta interface{
osDiskSnapShotID = *profile.OsDiskImage.Source.ID
}
d.Set("os_disk_snapshot_id", osDiskSnapShotID)

osDiskImageSize := 0
if profile.OsDiskImage != nil && profile.OsDiskImage.SizeInGB != nil {
osDiskImageSize = int(*profile.OsDiskImage.SizeInGB)
}
d.Set("os_disk_image_size_gb", osDiskImageSize)
}
}

Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/shared_image_version.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ The following attributes are exported:

* `os_disk_snapshot_id` - The ID of the OS disk snapshot which was the source of this Shared Image Version.

* `os_disk_image_size_gb` - The size of the OS disk snapshot (in Gigabytes) which was the source of this Shared Image Version.

* `tags` - A mapping of tags assigned to the Shared Image.

---
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/api_management_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d
API Management Subscriptions can be imported using the `resource id`, e.g.

```shell
terraform import azurerm_api_management_subscription.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources/providers/Microsoft.ApiManagement/service/example-apim/properties/example-apimp
terraform import azurerm_api_management_subscription.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources/providers/Microsoft.ApiManagement/service/example-apim/subscriptions/subscription-name
```
18 changes: 18 additions & 0 deletions website/docs/r/app_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ The following arguments are supported:

* `sku` - (Optional) The SKU name of the the App Configuration. Possible values are `free` and `standard`.

* `identity` - (Optional) An `identity` block as defined below.

~> **NOTE:** Azure does not allow a downgrade from `standard` to `free`.

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

---

An `identity` block supports the following:

* `type` - (Required) Specifies the identity type of the App Configuration. At this time the only allowed value is `SystemAssigned`.

---
## Attributes Reference

Expand All @@ -59,6 +67,16 @@ The following attributes are exported:

* `secondary_write_key` - A `secondary_write_key` block as defined below containing the secondary write access key.

* `identity` - An `identity` block as defined below.

---

An `identity` block exports the following:

* `principal_id` - The ID of the Principal (Client) in Azure Active Directory.

* `tenant_id` - The ID of the Azure Active Directory Tenant.

---

A `primary_read_key` block exports the following:
Expand Down

0 comments on commit c75d945

Please sign in to comment.