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

data.azurerm_linux_web_app, data.azurerm_linux_function_app, data.azurerm_cdn_frontdoor_secret data.azurerm_virtual_machine, data.azurerm_virtual_machine_scale_set: add various properties #21945

Merged
merged 2 commits into from
Jun 1, 2023
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
14 changes: 14 additions & 0 deletions internal/services/appservice/linux_function_app_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type LinuxFunctionAppDataSourceModel struct {
AppSettings map[string]string `tfschema:"app_settings"`
AuthSettings []helpers.AuthSettings `tfschema:"auth_settings"`
AuthV2Settings []helpers.AuthV2Settings `tfschema:"auth_settings_v2"`
Availability string `tfschema:"availability"`
Backup []helpers.Backup `tfschema:"backup"` // Not supported on Dynamic or Basic plans
BuiltinLogging bool `tfschema:"builtin_logging_enabled"`
ClientCertEnabled bool `tfschema:"client_certificate_enabled"`
Expand All @@ -60,6 +61,7 @@ type LinuxFunctionAppDataSourceModel struct {
OutboundIPAddressList []string `tfschema:"outbound_ip_address_list"`
PossibleOutboundIPAddresses string `tfschema:"possible_outbound_ip_addresses"`
PossibleOutboundIPAddressList []string `tfschema:"possible_outbound_ip_address_list"`
Usage string `tfschema:"usage"`

SiteCredentials []helpers.SiteCredential `tfschema:"site_credential"`
}
Expand Down Expand Up @@ -127,6 +129,11 @@ func (d LinuxFunctionAppDataSource) Attributes() map[string]*pluginsdk.Schema {
},
},

"availability": {
Type: pluginsdk.TypeString,
Computed: true,
},

"auth_settings": helpers.AuthSettingsSchemaComputed(),

"auth_settings_v2": helpers.AuthV2SettingsComputedSchema(),
Expand Down Expand Up @@ -234,6 +241,11 @@ func (d LinuxFunctionAppDataSource) Attributes() map[string]*pluginsdk.Schema {
},
},

"usage": {
Type: pluginsdk.TypeString,
Computed: true,
},

"site_credential": helpers.SiteCredentialSchema(),

