-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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 resources: azurerm_eventhub_namespace_dedicated and azurerm_eventhub_dedicated #7347
Closed
favoretti
wants to merge
48
commits into
hashicorp:master
from
favoretti:adjust_partition_count_validator
Closed
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
39b309f
Adjust partition count validator
favoretti cec7b0f
Update tests
favoretti f8f4f58
Up retention limits to fit eventhub clusters
favoretti 977375b
WIP: dedicated eventhubs
favoretti 44934a3
Fix tests
favoretti 9680d01
Revert error messages to what they should be
favoretti 50dd95a
Add tests
favoretti b8d1041
Fix typos, add registration
favoretti 2401a49
More typoes, set locks for both normal and dedicated hubs and namespaces
favoretti d049c1c
Fix last linter error
favoretti 1b2f139
Added documentation
favoretti 6b42455
Update CHANGELOG
favoretti 5689261
Sigh, more typoes
favoretti 2d0372e
Update website/docs/r/eventhub_dedicated.html.markdown
favoretti ec54ba7
Update website/docs/r/eventhub_dedicated.html.markdown
favoretti a626c83
Update azurerm/internal/services/eventhub/eventhub_dedicated_resource.go
favoretti b65f3c0
Update website/docs/r/eventhub_dedicated.html.markdown
favoretti 0b18f1e
Update website/docs/r/eventhub_namespace_dedicated.html.markdown
favoretti 25f72f5
Revert "Update CHANGELOG"
favoretti 1a6cdfe
Address review feedback
favoretti 14c3576
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 5c15c31
Update azurerm/internal/services/eventhub/tests/eventhub_dedicated_re…
favoretti f623029
Update azurerm/internal/services/eventhub/tests/eventhub_dedicated_re…
favoretti 9d12d6d
Address feedback batch 2
favoretti dbce63e
Update azurerm/internal/services/eventhub/eventhub_dedicated_resource.go
favoretti 8917af5
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 5452ca4
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 0005649
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 953dbfa
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 8d3c2cf
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 6dbe1e9
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti a662eb4
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 4a3a4e0
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 7cc7328
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 202b886
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 3953e9b
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 33597bf
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 1c33705
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti ca31414
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 0d8452a
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 2f51ac6
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti baff0ed
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 0841593
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti cca9342
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti e3ab34b
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 32c188b
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti 8d3bd89
Update azurerm/internal/services/eventhub/eventhub_namespace_dedicate…
favoretti b4b2a98
Address feedback batch 3
favoretti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
289 changes: 289 additions & 0 deletions
289
azurerm/internal/services/eventhub/eventhub_dedicated_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,289 @@ | ||
package eventhub | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/preview/eventhub/mgmt/2018-01-01-preview/eventhub" | ||
"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/suppress" | ||
"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/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
var eventHubDedicatedResourceName = "azurerm_eventhub_dedicated" | ||
|
||
func resourceArmEventHubDedicated() *schema.Resource { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. taking a look through this appears to be the same as the |
||
return &schema.Resource{ | ||
Create: resourceArmEventHubDedicatedCreateUpdate, | ||
Read: resourceArmEventHubDedicatedRead, | ||
Update: resourceArmEventHubDedicatedCreateUpdate, | ||
Delete: resourceArmEventHubDedicatedDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
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), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: azure.ValidateEventHubName(), | ||
}, | ||
|
||
"namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: azure.ValidateEventHubNamespaceName(), | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupName(), | ||
|
||
"partition_count": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: ValidateEventHubDedicatedPartitionCount, | ||
}, | ||
|
||
"message_retention": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ValidateFunc: ValidateEventHubDedicatedMessageRetentionCount, | ||
}, | ||
|
||
"capture_description": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"enabled": { | ||
Type: schema.TypeBool, | ||
Required: true, | ||
}, | ||
"skip_empty_archives": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
"encoding": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DiffSuppressFunc: suppress.CaseDifference, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(eventhub.Avro), | ||
string(eventhub.AvroDeflate), | ||
}, true), | ||
}, | ||
"interval_in_seconds": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 300, | ||
ValidateFunc: validation.IntBetween(60, 900), | ||
}, | ||
"size_limit_in_bytes": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 314572800, | ||
ValidateFunc: validation.IntBetween(10485760, 524288000), | ||
}, | ||
"destination": { | ||
Type: schema.TypeList, | ||
Required: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"EventHubArchive.AzureBlockBlob", | ||
// TODO: support `EventHubArchive.AzureDataLake` once supported in the Swagger / SDK | ||
// https://github.com/Azure/azure-rest-api-specs/issues/2255 | ||
// BlobContainerName & StorageAccountID can then become Optional | ||
}, false), | ||
}, | ||
"archive_name_format": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: ValidateEventHubArchiveNameFormat, | ||
}, | ||
"blob_container_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"storage_account_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateResourceID, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"partition_ids": { | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmEventHubDedicatedCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Eventhub.EventHubsClient | ||
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
log.Printf("[INFO] preparing arguments for Azure ARM EventHub creation.") | ||
|
||
name := d.Get("name").(string) | ||
namespaceName := d.Get("namespace_name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
if d.IsNewResource() { | ||
existing, err := client.Get(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
if !utils.ResponseWasNotFound(existing.Response) { | ||
return fmt.Errorf("Error checking for presence of existing Dedicated EventHub %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err) | ||
} | ||
} | ||
|
||
if existing.ID != nil && *existing.ID != "" { | ||
return tf.ImportAsExistsError("azurerm_eventhub", *existing.ID) | ||
} | ||
} | ||
|
||
partitionCount := int64(d.Get("partition_count").(int)) | ||
messageRetention := int64(d.Get("message_retention").(int)) | ||
|
||
parameters := eventhub.Model{ | ||
Properties: &eventhub.Properties{ | ||
PartitionCount: &partitionCount, | ||
MessageRetentionInDays: &messageRetention, | ||
}, | ||
} | ||
|
||
if _, ok := d.GetOk("capture_description"); ok { | ||
parameters.Properties.CaptureDescription = expandEventHubCaptureDescription(d) | ||
} | ||
|
||
if _, err := client.CreateOrUpdate(ctx, resourceGroup, namespaceName, name, parameters); err != nil { | ||
return err | ||
} | ||
|
||
read, err := client.Get(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read EventHub %s (resource group %s) ID", name, resourceGroup) | ||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmEventHubDedicatedRead(d, meta) | ||
} | ||
|
||
func resourceArmEventHubDedicatedRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Eventhub.EventHubsClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := azure.ParseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
namespaceName := id.Path["namespaces"] | ||
name := id.Path["eventhubs"] | ||
resp, err := client.Get(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("Error making Read request on Azure EventHub %q (resource group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("namespace_name", namespaceName) | ||
d.Set("resource_group_name", resourceGroup) | ||
|
||
if props := resp.Properties; props != nil { | ||
d.Set("partition_count", props.PartitionCount) | ||
d.Set("message_retention", props.MessageRetentionInDays) | ||
d.Set("partition_ids", props.PartitionIds) | ||
|
||
captureDescription := flattenEventHubCaptureDescription(props.CaptureDescription) | ||
if err := d.Set("capture_description", captureDescription); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmEventHubDedicatedDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).Eventhub.EventHubsClient | ||
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
id, err := azure.ParseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
namespaceName := id.Path["namespaces"] | ||
name := id.Path["eventhubs"] | ||
resp, err := client.Delete(ctx, resourceGroup, namespaceName, name) | ||
|
||
if err != nil { | ||
if utils.ResponseWasNotFound(resp) { | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Error issuing delete request for EventHub %q (resource group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func ValidateEventHubDedicatedPartitionCount(v interface{}, _ string) (warnings []string, errors []error) { | ||
value := v.(int) | ||
|
||
if !(1024 >= value && value >= 1) { | ||
errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 1024")) | ||
} | ||
|
||
return warnings, errors | ||
} | ||
|
||
func ValidateEventHubDedicatedMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) { | ||
value := v.(int) | ||
|
||
if !(90 >= value && value >= 1) { | ||
errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 90")) | ||
} | ||
|
||
return warnings, errors | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I missed on the first pass, but we'll need this locking in the
resourceArmEventHubAuthorizationRuleDelete
func too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSFT isn't super clear on naming either it seems. Lots of documentation calls them dedicated eventhubs, however portal calls them Event Hubs Cluster.