Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New resource/data source
azurerm_logic_app_integration_account
(#7099)
- Loading branch information
Showing
18 changed files
with
966 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
azurerm/internal/services/logic/logic_app_integration_account_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package logic | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceLogicAppIntegrationAccount() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmLogicAppIntegrationAccountRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"sku_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tags.SchemaDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmLogicAppIntegrationAccountRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Logic.IntegrationAccountClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Logic App Integration Account Account %q does not exist in Resource Group %q", name, resourceGroup) | ||
} | ||
return fmt.Errorf("retrieving Logic App Integration Account Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("reading Logic App Integration Account Account %q (Resource Group %q): ID is empty or nil", name, resourceGroup) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("location", location.NormalizeNilable(resp.Location)) | ||
d.Set("sku_name", string(resp.Sku.Name)) | ||
return tags.FlattenAndSet(d, resp.Tags) | ||
} |
151 changes: 151 additions & 0 deletions
151
azurerm/internal/services/logic/logic_app_integration_account_resource.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package logic | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2019-05-01/logic" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/logic/parse" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/logic/validate" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" | ||
azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func resourceArmLogicAppIntegrationAccount() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmLogicAppIntegrationAccountCreateUpdate, | ||
Read: resourceArmLogicAppIntegrationAccountRead, | ||
Update: resourceArmLogicAppIntegrationAccountCreateUpdate, | ||
Delete: resourceArmLogicAppIntegrationAccountDelete, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(30 * time.Minute), | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
Update: schema.DefaultTimeout(30 * time.Minute), | ||
Delete: schema.DefaultTimeout(30 * time.Minute), | ||
}, | ||
|
||
Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { | ||
_, err := parse.IntegrationAccountID(id) | ||
return err | ||
}), | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validate.IntegrationAccountName(), | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupName(), | ||
|
||
"location": azure.SchemaLocation(), | ||
|
||
"sku_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(logic.IntegrationAccountSkuNameBasic), | ||
string(logic.IntegrationAccountSkuNameFree), | ||
string(logic.IntegrationAccountSkuNameStandard), | ||
}, false), | ||
}, | ||
|
||
"tags": tags.Schema(), | ||
}, | ||
} | ||
} | ||
func resourceArmLogicAppIntegrationAccountCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Logic.IntegrationAccountClient | ||
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
if d.IsNewResource() { | ||
existing, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if !utils.ResponseWasNotFound(existing.Response) { | ||
return fmt.Errorf("checking for present of existing Integration Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
} | ||
if existing.ID != nil && *existing.ID != "" { | ||
return tf.ImportAsExistsError("azurerm_logic_app_integration_account", *existing.ID) | ||
} | ||
} | ||
|
||
account := logic.IntegrationAccount{ | ||
IntegrationAccountProperties: &logic.IntegrationAccountProperties{}, | ||
Location: utils.String(location.Normalize(d.Get("location").(string))), | ||
Sku: &logic.IntegrationAccountSku{ | ||
Name: logic.IntegrationAccountSkuName(d.Get("sku_name").(string)), | ||
}, | ||
Tags: tags.Expand(d.Get("tags").(map[string]interface{})), | ||
} | ||
|
||
if _, err := client.CreateOrUpdate(ctx, resourceGroup, name, account); err != nil { | ||
return fmt.Errorf("creating Integration Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("retrieving Integration Account %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("reading Integration Account %q (Resource Group %q): ID is empty or nil", name, resourceGroup) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
return resourceArmLogicAppIntegrationAccountRead(d, meta) | ||
} | ||
|
||
func resourceArmLogicAppIntegrationAccountRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Logic.IntegrationAccountClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := parse.IntegrationAccountID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resp, err := client.Get(ctx, id.ResourceGroup, id.Name) | ||
if err != nil { | ||
return fmt.Errorf("retrieving Integration Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) | ||
} | ||
d.Set("name", id.Name) | ||
d.Set("resource_group_name", id.ResourceGroup) | ||
d.Set("location", location.NormalizeNilable(resp.Location)) | ||
d.Set("sku_name", string(resp.Sku.Name)) | ||
|
||
return tags.FlattenAndSet(d, resp.Tags) | ||
} | ||
|
||
func resourceArmLogicAppIntegrationAccountDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Logic.IntegrationAccountClient | ||
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := parse.IntegrationAccountID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, err := client.Delete(ctx, id.ResourceGroup, id.Name); err != nil { | ||
return fmt.Errorf("deleting Integration Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type IntegrationAccountId struct { | ||
ResourceGroup string | ||
Name string | ||
} | ||
|
||
func IntegrationAccountID(input string) (*IntegrationAccountId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing Integration Account ID %q: %+v", input, err) | ||
} | ||
|
||
IntegrationAccount := IntegrationAccountId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
if IntegrationAccount.Name, err = id.PopSegment("integrationAccounts"); err != nil { | ||
return nil, err | ||
} | ||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &IntegrationAccount, nil | ||
} |
Oops, something went wrong.