Skip to content

Commit

Permalink
automation dsconfiguration/dscnodeconfiguration and support log_progr…
Browse files Browse the repository at this point in the history
…ess", "hash", "source_version" properties
  • Loading branch information
wuxu92 committed Jul 7, 2023
1 parent e26d8c0 commit 70b7350
Show file tree
Hide file tree
Showing 26 changed files with 1,181 additions and 10 deletions.
4 changes: 3 additions & 1 deletion internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
return fmt.Errorf("building clients for Authorization: %+v", err)
}
client.Automanage = automanage.NewClient(o)
client.Automation = automation.NewClient(o)
if client.Automation, err = automation.NewClient(o); err != nil {
return fmt.Errorf("building clients for Autoamtion: %+v", err)
}
client.AzureStackHCI = azureStackHCI.NewClient(o)
if client.Batch, err = batch.NewClient(o); err != nil {
return fmt.Errorf("building clients for Batch: %+v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2019-06-01/dscconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2022-08-08/dscconfiguration"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -75,6 +75,26 @@ func resourceAutomationDscConfiguration() *pluginsdk.Resource {
Default: false,
},

"log_progress": {
Type: pluginsdk.TypeBool,
Optional: true,
},

"hash_algorithm": {
Type: pluginsdk.TypeString,
Optional: true,
},

"hash_value": {
Type: pluginsdk.TypeString,
Optional: true,
},

"source_version": {
Type: pluginsdk.TypeString,
Optional: true,
},

"description": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -121,10 +141,16 @@ func resourceAutomationDscConfigurationCreateUpdate(d *pluginsdk.ResourceData, m
parameters := dscconfiguration.DscConfigurationCreateOrUpdateParameters{
Properties: dscconfiguration.DscConfigurationCreateOrUpdateProperties{
LogVerbose: utils.Bool(logVerbose),
LogProgress: utils.Bool(d.Get("log_progress").(bool)),
Description: utils.String(description),
Source: dscconfiguration.ContentSource{
Type: pointer.To(dscconfiguration.ContentSourceTypeEmbeddedContent),
Value: utils.String(contentEmbedded),
Hash: &dscconfiguration.ContentHash{
Algorithm: d.Get("hash_algorithm").(string),
Value: d.Get("hash_value").(string),
},
Version: utils.String(d.Get("source_version").(string)),
},
},
Location: utils.String(location),
Expand Down Expand Up @@ -173,6 +199,14 @@ func resourceAutomationDscConfigurationRead(d *pluginsdk.ResourceData, meta inte
d.Set("log_verbose", props.LogVerbose)
d.Set("description", props.Description)
d.Set("state", string(pointer.From(props.State)))

if source := props.Source; source != nil {
d.Set("source_version", source.Version)
if hash := source.Hash; hash != nil {
d.Set("hash_algorithm", hash.Algorithm)
d.Set("hash_value", hash.Value)
}
}
}

if model.Tags != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2019-06-01/dscconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2022-08-08/dscconfiguration"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -61,7 +61,8 @@ func TestAccAutomationDscConfiguration_complete(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
// not respond by Get API
data.ImportStep("log_progress", "hash", "source_version"),
})
}

Expand Down Expand Up @@ -154,6 +155,10 @@ resource "azurerm_automation_dsc_configuration" "test" {
content_embedded = "configuration acctest {}"
description = "test"
log_verbose = "true"
log_progress = "true"
source_version = "1.0.0"
hash_algorithm = "algm"
hash_value = "hash"
tags = {
ENV = "prod"
}
Expand Down
17 changes: 11 additions & 6 deletions internal/services/automation/client/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package client

import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/preview/automation/mgmt/2020-01-13-preview/automation" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2015-10-31/webhook"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2019-06-01/dscconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2019-06-01/runbook"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2019-06-01/softwareupdateconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2020-01-13-preview/certificate"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/automationaccount"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworker"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2021-06-22/hybridrunbookworkergroup"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2022-08-08/dscconfiguration"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down Expand Up @@ -47,7 +49,7 @@ type Client struct {
WebhookClient *webhook.WebhookClient
}

func NewClient(o *common.ClientOptions) *Client {
func NewClient(o *common.ClientOptions) (*Client, error) {
accountClient := automationaccount.NewAutomationAccountClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&accountClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -66,8 +68,11 @@ func NewClient(o *common.ClientOptions) *Client {
credentialClient := credential.NewCredentialClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&credentialClient.Client, o.ResourceManagerAuthorizer)

dscConfigurationClient := dscconfiguration.NewDscConfigurationClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&dscConfigurationClient.Client, o.ResourceManagerAuthorizer)
dscConfigurationClient, err := dscconfiguration.NewDscConfigurationClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("build dscConfigurationClient: %+v", err)
}
o.Configure(dscConfigurationClient.Client, o.Authorizers.ResourceManager)

dscNodeConfigurationClient := dscnodeconfiguration.NewDscNodeConfigurationClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&dscNodeConfigurationClient.Client, o.ResourceManagerAuthorizer)
Expand Down Expand Up @@ -118,7 +123,7 @@ func NewClient(o *common.ClientOptions) *Client {
ConnectionClient: &connectionClient,
ConnectionTypeClient: &connectionTypeClient,
CredentialClient: &credentialClient,
DscConfigurationClient: &dscConfigurationClient,
DscConfigurationClient: dscConfigurationClient,
DscNodeConfigurationClient: &dscNodeConfigurationClient,
JobScheduleClient: &jobScheduleClient,
ModuleClient: &moduleClient,
Expand All @@ -133,5 +138,5 @@ func NewClient(o *common.ClientOptions) *Client {
VariableClient: &variableClient,
WatcherClient: &watcherClient,
WebhookClient: &webhookClient,
}
}, nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 70b7350

Please sign in to comment.