Add example to batch application.
This commit is contained in:
Родитель
513ad8a8ca
Коммит
73d1d94503
|
@ -72,13 +72,20 @@ author:
|
|||
- "Junyi Yi (@JunyiYi)"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Create Batch Application
|
||||
azure_rm_batchapplication:
|
||||
resource_group: MyResGroup
|
||||
name: mybatchapplication
|
||||
account_name: mybatchaccount
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
--- {}
|
||||
'''
|
||||
|
||||
import time
|
||||
from ansible.module_utils.azure_rm_common import from ansible.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt
|
||||
from ansible.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt
|
||||
from ansible.module_utils.common.dict_transformations import _snake_to_camel
|
||||
|
||||
try:
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
cloud/azure
|
||||
destructive
|
||||
shippable/azure/group2
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- setup_azure
|
|
@ -0,0 +1,83 @@
|
|||
---
|
||||
# ----------------------------------------------------------------------------
|
||||
#
|
||||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
#
|
||||
# This file is automatically generated by Magic Modules and manual
|
||||
# changes will be clobbered when the file is regenerated.
|
||||
#
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: Prepare random number
|
||||
set_fact:
|
||||
storage_account_name: "st{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
||||
batch_account_name: "ba{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
||||
batch_application_name: "bap{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
||||
run_once: yes
|
||||
|
||||
- name: Create Storage Account
|
||||
azure_rm_storageaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ storage_account_name }}"
|
||||
location: eastus
|
||||
account_type: Standard_LRS
|
||||
|
||||
- name: Create Batch Account
|
||||
azure_rm_batchaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ batch_account_name }}"
|
||||
location: eastus
|
||||
auto_storage_account:
|
||||
name: "{{ storage_account_name }}"
|
||||
pool_allocation_mode: batch_service
|
||||
|
||||
- name: Create Batch Application
|
||||
azure_rm_batchapplication:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ batch_application_name }}"
|
||||
account_name: "{{ batch_account_name }}"
|
||||
register: output
|
||||
|
||||
- name: Assert the resource was created
|
||||
assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Create Batch Application -- idempotent
|
||||
azure_rm_batchapplication:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ batch_application_name }}"
|
||||
account_name: "{{ batch_account_name }}"
|
||||
register: output
|
||||
|
||||
- name: Assert the resource was created
|
||||
assert:
|
||||
that:
|
||||
- not output.changed
|
||||
|
||||
- name: Delete Batch Application
|
||||
azure_rm_batchapplication:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ batch_application_name }}"
|
||||
account_name: "{{ batch_account_name }}"
|
||||
state: absent
|
||||
register: output
|
||||
|
||||
- name: Assert that state has changed
|
||||
assert:
|
||||
that:
|
||||
- output.changed
|
||||
|
||||
- name: Delete Batch Account
|
||||
azure_rm_batchaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ batch_account_name }}"
|
||||
state: absent
|
||||
|
||||
- name: Delete Storage Account
|
||||
azure_rm_batchaccount:
|
||||
resource_group: "{{ resource_group }}"
|
||||
name: "{{ storage_account_name }}"
|
||||
state: absent
|
|
@ -35,14 +35,14 @@ func resourceArmBatchApplication() *schema.Resource {
|
|||
ForceNew: true,
|
||||
},
|
||||
|
||||
"resource_group_name": resourceGroupNameSchema(),
|
||||
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"resource_group": resourceGroupNameSchema(),
|
||||
|
||||
"allow_updates": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
|
@ -66,7 +66,7 @@ func resourceArmBatchApplicationCreate(d *schema.ResourceData, meta interface{})
|
|||
ctx := meta.(*ArmClient).StopContext
|
||||
|
||||
name := d.Get("name").(string)
|
||||
resourceGroup := d.Get("resource_group").(string)
|
||||
resourceGroup := d.Get("resource_group_name").(string)
|
||||
AccountName := d.Get("account_name").(string)
|
||||
|
||||
if requireResourcesToBeImported {
|
||||
|
@ -135,7 +135,7 @@ func resourceArmBatchApplicationRead(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
|
||||
d.Set("name", name)
|
||||
d.Set("resource_group", resourceGroup)
|
||||
d.Set("resource_group_name", resourceGroup)
|
||||
d.Set("account_name", AccountName)
|
||||
|
||||
return nil
|
||||
|
@ -146,7 +146,7 @@ func resourceArmBatchApplicationUpdate(d *schema.ResourceData, meta interface{})
|
|||
ctx := meta.(*ArmClient).StopContext
|
||||
|
||||
name := d.Get("name").(string)
|
||||
resourceGroup := d.Get("resource_group").(string)
|
||||
resourceGroup := d.Get("resource_group_name").(string)
|
||||
AccountName := d.Get("account_name").(string)
|
||||
allowUpdates := d.Get("allow_updates").(bool)
|
||||
defaultVersion := d.Get("default_version").(string)
|
||||
|
|
|
@ -24,6 +24,31 @@ import (
|
|||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
|
||||
)
|
||||
|
||||
func TestAccAzureRMBatchApplication_basic(t *testing.T) {
|
||||
resourceName := "azurerm_batch_application.test"
|
||||
ri := tf.AccRandTimeInt()
|
||||
location := testLocation()
|
||||
|
||||
resource.ParallelTest(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMBatchApplicationDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccAzureRMBatchApplication_basic(ri, location),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMBatchApplicationExists(resourceName),
|
||||
),
|
||||
},
|
||||
{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func testCheckAzureRMBatchApplicationExists(resourceName string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
|
@ -33,7 +58,7 @@ func testCheckAzureRMBatchApplicationExists(resourceName string) resource.TestCh
|
|||
}
|
||||
|
||||
name := rs.Primary.Attributes["name"]
|
||||
resourceGroup := rs.Primary.Attributes["resource_group"]
|
||||
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||
AccountName := rs.Primary.Attributes["account_name"]
|
||||
|
||||
client := testAccProvider.Meta().(*ArmClient).applicationClient
|
||||
|
@ -60,7 +85,7 @@ func testCheckAzureRMBatchApplicationDestroy(s *terraform.State) error {
|
|||
}
|
||||
|
||||
name := rs.Primary.Attributes["name"]
|
||||
resourceGroup := rs.Primary.Attributes["resource_group"]
|
||||
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||
AccountName := rs.Primary.Attributes["account_name"]
|
||||
|
||||
if resp, err := client.Get(ctx, resourceGroup, AccountName, name); err != nil {
|
||||
|
@ -74,3 +99,34 @@ func testCheckAzureRMBatchApplicationDestroy(s *terraform.State) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func testAccAzureRMBatchApplication_basic(rInt int, location string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acctestRG-%d"
|
||||
location = "%s"
|
||||
}
|
||||
|
||||
resource "azurerm_storage_account" "test" {
|
||||
name = "acctestsa-%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
location = "${azurerm_resource_group.test.location}"
|
||||
accountTier = "Standard"
|
||||
accountReplicationType = "LRS"
|
||||
}
|
||||
|
||||
resource "azurerm_batch_account" "test" {
|
||||
name = "acctestbatch-%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
location = "${azurerm_resource_group.test.location}"
|
||||
poolAllocationMode = "BatchService"
|
||||
storageAccountId = "${azurerm_storage_account.test.id}"
|
||||
}
|
||||
|
||||
resource "azurerm_batch_application" "test" {
|
||||
name = "acctestbatchapp-%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
account_name = "${azurerm_batch_account.test.name}"
|
||||
}
|
||||
`, rInt, location, rInt, rInt, rInt)
|
||||
}
|
||||
|
|
|
@ -24,13 +24,44 @@ description: |-
|
|||
Manage Azure Application instance.
|
||||
|
||||
|
||||
## Example Usage
|
||||
|
||||
```hcl
|
||||
resource "azurerm_resource_group" "example" {
|
||||
name = "example-rg"
|
||||
location = "West US"
|
||||
}
|
||||
|
||||
resource "azurerm_storage_account" "example" {
|
||||
name = "examplesa"
|
||||
resource_group_name = "${azurerm_resource_group.example.name}"
|
||||
location = "${azurerm_resource_group.example.location}"
|
||||
accountTier = "Standard"
|
||||
accountReplicationType = "LRS"
|
||||
}
|
||||
|
||||
resource "azurerm_batch_account" "example" {
|
||||
name = "example-batch-account"
|
||||
resource_group_name = "${azurerm_resource_group.example.name}"
|
||||
location = "${azurerm_resource_group.example.location}"
|
||||
poolAllocationMode = "BatchService"
|
||||
storageAccountId = "${azurerm_storage_account.example.id}"
|
||||
}
|
||||
|
||||
resource "azurerm_batch_application" "example" {
|
||||
name = "example-batch-application"
|
||||
resource_group_name = "${azurerm_resource_group.example.name}"
|
||||
account_name = "${azurerm_batch_account.example.name}"
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The name of the application. This must be unique within the account. Changing this forces a new resource to be created.
|
||||
|
||||
* `resource_group` - (Required) The name of the resource group that contains the Batch account. Changing this forces a new resource to be created.
|
||||
* `resource_group_name` - (Required) The name of the resource group that contains the Batch account. Changing this forces a new resource to be created.
|
||||
|
||||
* `account_name` - (Required) The name of the Batch account. Changing this forces a new resource to be created.
|
||||
|
||||
|
@ -43,3 +74,12 @@ The following arguments are supported:
|
|||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
||||
|
||||
## Import
|
||||
|
||||
Batch Application can be imported using the `resource id`, e.g.
|
||||
|
||||
```shell
|
||||
$ terraform import azurerm_batch_application.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Batch/batchAccounts/example-batch-account/applications/example-batch-application
|
||||
```
|
||||
|
|
|
@ -12,4 +12,15 @@ manifest: !ruby/object:Provider::Ansible::Manifest
|
|||
overrides: !ruby/object:Provider::ResourceOverrides
|
||||
Application: !ruby/object:Provider::Azure::Ansible::ResourceOverride
|
||||
name: BatchApplication
|
||||
examples: []
|
||||
examples:
|
||||
- !ruby/object:Provider::Azure::Ansible::ResourceOverride::DocumentExampleReference
|
||||
example: basic
|
||||
resource_name_hints:
|
||||
resourceGroups: MyResGroup
|
||||
storageAccounts: mystorageaccountname
|
||||
batchAccounts: mybatchaccount
|
||||
batchApplications: mybatchapplication
|
||||
inttests:
|
||||
- !ruby/object:Provider::Azure::Ansible::ResourceOverride::IntegrationTestDefinition
|
||||
example: basic
|
||||
delete_example: delete
|
|
@ -0,0 +1,14 @@
|
|||
--- !ruby/object:Provider::Azure::Example
|
||||
resource: azure_rm_batchapplication
|
||||
description: Create Batch Application
|
||||
prerequisites:
|
||||
- !ruby/object:Provider::Azure::ExampleReference
|
||||
product: storageaccount
|
||||
example: basic
|
||||
- !ruby/object:Provider::Azure::ExampleReference
|
||||
product: batchaccount
|
||||
example: basic
|
||||
properties:
|
||||
resourceGroup: "<%= get_resource_name('resourceGroups', 'resource_group') -%>"
|
||||
name: "<%= get_resource_name('batchApplications', 'batch_application_name', 'bap') -%>"
|
||||
account_name: "<%= get_resource_name('batchAccounts', 'batch_account_name', 'ba') -%>"
|
|
@ -0,0 +1,15 @@
|
|||
--- !ruby/object:Provider::Azure::Example
|
||||
resource: azure_rm_batchapplication
|
||||
description: Delete Batch Application
|
||||
prerequisites:
|
||||
- !ruby/object:Provider::Azure::ExampleReference
|
||||
product: batchaccount
|
||||
example: delete
|
||||
- !ruby/object:Provider::Azure::ExampleReference
|
||||
product: storageaccount
|
||||
example: delete
|
||||
properties:
|
||||
resourceGroup: "<%= get_resource_name('resourceGroups', 'resource_group') -%>"
|
||||
name: "<%= get_resource_name('batchApplications', 'batch_application_name', 'bap') -%>"
|
||||
account_name: "<%= get_resource_name('batchAccounts', 'batch_account_name', 'ba') -%>"
|
||||
state: absent
|
|
@ -0,0 +1,16 @@
|
|||
--- !ruby/object:Provider::Azure::Example
|
||||
resource: azurerm_batch_application
|
||||
prerequisites:
|
||||
- !ruby/object:Provider::Azure::ExampleReference
|
||||
product: resourcegroup
|
||||
example: basic
|
||||
- !ruby/object:Provider::Azure::ExampleReference
|
||||
product: storageaccount
|
||||
example: basic
|
||||
- !ruby/object:Provider::Azure::ExampleReference
|
||||
product: batchaccount
|
||||
example: basic
|
||||
properties:
|
||||
name: "<%= get_resource_name('applications', 'batchapp') -%>"
|
||||
resource_group_name: ${azurerm_resource_group.<%= resource_id_hint -%>.name}
|
||||
account_name: ${azurerm_batch_account.<%= resource_id_hint -%>.name}
|
|
@ -2,4 +2,22 @@
|
|||
overrides: !ruby/object:Provider::ResourceOverrides
|
||||
Application: !ruby/object:Provider::Azure::Terraform::ResourceOverride
|
||||
name: BatchApplication
|
||||
properties: {}
|
||||
properties:
|
||||
name: !ruby/object:Provider::Terraform::PropertyOverride
|
||||
order: 100
|
||||
resourceGroup: !ruby/object:Provider::Terraform::PropertyOverride
|
||||
name: resourceGroupName
|
||||
acctests:
|
||||
- !ruby/object:Provider::Azure::Terraform::ResourceOverride::AccTestDefinition
|
||||
name: basic
|
||||
steps: [basic]
|
||||
document_examples:
|
||||
- !ruby/object:Provider::Azure::Terraform::ResourceOverride::DocumentExampleReference
|
||||
title: Example Usage
|
||||
example_name: basic
|
||||
resource_name_hints:
|
||||
resourceGroups: example-rg
|
||||
storageAccounts: examplesa
|
||||
batchAccounts: example-batch-account
|
||||
applications: example-batch-application
|
||||
location: West US
|
||||
|
|
Загрузка…
Ссылка в новой задаче