Skip to content

Commit

Permalink
Setting the ID's for the Data Sources
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed May 6, 2018
1 parent f303b2a commit a7c1b74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
14 changes: 6 additions & 8 deletions azurerm/data_source_key_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,10 @@ func dataSourceArmKeyVaultRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).keyVaultClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}
resGroup := id.ResourceGroup
name := id.Path["vaults"]
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resGroup, name)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
Expand All @@ -129,8 +125,10 @@ func dataSourceArmKeyVaultRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error making Read request on KeyVault %q: %+v", name, err)
}

d.SetId(*resp.ID)

d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}
Expand Down
12 changes: 6 additions & 6 deletions azurerm/data_source_key_vault_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ func dataSourceArmKeyVaultSecretRead(d *schema.ResourceData, meta interface{}) e
client := meta.(*ArmClient).keyVaultManagementClient
ctx := meta.(*ArmClient).StopContext

id, err := parseKeyVaultChildID(d.Id())
if err != nil {
return err
}
name := d.Get("name").(string)
vaultUri := d.Get("vault_uri").(string)

// we always want to get the latest version
resp, err := client.GetSecret(ctx, id.KeyVaultBaseUrl, id.Name, "")
resp, err := client.GetSecret(ctx, vaultUri, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
}
return fmt.Errorf("Error making Read request on Azure KeyVault Secret %s: %+v", id.Name, err)
return fmt.Errorf("Error making Read request on Azure KeyVault Secret %s: %+v", name, err)
}

// the version may have changed, so parse the updated id
Expand All @@ -70,6 +68,8 @@ func dataSourceArmKeyVaultSecretRead(d *schema.ResourceData, meta interface{}) e
return err
}

d.SetId(*resp.ID)

d.Set("name", respID.Name)
d.Set("vault_uri", respID.KeyVaultBaseUrl)
d.Set("value", resp.Value)
Expand Down

0 comments on commit a7c1b74

Please sign in to comment.