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

New resource: Automation Account/Credential/Runbook/Schedule #257

Merged
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d80fd0e
Add automation resources: account, credential, runbook, schedule
Kemyke Aug 10, 2017
6c09115
Add issue links
Kemyke Aug 17, 2017
523e08e
Formatting
Kemyke Aug 18, 2017
1c34e27
Fix formatting and logging
Kemyke Aug 18, 2017
9bfd535
Add documentation
Kemyke Aug 18, 2017
b969cbb
Merge branch 'master' into automation_resource
Kemyke Aug 29, 2017
f607970
Merge branch 'master' into automation_resource
Kemyke Aug 30, 2017
c283cbf
Merge branch 'master' of https://github.com/terraform-providers/terra…
Aug 31, 2017
3b04f54
Fix auto-merge
Aug 31, 2017
9002060
Use new utils library
Aug 31, 2017
50fa597
Fix method name
Aug 31, 2017
b220c77
Minor fixes based on the review
Aug 31, 2017
72d53c6
Fix formatting
Aug 31, 2017
a4d9c38
Refactor sku as List
Sep 1, 2017
4d62cd9
Get UserName from CredentialProperties instead of top level property
Sep 1, 2017
cb9e4d9
Extend content_link schema with hash and version
Sep 1, 2017
7dbda41
Use properties from RunbookProperties
Sep 1, 2017
fe3cd90
Use TypeList instead of TypeSet
Sep 1, 2017
612a1a9
Add timezone to schedule
Sep 1, 2017
124f466
Remove unsupported interval
Sep 1, 2017
3b9ee8d
Remove interval from schema
Sep 1, 2017
1b0425b
Remove interval from docs
Sep 1, 2017
fe7f536
Remove first_run field and switch start_time as required field
Sep 1, 2017
6b2c8e1
Fix example in documentation
Sep 4, 2017
3c93fe6
Fix typo in documentation
Sep 4, 2017
90f30d5
Remove nil association
Sep 4, 2017
cab95de
Add validate function for start_time field
Sep 4, 2017
1a9e856
Fix timezone in example
Sep 4, 2017
789bd76
Formatting
Sep 4, 2017
92f5b17
Add resrouce provider registration
Sep 4, 2017
8bde7e8
Remove publish content link from read
Sep 4, 2017
79f34c5
Merge branch 'master' into automation_resource
Kemyke Sep 6, 2017
97b96a3
Fix test, add expirytime, fix logging
Sep 11, 2017
df7f71a
Merge branch 'automation_resource' of https://github.com/nexogen-inte…
Sep 11, 2017
6f5ea11
Remove Computed tag
Sep 12, 2017
7caaa74
Check from state
Sep 12, 2017
8d96426
Refactor credential tests
Sep 12, 2017
a540b75
Fix runbook import test
Sep 12, 2017
13a4bdb
Refactor logic
Sep 12, 2017
0b5f90a
Refactor schedule tests
Sep 12, 2017
816e856
Add diff function for start_time
Sep 18, 2017
5cdc5d9
Remove ExpectNonEmptyPlan
Sep 18, 2017
2fe3b66
Add DiffSuppressFunc, formatting
Sep 18, 2017
31d14da
Merge branch 'master' into automation_resource
tombuildsstuff Sep 19, 2017
69b00d6
Fixing the broken build (caused by a bad rebase)
tombuildsstuff Sep 20, 2017
231c7cc
Vendoring the Azure Automation SDK
tombuildsstuff Sep 20, 2017
d830bca
Vendoring (plus comma)
tombuildsstuff Sep 20, 2017
17a304c
Upgrading to SDK 10.3
tombuildsstuff Sep 20, 2017
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
39 changes: 37 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,36 @@ 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 = autorest.CreateSender(withRequestLogging())
client.automationAccountClient = aadb

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

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

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

ac := web.NewAppsClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&ac.Client)
ac.Authorizer = auth
ac.Sender = autorest.CreateSender(withRequestLogging())
client.appsClient = ac

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"},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than expecting a non-empty plan - can we swap this out to ignore the specific field that's missing? i.e.

{
    Config: config,
},
{
    ResourceName:            resourceName,
    ImportState:             true,
    ImportStateVerify:       true,
    ImportStateVerifyIgnore: []string{"storage_account"},
},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

},
})
}
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"},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as above) - can we update this to name the field which won't be set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

},
})
}
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,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as above) - can we update this to name the field which isn't set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really solve this with the Ignore attribute. The output of the test is the following:

        testing.go:435: Step 0 error: After applying this step, the plan was not empty:

                DIFF:

                UPDATE: azurerm_automation_schedule.test
                  start_time: "2017-09-12T16:20:00+02:00" => "2017-09-12T14:20:38Z"

                STATE:

                azurerm_automation_account.test:
.
.
.

The start_time is received in UTC and that's cause the difference. Can we handle this without the ExpectNonEmptyPlan attribute?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so in that case we should be able to add a DiffSuppressFunc to the start_time field, which will cast both dates to UTC time and then check if there's any difference?

},
})
}
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