Skip to content

Commit

Permalink
New resource: Automation Account/Credential/Runbook/Schedule (#257)
Browse files Browse the repository at this point in the history
* Add automation resources: account, credential, runbook, schedule

* Add issue links

* Formatting

* Fix formatting and logging

* Add documentation

* Fix auto-merge

* Use new utils library

* Fix method name

* Minor fixes based on the review

* Fix formatting

* Refactor sku as List
Remove name AccountCreateOrUpdateProperties

* Get UserName from CredentialProperties instead of top level property

* Extend content_link schema with hash and version

* Use properties from RunbookProperties

* Use TypeList instead of TypeSet

* Add timezone to schedule

* Remove unsupported interval

* Remove interval from schema

* Remove interval from docs

* Remove first_run field and switch start_time as required field

* Fix example in documentation

* Fix typo in documentation

* Remove nil association

* Add validate function for start_time field

* Fix timezone in example

* Formatting

* Add resrouce provider registration

* Remove publish content link from read

* Fix test, add expirytime, fix logging

* Remove Computed tag

* Check from state

* Refactor credential tests

* Fix runbook import test

* Refactor logic

* Refactor schedule tests

* Add diff function for start_time

* Remove ExpectNonEmptyPlan

* Add DiffSuppressFunc, formatting

* Fixing the broken build (caused by a bad rebase)

Also swapping the re-initialisation of `sender` to use the shared variable

* Vendoring the Azure Automation SDK

* Vendoring (plus comma)

* Upgrading to SDK 10.3
  • Loading branch information
Kemyke authored and tombuildsstuff committed Sep 20, 2017
1 parent 3e78d8d commit 97bcbc5
Show file tree
Hide file tree
Showing 51 changed files with 14,046 additions and 2 deletions.
33 changes: 31 additions & 2 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http/httputil"

"github.com/Azure/azure-sdk-for-go/arm/appinsights"
"github.com/Azure/azure-sdk-for-go/arm/automation"
"github.com/Azure/azure-sdk-for-go/arm/cdn"
"github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/Azure/azure-sdk-for-go/arm/containerinstance"
Expand Down Expand Up @@ -59,8 +60,12 @@ type ArmClient struct {
vmClient compute.VirtualMachinesClient
imageClient compute.ImagesClient

diskClient disk.DisksClient
cosmosDBClient cosmosdb.DatabaseAccountsClient
diskClient disk.DisksClient
cosmosDBClient cosmosdb.DatabaseAccountsClient
automationAccountClient automation.AccountClient
automationRunbookClient automation.RunbookClient
automationCredentialClient automation.CredentialClient
automationScheduleClient automation.ScheduleClient

appGatewayClient network.ApplicationGatewaysClient
ifaceClient network.InterfacesClient
Expand Down Expand Up @@ -659,6 +664,30 @@ func (c *Config) getArmClient() (*ArmClient, error) {
spc.Sender = sender
client.servicePrincipalsClient = spc

aadb := automation.NewAccountClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&aadb.Client)
aadb.Authorizer = auth
aadb.Sender = sender
client.automationAccountClient = aadb

arc := automation.NewRunbookClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&arc.Client)
arc.Authorizer = auth
arc.Sender = sender
client.automationRunbookClient = arc

acc := automation.NewCredentialClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&acc.Client)
acc.Authorizer = auth
acc.Sender = sender
client.automationCredentialClient = acc

aschc := automation.NewScheduleClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&aschc.Client)
aschc.Authorizer = auth
aschc.Sender = sender
client.automationScheduleClient = aschc

kvc := keyvault.NewVaultsClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&kvc.Client)
kvc.Authorizer = auth
Expand Down
56 changes: 56 additions & 0 deletions azurerm/import_arm_automation_account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMAutomationAccount_importAccountWithFreeSku(t *testing.T) {
resourceName := "azurerm_automation_account.test"

ri := acctest.RandInt()
config := testAccAzureRMAutomationAccount_skuFree(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAutomationAccountDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMAutomationAccount_importAccountWithBasicSku(t *testing.T) {
resourceName := "azurerm_automation_account.test"

ri := acctest.RandInt()
config := testAccAzureRMAutomationAccount_skuBasic(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAutomationAccountDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
33 changes: 33 additions & 0 deletions azurerm/import_arm_automation_credential_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMAutomationCredential_importCredential(t *testing.T) {
resourceName := "azurerm_automation_credential.test"

ri := acctest.RandInt()
config := testAccAzureRMAutomationCredential_complete(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAutomationCredentialDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"password"},
},
},
})
}
33 changes: 33 additions & 0 deletions azurerm/import_arm_automation_runbook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMAutomationRunbook_importRunbookPSWorkflow(t *testing.T) {
resourceName := "azurerm_automation_runbook.test"

ri := acctest.RandInt()
config := testAccAzureRMAutomationRunbook_PSWorkflow(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAutomationRunbookDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"publish_content_link"},
},
},
})
}
32 changes: 32 additions & 0 deletions azurerm/import_arm_automation_schedule_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMAutomationSchedule_importScheduleOneTime(t *testing.T) {
resourceName := "azurerm_automation_schedule.test"

ri := acctest.RandInt()
config := testAccAzureRMAutomationSchedule_oneTime(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAutomationScheduleDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
5 changes: 5 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func Provider() terraform.ResourceProvider {
"azurerm_application_insights": resourceArmApplicationInsights(),
"azurerm_app_service": resourceArmAppService(),
"azurerm_app_service_plan": resourceArmAppServicePlan(),
"azurerm_automation_account": resourceArmAutomationAccount(),
"azurerm_automation_runbook": resourceArmAutomationRunbook(),
"azurerm_automation_credential": resourceArmAutomationCredential(),
"azurerm_automation_schedule": resourceArmAutomationSchedule(),
"azurerm_availability_set": resourceArmAvailabilitySet(),
"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
"azurerm_cdn_profile": resourceArmCdnProfile(),
Expand Down Expand Up @@ -377,6 +381,7 @@ var providerRegistrationOnce sync.Once

func determineAzureResourceProvidersToRegister(providerList []resources.Provider) map[string]struct{} {
providers := map[string]struct{}{
"Microsoft.Automation": {},
"Microsoft.Cache": {},
"Microsoft.Cdn": {},
"Microsoft.Compute": {},
Expand Down
Loading

0 comments on commit 97bcbc5

Please sign in to comment.