-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update azure-sdk-for-go to v47.0.0 * Updated to v47.1.0 * Update SDK to v48.0.0 * update * update * update * update * update * update * update * update * update * update * update * update * review * Resolve conflicts * Rename and move tests * Fixed test case * gofmt registration Co-authored-by: arcturusZhang <[email protected]> Co-authored-by: Dapeng Zhang <[email protected]> Co-authored-by: Jeffrey Cline <[email protected]>
- Loading branch information
1 parent
abecf58
commit dc4ed94
Showing
9 changed files
with
736 additions
and
1 deletion.
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
184 changes: 184 additions & 0 deletions
184
azurerm/internal/services/digitaltwins/digital_twins_endpoint_eventgrid_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,184 @@ | ||
package digitaltwins | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/digitaltwins/mgmt/2020-10-31/digitaltwins" | ||
"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/tf" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/digitaltwins/parse" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/digitaltwins/validate" | ||
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 resourceDigitalTwinsEndpointEventGrid() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceDigitalTwinsEndpointEventGridCreateUpdate, | ||
Read: resourceDigitalTwinsEndpointEventGridRead, | ||
Update: resourceDigitalTwinsEndpointEventGridCreateUpdate, | ||
Delete: resourceDigitalTwinsEndpointEventGridDelete, | ||
|
||
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.DigitalTwinsEndpointID(id) | ||
return err | ||
}), | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validate.DigitalTwinsInstanceName, | ||
}, | ||
|
||
"digital_twins_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validate.DigitalTwinsInstanceID, | ||
}, | ||
|
||
"eventgrid_topic_endpoint": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.IsURLWithHTTPS, | ||
}, | ||
|
||
"eventgrid_topic_primary_access_key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"eventgrid_topic_secondary_access_key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"dead_letter_storage_secret": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
}, | ||
} | ||
} | ||
func resourceDigitalTwinsEndpointEventGridCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
subscriptionId := meta.(*clients.Client).Account.SubscriptionId | ||
client := meta.(*clients.Client).DigitalTwins.EndpointClient | ||
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
digitalTwinsId, err := parse.DigitalTwinsInstanceID(d.Get("digital_twins_id").(string)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id := parse.NewDigitalTwinsEndpointID(subscriptionId, digitalTwinsId.ResourceGroup, digitalTwinsId.Name, name).ID("") | ||
|
||
if d.IsNewResource() { | ||
existing, err := client.Get(ctx, digitalTwinsId.ResourceGroup, digitalTwinsId.Name, name) | ||
if err != nil { | ||
if !utils.ResponseWasNotFound(existing.Response) { | ||
return fmt.Errorf("checking for present of existing Digital Twins Endpoint %q (Resource Group %q / Instance %q): %+v", name, digitalTwinsId.ResourceGroup, digitalTwinsId.Name, err) | ||
} | ||
} | ||
if !utils.ResponseWasNotFound(existing.Response) { | ||
return tf.ImportAsExistsError("azurerm_digital_twins_endpoint_eventgrid", id) | ||
} | ||
} | ||
|
||
properties := digitaltwins.EndpointResource{ | ||
Properties: &digitaltwins.EventGrid{ | ||
EndpointType: digitaltwins.EndpointTypeEventGrid, | ||
TopicEndpoint: utils.String(d.Get("eventgrid_topic_endpoint").(string)), | ||
AccessKey1: utils.String(d.Get("eventgrid_topic_primary_access_key").(string)), | ||
AccessKey2: utils.String(d.Get("eventgrid_topic_secondary_access_key").(string)), | ||
DeadLetterSecret: utils.String(d.Get("dead_letter_storage_secret").(string)), | ||
}, | ||
} | ||
|
||
future, err := client.CreateOrUpdate(ctx, digitalTwinsId.ResourceGroup, digitalTwinsId.Name, name, properties) | ||
if err != nil { | ||
return fmt.Errorf("creating/updating Digital Twins EventGrid Endpoint %q (Resource Group %q / Instance %q): %+v", name, digitalTwinsId.ResourceGroup, digitalTwinsId.Name, err) | ||
} | ||
|
||
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
return fmt.Errorf("waiting for creation/update of the Digital Twins EventGrid Endpoint %q (Resource Group %q / Instance %q): %+v", name, digitalTwinsId.ResourceGroup, digitalTwinsId.Name, err) | ||
} | ||
|
||
if _, err := client.Get(ctx, digitalTwinsId.ResourceGroup, digitalTwinsId.Name, name); err != nil { | ||
return fmt.Errorf("retrieving Digital Twins EventGrid Endpoint %q (Resource Group %q / Instance %q): %+v", name, digitalTwinsId.ResourceGroup, digitalTwinsId.Name, err) | ||
} | ||
|
||
d.SetId(id) | ||
|
||
return resourceDigitalTwinsEndpointEventGridRead(d, meta) | ||
} | ||
|
||
func resourceDigitalTwinsEndpointEventGridRead(d *schema.ResourceData, meta interface{}) error { | ||
subscriptionId := meta.(*clients.Client).Account.SubscriptionId | ||
client := meta.(*clients.Client).DigitalTwins.EndpointClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := parse.DigitalTwinsEndpointID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resp, err := client.Get(ctx, id.ResourceGroup, id.DigitalTwinsInstanceName, id.EndpointName) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
log.Printf("[INFO] Digital Twins EventGrid Endpoint %q does not exist - removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("retrieving Digital Twins EventGrid Endpoint %q (Resource Group %q / Instance %q): %+v", id.EndpointName, id.ResourceGroup, id.DigitalTwinsInstanceName, err) | ||
} | ||
d.Set("name", id.EndpointName) | ||
d.Set("digital_twins_id", parse.NewDigitalTwinsInstanceID(subscriptionId, id.ResourceGroup, id.DigitalTwinsInstanceName).ID("")) | ||
if resp.Properties != nil { | ||
if _, ok := resp.Properties.AsEventGrid(); !ok { | ||
return fmt.Errorf("retrieving Digital Twins Endpoint %q (Resource Group %q / Instance %q) is not type Event Grid", id.EndpointName, id.ResourceGroup, id.DigitalTwinsInstanceName) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceDigitalTwinsEndpointEventGridDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).DigitalTwins.EndpointClient | ||
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := parse.DigitalTwinsEndpointID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
future, err := client.Delete(ctx, id.ResourceGroup, id.DigitalTwinsInstanceName, id.EndpointName) | ||
if err != nil { | ||
return fmt.Errorf("deleting Digital Twins EventGrid Endpoint %q (Resource Group %q / Instance %q): %+v", id.EndpointName, id.ResourceGroup, id.DigitalTwinsInstanceName, err) | ||
} | ||
|
||
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
return fmt.Errorf("waiting for deletion of the Digital Twins EventGrid Endpoint %q (Resource Group %q / Instance %q): %+v", id.EndpointName, id.ResourceGroup, id.DigitalTwinsInstanceName, err) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.