"sticky_settings": helpers.StickySettingsComputedSchema(),
Expand Down Expand Up @@ -325,6 +337,7 @@ func (d LinuxFunctionAppDataSource) Read() sdk.ResourceFunc {
state := LinuxFunctionAppDataSourceModel{
Name: id.SiteName,
ResourceGroup: id.ResourceGroup,
Availability: string(props.AvailabilityState),
ServicePlanId: utils.NormalizeNilableString(props.ServerFarmID),
Location: location.NormalizeNilable(functionApp.Location),
Enabled: utils.NormaliseNilableBool(functionApp.Enabled),
Expand All @@ -336,6 +349,7 @@ func (d LinuxFunctionAppDataSource) Read() sdk.ResourceFunc {
Kind: utils.NormalizeNilableString(functionApp.Kind),
CustomDomainVerificationId: utils.NormalizeNilableString(props.CustomDomainVerificationID),
DefaultHostname: utils.NormalizeNilableString(functionApp.DefaultHostName),
Usage: string(props.UsageState),
}

if hostingEnv := props.HostingEnvironmentProfile; hostingEnv != nil {
Expand Down
14 changes: 14 additions & 0 deletions internal/services/appservice/linux_web_app_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type LinuxWebAppDataSourceModel struct {
AppSettings map[string]string `tfschema:"app_settings"`
AuthSettings []helpers.AuthSettings `tfschema:"auth_settings"`
AuthV2Settings []helpers.AuthV2Settings `tfschema:"auth_settings_v2"`
Availability string `tfschema:"availability"`
Backup []helpers.Backup `tfschema:"backup"`
ClientAffinityEnabled bool `tfschema:"client_affinity_enabled"`
ClientCertEnabled bool `tfschema:"client_certificate_enabled"`
Expand All @@ -51,6 +52,7 @@ type LinuxWebAppDataSourceModel struct {
OutboundIPAddressList []string `tfschema:"outbound_ip_address_list"`
PossibleOutboundIPAddresses string `tfschema:"possible_outbound_ip_addresses"`
PossibleOutboundIPAddressList []string `tfschema:"possible_outbound_ip_address_list"`
Usage string `tfschema:"usage"`
SiteCredentials []helpers.SiteCredential `tfschema:"site_credential"`
VirtualNetworkSubnetID string `tfschema:"virtual_network_subnet_id"`
}
Expand Down Expand Up @@ -97,6 +99,11 @@ func (r LinuxWebAppDataSource) Attributes() map[string]*pluginsdk.Schema {
},
},

"availability": {
Type: pluginsdk.TypeString,
Computed: true,
},

"auth_settings": helpers.AuthSettingsSchemaComputed(),

"auth_settings_v2": helpers.AuthV2SettingsComputedSchema(),
Expand Down Expand Up @@ -192,6 +199,11 @@ func (r LinuxWebAppDataSource) Attributes() map[string]*pluginsdk.Schema {
},
},

"usage": {
Type: pluginsdk.TypeString,
Computed: true,
},

"site_credential": helpers.SiteCredentialSchema(),

"service_plan_id": {
Expand Down Expand Up @@ -305,6 +317,7 @@ func (r LinuxWebAppDataSource) Read() sdk.ResourceFunc {
webApp.Location = location.NormalizeNilable(existing.Location)
webApp.Tags = tags.ToTypedObject(existing.Tags)
if props := existing.SiteProperties; props != nil {
webApp.Availability = string(props.AvailabilityState)
if props.ClientAffinityEnabled != nil {
webApp.ClientAffinityEnabled = *props.ClientAffinityEnabled
}
Expand All @@ -326,6 +339,7 @@ func (r LinuxWebAppDataSource) Read() sdk.ResourceFunc {
webApp.OutboundIPAddressList = strings.Split(webApp.OutboundIPAddresses, ",")
webApp.PossibleOutboundIPAddresses = utils.NormalizeNilableString(props.PossibleOutboundIPAddresses)
webApp.PossibleOutboundIPAddressList = strings.Split(webApp.PossibleOutboundIPAddresses, ",")
webApp.Usage = string(props.UsageState)
if hostingEnv := props.HostingEnvironmentProfile; hostingEnv != nil {
webApp.HostingEnvId = pointer.From(hostingEnv.ID)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/services/cdn/cdn_frontdoor_secret_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func dataSourceCdnFrontDoorSecret() *pluginsdk.Resource {
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"expiration_date": {
Type: pluginsdk.TypeString,
Computed: true,
},

"key_vault_certificate_id": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -100,7 +105,7 @@ func dataSourceCdnFrontDoorSecretRead(d *pluginsdk.ResourceData, meta interface{

if props := resp.SecretProperties; props != nil {
var customerCertificate []interface{}
if customerCertificate, err = flattenSecretParameters(ctx, props.Parameters, meta); err != nil {
if customerCertificate, err = flattenSecretParametersDataSource(ctx, props.Parameters, meta); err != nil {
return fmt.Errorf("flattening 'secret': %+v", err)
}

Expand Down
70 changes: 68 additions & 2 deletions internal/services/cdn/cdn_frontdoor_secret_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -165,7 +166,7 @@ func resourceCdnFrontDoorSecretRead(d *pluginsdk.ResourceData, meta interface{})

if props := resp.SecretProperties; props != nil {
var customerCertificate []interface{}
if customerCertificate, err = flattenSecretParameters(ctx, props.Parameters, meta); err != nil {
if customerCertificate, err = flattenSecretParametersResource(ctx, props.Parameters, meta); err != nil {
return fmt.Errorf("flattening 'secret': %+v", err)
}

Expand Down Expand Up @@ -218,7 +219,7 @@ func expandCdnFrontDoorBasicSecretParameters(ctx context.Context, input []interf
return customerCertificate, nil
}

func flattenSecretParameters(ctx context.Context, input cdn.BasicSecretParameters, meta interface{}) ([]interface{}, error) {
func flattenSecretParametersResource(ctx context.Context, input cdn.BasicSecretParameters, meta interface{}) ([]interface{}, error) {
client := meta.(*clients.Client).KeyVault

results := make([]interface{}, 0)
Expand Down Expand Up @@ -281,3 +282,68 @@ func flattenSecretParameters(ctx context.Context, input cdn.BasicSecretParameter

return results, nil
}

func flattenSecretParametersDataSource(ctx context.Context, input cdn.BasicSecretParameters, meta interface{}) ([]interface{}, error) {
client := meta.(*clients.Client).KeyVault

results := make([]interface{}, 0)
if input == nil {
return results, nil
}

result := make(map[string]interface{})
fields := make(map[string]interface{})

customerCertificate, ok := input.AsCustomerCertificateParameters()
if !ok {
return nil, fmt.Errorf("expected a Customer Certificate Parameter")
}

secretSourceId, err := keyVaultParse.SecretVersionlessID(*customerCertificate.SecretSource.ID)
if err != nil {
return nil, fmt.Errorf("unable to parse the 'Secret Source' field of the 'Customer Certificate', got %q", *customerCertificate.SecretSource.ID)
}

if customerCertificate.UseLatestVersion != nil {
// The API always sends back the version...
var certificateVersion string
var useLatest bool

if customerCertificate.SecretVersion != nil {
certificateVersion = *customerCertificate.SecretVersion
}

if customerCertificate.UseLatestVersion != nil {
useLatest = *customerCertificate.UseLatestVersion
}

keyVaultId := commonids.NewKeyVaultID(secretSourceId.SubscriptionId, secretSourceId.ResourceGroup, secretSourceId.VaultName)
keyVaultBaseUri, err := client.BaseUriForKeyVault(ctx, keyVaultId)
if err != nil {
return nil, fmt.Errorf("looking up Base URI for Certificate %q in %s: %+v", secretSourceId.SecretName, keyVaultId, err)
}

keyVaultCertificateId, err := keyVaultParse.NewNestedItemID(*keyVaultBaseUri, "certificates", secretSourceId.SecretName, certificateVersion)
if err != nil {
return nil, err
}

if useLatest {
fields["key_vault_certificate_id"] = keyVaultCertificateId.VersionlessID()
} else {
fields["key_vault_certificate_id"] = keyVaultCertificateId.ID()
}
}

if customerCertificate.SubjectAlternativeNames != nil {
fields["subject_alternative_names"] = utils.FlattenStringSlice(customerCertificate.SubjectAlternativeNames)
} else {
fields["subject_alternative_names"] = make([]string, 0)
}

result["expiration_date"] = pointer.From(customerCertificate.ExpirationDate)
result["customer_certificate"] = []interface{}{fields}
results = append(results, result)

return results, nil
}
21 changes: 21 additions & 0 deletions internal/services/compute/virtual_machine_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package compute

import (
"fmt"
"strings"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -39,24 +40,32 @@ func dataSourceVirtualMachine() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Computed: true,
},

"private_ip_addresses": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

"public_ip_address": {
Type: pluginsdk.TypeString,
Computed: true,
},

"public_ip_addresses": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

"power_state": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -85,6 +94,18 @@ func dataSourceVirtualMachineRead(d *pluginsdk.ResourceData, meta interface{}) e

d.Set("location", location.NormalizeNilable(resp.Location))

if prop := resp.VirtualMachineProperties; prop != nil {
if instance := prop.InstanceView; instance != nil {
if statues := instance.Statuses; statues != nil {
for _, status := range *statues {
if status.Code != nil && strings.HasPrefix(strings.ToLower(*status.Code), "powerstate/") {
d.Set("power_state", strings.SplitN(*status.Code, "/", 2)[1])
}
}
}
}
}

connectionInfo := retrieveConnectionInformation(ctx, networkInterfacesClient, publicIPAddressesClient, resp.VirtualMachineProperties)
err = d.Set("private_ip_address", connectionInfo.primaryPrivateAddress)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions internal/services/compute/virtual_machine_scale_set_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package compute
import (
"context"
"fmt"
"strings"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -101,6 +102,11 @@ func dataSourceVirtualMachineScaleSet() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Computed: true,
},

"power_state": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -278,5 +284,15 @@ func flattenVirtualMachineScaleSetVM(input compute.VirtualMachineScaleSetVM, con
output["public_ip_addresses"] = connectionInfo.publicAddresses
}

if instance := input.InstanceView; instance != nil {
if statues := instance.Statuses; statues != nil {
for _, status := range *statues {
if status.Code != nil && strings.HasPrefix(strings.ToLower(*status.Code), "powerstate/") {
output["power_state"] = strings.SplitN(*status.Code, "/", 2)[1]
}
}
}
}

return output
}
3 changes: 3 additions & 0 deletions website/docs/d/cdn_frontdoor_secret.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ A `secret` block exports the following:

A `customer_certificate` block exports the following:


* `expiration_date` - The key vault certificate expiration date.

* `key_vault_certificate_id` - The key vault certificate ID.

* `subject_alternative_names` - One or more `subject alternative names` contained within the key vault certificate.
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/linux_function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `auth_settings_v2` - A `auth_settings_v2` block as defined below.

* `availability` - The current availability state. Possible values are `Normal`, `Limited`, and `DisasterRecoveryMode`.

* `backup` - A `backup` block as defined below.

* `builtin_logging_enabled` - Is built in logging enabled?
Expand Down Expand Up @@ -103,6 +105,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `tags` - A mapping of tags which are assigned to the Linux Function App.

* `usage` - The current usage state. Possible values are `Normal` and `Exceeded`.

* `virtual_network_subnet_id` - The subnet id which the Linux Function App is vNet Integrated with.

---
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/linux_web_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

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

* `availability` - The current availability state. Possible values are `Normal`, `Limited`, and `DisasterRecoveryMode`.
*
* `backup` - A `backup` block as defined below.

* `client_affinity_enabled` - Is Client Affinity enabled?
Expand Down Expand Up @@ -95,6 +97,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `virtual_network_subnet_id` - The subnet id which the Linux Web App is vNet Integrated with.

* `usage` - The current usage state. Possible values are `Normal` and `Exceeded`.

* `tags` - A mapping of tags assigned to the Linux Web App.

---
Expand Down
4 changes: 3 additions & 1 deletion website/docs/d/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ output "virtual_machine_id" {
* `id` - The ID of the Virtual Machine.

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

* `private_ip_address` - The Primary Private IP Address assigned to this Virtual Machine.

* `private_ip_addresses` - A list of Private IP Addresses assigned to this Virtual Machine.
Expand All @@ -47,6 +47,8 @@ output "virtual_machine_id" {

* `public_ip_addresses` - A list of the Public IP Addresses assigned to this Virtual Machine.

* `power_state` - The power state of the virtual machine.

~> In this release there's a known issue where the `public_ip_address` and `public_ip_addresses` fields may not be fully populated for Dynamic Public IP's.

---
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/virtual_machine_scale_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ An `identity` block exports the following:
* `private_ip_addresses` - A list of Private IP Addresses assigned to this Virtual Machine.
* `public_ip_address` - The Primary Public IP Address assigned to this Virtual Machine.
* `public_ip_addresses` - A list of the Public IP Addresses assigned to this Virtual Machine.
* `provisioning_state` - The provisioning state of the virtual machine.
* `power_state` - The power state of the virtual machine.
* `virtual_machine_id` - The unique ID of the virtual machine.
* `zone` - The zones of the virtual machine.

Expand Down
Loading