-
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: azurerm_relay_hybrid_connection
#4832
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
60a5eda
Add HybridConnectionsClient
DSakura207 08776a1
Add placeholder for resource and test
DSakura207 bf6f821
Rename file for hybrid connection
DSakura207 d154568
Add unit test
DSakura207 d6fa441
Fix testcase and import
DSakura207 360a96f
Add Relay Hybrid Connection support
DSakura207 a73f489
Add resource mapping
DSakura207 c92be40
Fix typos
DSakura207 8308a10
Update values for correct depedencies
DSakura207 d23f6a0
Align with Azure Portal settings
DSakura207 1efdb73
Workaround for updating requires_client_authorization
DSakura207 0e66879
Add test for updating requires_client_authorization
DSakura207 fe6132b
Add document for azurerm_relay_hybrid_connection
DSakura207 5246848
Add optional requires_client_authorization in example
DSakura207 1e7856b
Support UserMetadata
DSakura207 8ee9c9b
Support UserMetadata
DSakura207 a85eb9b
Add description for user_metadata
DSakura207 8884ca3
Fix copy-and-paste error
DSakura207 bbb4c9f
Add subcategory
DSakura207 4d782e4
Apply code review
DSakura207 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,193 @@ | ||
package azurerm | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/relay/mgmt/2017-04-01/relay" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"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/helpers/response" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func resourceArmHybridConnection() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmHybridConnectionCreateUpdate, | ||
Read: resourceArmHybridConnectionRead, | ||
Update: resourceArmHybridConnectionCreateUpdate, | ||
Delete: resourceArmHybridConnectionDelete, | ||
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: validate.NoEmptyStrings, | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupName(), | ||
|
||
"relay_namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, | ||
|
||
"requires_client_authorization": { | ||
Type: schema.TypeBool, | ||
Default: true, | ||
ForceNew: true, | ||
Optional: true, | ||
}, | ||
"user_metadata": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmHybridConnectionCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).Relay.HybridConnectionsClient | ||
ctx, cancel := timeouts.ForCreateUpdate(meta.(*ArmClient).StopContext, d) | ||
defer cancel() | ||
|
||
log.Printf("[INFO] preparing arguments for Relay Hybrid Connection creation.") | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
relayNamespace := d.Get("relay_namespace_name").(string) | ||
requireClientAuthroization := d.Get("requires_client_authorization").(bool) | ||
userMetadata := d.Get("user_metadata").(string) | ||
|
||
parameters := relay.HybridConnection{ | ||
HybridConnectionProperties: &relay.HybridConnectionProperties{ | ||
RequiresClientAuthorization: &requireClientAuthroization, | ||
UserMetadata: &userMetadata, | ||
}, | ||
} | ||
|
||
_, err := client.CreateOrUpdate(ctx, resourceGroup, relayNamespace, name, parameters) | ||
if err != nil { | ||
return fmt.Errorf("Error creating Relay Hybrid Connection %q (Namespace %q Resource Group %q): %+v", name, relayNamespace, resourceGroup, err) | ||
} | ||
|
||
read, err := client.Get(ctx, resourceGroup, relayNamespace, name) | ||
if err != nil { | ||
return fmt.Errorf("Error issuing get request for Relay Hybrid Connection %q (Namespace %q Resource Group %q): %+v", name, relayNamespace, resourceGroup, err) | ||
} | ||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read Relay Hybrid Connection %q (Namespace %q Resource group %s) ID", name, relayNamespace, resourceGroup) | ||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmHybridConnectionRead(d, meta) | ||
} | ||
|
||
func resourceArmHybridConnectionRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).Relay.HybridConnectionsClient | ||
ctx, cancel := timeouts.ForCreateUpdate(meta.(*ArmClient).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := azure.ParseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resourceGroup := id.ResourceGroup | ||
relayNamespace := id.Path["namespaces"] | ||
name := id.Path["hybridConnections"] | ||
|
||
resp, err := client.Get(ctx, resourceGroup, relayNamespace, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on Relay Hybrid Connection %q (Namespace %q Resource Group %q): %s", name, relayNamespace, resourceGroup, err) | ||
} | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("relay_namespace_name", relayNamespace) | ||
|
||
if props := resp.HybridConnectionProperties; props != nil { | ||
d.Set("requires_client_authorization", props.RequiresClientAuthorization) | ||
d.Set("user_metadata", props.UserMetadata) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmHybridConnectionDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).Relay.HybridConnectionsClient | ||
ctx, cancel := timeouts.ForCreateUpdate(meta.(*ArmClient).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := azure.ParseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resourceGroup := id.ResourceGroup | ||
relayNamespace := id.Path["namespaces"] | ||
name := id.Path["hybridConnections"] | ||
|
||
log.Printf("[INFO] Waiting for Relay Hybrid Connection %q (Namespace %q Resource Group %q) to be deleted", name, relayNamespace, resourceGroup) | ||
rc, err := client.Delete(ctx, resourceGroup, relayNamespace, name) | ||
|
||
if err != nil { | ||
if response.WasNotFound(rc.Response) { | ||
return nil | ||
} | ||
|
||
return err | ||
} | ||
|
||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{"Pending"}, | ||
Target: []string{"Deleted"}, | ||
Refresh: hybridConnectionDeleteRefreshFunc(ctx, client, resourceGroup, relayNamespace, name), | ||
Timeout: 30 * time.Minute, | ||
MinTimeout: 15 * time.Second, | ||
} | ||
|
||
if _, err := stateConf.WaitForState(); err != nil { | ||
return fmt.Errorf("Error waiting for Relay Hybrid Connection %q (Namespace %q Resource Group %q) to be deleted: %s", name, relayNamespace, resourceGroup, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func hybridConnectionDeleteRefreshFunc(ctx context.Context, client *relay.HybridConnectionsClient, resourceGroupName string, relayNamespace string, name string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
res, err := client.Get(ctx, resourceGroupName, relayNamespace, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(res.Response) { | ||
return res, "Deleted", nil | ||
} | ||
|
||
return nil, "Error", fmt.Errorf("Error issuing read request in relayNamespaceDeleteRefreshFunc to Relay Hybrid Connection %q (Namespace %q Resource Group %q): %s", name, relayNamespace, resourceGroupName, err) | ||
} | ||
|
||
return res, "Pending", nil | ||
} | ||
} |
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.
This should be moved up one to keep this list alphabetical