-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: SignalR service azurerm_signalr_service
#2410
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4d5c75e
Add go sdk support for SignalR
802d270
Add basic signalR resource
9f6296b
Merge branch 'master' into resource_signalr
e161396
Add more outputs to SignalR resource
89899e3
Add documentation related to SignalR
20934bc
Add acceptance tests related to SignalR
7902c86
Add capacity limitation
4f02bbc
Add a more restrict rule to capacity
1af2a9d
Update website/docs/r/signalr.html.markdown
katbyte 29d3211
Update azurerm/resource_arm_signalr.go
tombuildsstuff b5bfc7d
Update azurerm/resource_arm_signalr.go
tombuildsstuff d97e40d
Update azurerm/resource_arm_signalr.go
tombuildsstuff e7f2282
Update azurerm/resource_arm_signalr.go
tombuildsstuff 59e4f50
Update azurerm/resource_arm_signalr.go
tombuildsstuff c1bf09a
Update azurerm/resource_arm_signalr.go
tombuildsstuff 78629c4
Ingest code review feedbacks
dc1c7ff
Update documentation to match the updated schema
4c59566
Change sku name to match the ARM template
90126af
Update website/docs/r/signalr_service.html.markdown
katbyte cbe4d58
Update website/docs/r/signalr_service.html.markdown
katbyte 3dddcc3
Update signalr_service.html.markdown
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
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,212 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/preview/signalr/mgmt/2018-03-01-preview/signalr" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func resourceArmSignalRService() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmSignalRServiceCreateOrUpdate, | ||
Read: resourceArmSignalRServiceRead, | ||
Update: resourceArmSignalRServiceCreateOrUpdate, | ||
Delete: resourceArmSignalRServiceDelete, | ||
|
||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.NoZeroValues, | ||
}, | ||
|
||
"location": locationSchema(), | ||
|
||
"resource_group_name": resourceGroupNameSchema(), | ||
|
||
"sku": { | ||
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{ | ||
"Free_F1", | ||
"Standard_S1", | ||
}, false), | ||
}, | ||
|
||
"capacity": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ValidateFunc: validate.IntInSlice([]int{1, 2, 5, 10, 20, 50, 100}), | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"hostname": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"ip_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"public_port": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"server_port": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tagsSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmSignalRServiceCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).signalRClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
location := azureRMNormalizeLocation(d.Get("location").(string)) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
sku := d.Get("sku").([]interface{}) | ||
|
||
tags := d.Get("tags").(map[string]interface{}) | ||
expandedTags := expandTags(tags) | ||
|
||
parameters := &signalr.CreateParameters{ | ||
Location: utils.String(location), | ||
Sku: expandSignalRServiceSku(sku), | ||
Tags: expandedTags, | ||
} | ||
|
||
future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters) | ||
if err != nil { | ||
return fmt.Errorf("Error creating or updating SignalR %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
return fmt.Errorf("Error waiting for the result of creating or updating SignalR %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
read, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return err | ||
} | ||
if read.ID == nil { | ||
return fmt.Errorf("SignalR %q (Resource Group %q) ID is empty", name, resourceGroup) | ||
} | ||
d.SetId(*read.ID) | ||
|
||
return resourceArmSignalRServiceRead(d, meta) | ||
} | ||
|
||
func resourceArmSignalRServiceRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).signalRClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resourceGroup := id.ResourceGroup | ||
name := id.Path["SignalR"] | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
log.Printf("[DEBUG] SignalR %q was not found in Resource Group %q - removing from state!", name, resourceGroup) | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("Error getting SignalR %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azureRMNormalizeLocation(*location)) | ||
} | ||
if err = d.Set("sku", flattenSignalRServiceSku(resp.Sku)); err != nil { | ||
return fmt.Errorf("Error setting `sku`: %+v", err) | ||
} | ||
if properties := resp.Properties; properties != nil { | ||
d.Set("hostname", properties.HostName) | ||
d.Set("ip_address", properties.ExternalIP) | ||
d.Set("public_port", properties.PublicPort) | ||
d.Set("server_port", properties.ServerPort) | ||
} | ||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmSignalRServiceDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).signalRClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resourceGroup := id.ResourceGroup | ||
name := id.Path["SignalR"] | ||
|
||
future, err := client.Delete(ctx, resourceGroup, name) | ||
if err != nil { | ||
if !response.WasNotFound(future.Response()) { | ||
return fmt.Errorf("Error deleting SignalR %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
return nil | ||
} | ||
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
if !response.WasNotFound(future.Response()) { | ||
return fmt.Errorf("Error waiting for the deletion of SignalR %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func expandSignalRServiceSku(input []interface{}) *signalr.ResourceSku { | ||
v := input[0].(map[string]interface{}) | ||
return &signalr.ResourceSku{ | ||
Name: utils.String(v["name"].(string)), | ||
Capacity: utils.Int32(int32(v["capacity"].(int))), | ||
} | ||
} | ||
|
||
func flattenSignalRServiceSku(input *signalr.ResourceSku) []interface{} { | ||
result := make(map[string]interface{}) | ||
if input != nil { | ||
if input.Name != nil { | ||
result["name"] = *input.Name | ||
} | ||
if input.Capacity != nil { | ||
result["capacity"] = *input.Capacity | ||
} | ||
} | ||
return []interface{}{result} | ||
} |
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.
if input's nil we're going to set an empty sku block in the state (so there'll be an object there but it'll be empty) - can we update this to:
this way it'll show that the Sku block isn't being returned from the API from the fact that Terraform will show the block being removed, rather than the fields being blank