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 32 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
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/containerregistry"
Expand Down Expand Up @@ -58,8 +59,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 @@ -617,6 +622,30 @@ func (c *Config) getArmClient() (*ArmClient, error) {
spc.Sender = autorest.CreateSender(withRequestLogging())
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
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,
},
},
})
}
34 changes: 34 additions & 0 deletions azurerm/import_arm_automation_credential_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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_testCredential(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAutomationCredentialDestroy,
Steps: []resource.TestStep{
{
Config: config,
// publish content link is not returned after the runbook is created
ExpectNonEmptyPlan: true,
},

{
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.

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

},
})
}
34 changes: 34 additions & 0 deletions azurerm/import_arm_automation_runbook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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,
// publish content link is not returned after the runbook is created
ExpectNonEmptyPlan: true,
},

{
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 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

},
})
}
34 changes: 34 additions & 0 deletions azurerm/import_arm_automation_schedule_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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,
// publish content link is not returned after the runbook is created
ExpectNonEmptyPlan: true,
},

{
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 @@ -69,6 +69,10 @@ func Provider() terraform.ResourceProvider {
ResourcesMap: map[string]*schema.Resource{
"azurerm_application_insights": resourceArmApplicationInsights(),
"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 @@ -243,6 +247,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