forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Healthcareapi/workspace (hashicorp#15759)
* add pandora sdk for healthcare api * add workspace * workspace * hc worksapce update * remove pandora sdk * fmt * sort import * update * tidy vendor * update workspace * rename * go mod * add healthcare workspace data source docs and add an update test for tags for healthcare workspace resource Co-authored-by: Steph <[email protected]>
- Loading branch information
Showing
38 changed files
with
8,424 additions
and
1,440 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
package client | ||
|
||
import ( | ||
healthcare "github.com/Azure/azure-sdk-for-go/services/healthcareapis/mgmt/2020-03-30/healthcareapis" | ||
"github.com/Azure/azure-sdk-for-go/services/healthcareapis/mgmt/2021-11-01/healthcareapis" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/common" | ||
) | ||
|
||
type Client struct { | ||
HealthcareServiceClient *healthcare.ServicesClient | ||
HealthcareServiceClient *healthcareapis.ServicesClient | ||
HealthcareWorkspaceClient *healthcareapis.WorkspacesClient | ||
} | ||
|
||
func NewClient(o *common.ClientOptions) *Client { | ||
HealthcareServiceClient := healthcare.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
HealthcareServiceClient := healthcareapis.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&HealthcareServiceClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
HealthcareWorkspaceClient := healthcareapis.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&HealthcareWorkspaceClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
return &Client{ | ||
HealthcareServiceClient: &HealthcareServiceClient, | ||
HealthcareServiceClient: &HealthcareServiceClient, | ||
HealthcareWorkspaceClient: &HealthcareWorkspaceClient, | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
internal/services/healthcare/healthcare_workspace_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,67 @@ | ||
package healthcare | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" | ||
"github.com/hashicorp/go-azure-helpers/resourcemanager/location" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/parse" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/validate" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tags" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" | ||
"github.com/hashicorp/terraform-provider-azurerm/utils" | ||
) | ||
|
||
func dataSourceHealthcareWorkspace() *pluginsdk.Resource { | ||
return &pluginsdk.Resource{ | ||
Read: dataSourceHealthcareWorkspaceRead, | ||
|
||
Timeouts: &pluginsdk.ResourceTimeout{ | ||
Read: pluginsdk.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validate.WorkspaceName, | ||
}, | ||
|
||
"resource_group_name": commonschema.ResourceGroupName(), | ||
|
||
"location": commonschema.LocationComputed(), | ||
|
||
"tags": tags.SchemaDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceHealthcareWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceClient | ||
subscriptionId := meta.(*clients.Client).Account.SubscriptionId | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id := parse.NewWorkspaceID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) | ||
resp, err := client.Get(ctx, id.ResourceGroup, id.Name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("%s was not found", id) | ||
} | ||
return fmt.Errorf("retrieving %s: %+v", id, err) | ||
} | ||
|
||
d.SetId(id.ID()) | ||
|
||
d.Set("name", id.Name) | ||
d.Set("resource_group_name", id.ResourceGroup) | ||
|
||
if locations := resp.Location; locations != nil { | ||
d.Set("location", location.Normalize(*locations)) | ||
} | ||
|
||
return tags.FlattenAndSet(d, resp.Tags) | ||
} |
35 changes: 35 additions & 0 deletions
35
internal/services/healthcare/healthcare_workspace_data_source_test.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,35 @@ | ||
package healthcare_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type HealthCareWorkspaceDataSource struct{} | ||
|
||
func TestAccHealthCareWorkspaceDataSource_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_healthcare_workspace", "test") | ||
r := HealthCareWorkspaceDataSource{} | ||
|
||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("name").Exists()), | ||
}, | ||
}) | ||
} | ||
|
||
func (HealthCareWorkspaceDataSource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_healthcare_workspace" "test" { | ||
name = azurerm_healthcare_workspace.test.name | ||
resource_group_name = azurerm_healthcare_workspace.test.resource_group_name | ||
} | ||
`, HealthCareWorkspaceResource{}.complete(data)) | ||
} |
217 changes: 217 additions & 0 deletions
217
internal/services/healthcare/healthcare_workspace_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,217 @@ | ||
package healthcare | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/healthcareapis/mgmt/2021-11-01/healthcareapis" | ||
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" | ||
"github.com/hashicorp/go-azure-helpers/resourcemanager/location" | ||
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/parse" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/validate" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tags" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" | ||
"github.com/hashicorp/terraform-provider-azurerm/utils" | ||
) | ||
|
||
func resourceHealthcareApisWorkspace() *pluginsdk.Resource { | ||
return &pluginsdk.Resource{ | ||
Create: resourceHealthcareApisWorkspaceCreate, | ||
Read: resourceHealthcareApisWorkspaceRead, | ||
Update: resourceHealthcareApisWorkspaceUpdate, | ||
Delete: resourceHealthcareApisWorkspaceDelete, | ||
|
||
Timeouts: &pluginsdk.ResourceTimeout{ | ||
Create: pluginsdk.DefaultTimeout(30 * time.Minute), | ||
Read: pluginsdk.DefaultTimeout(5 * time.Minute), | ||
Update: pluginsdk.DefaultTimeout(30 * time.Minute), | ||
Delete: pluginsdk.DefaultTimeout(30 * time.Minute), | ||
}, | ||
|
||
Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { | ||
_, err := parse.WorkspaceID(id) | ||
return err | ||
}), | ||
|
||
Schema: map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validate.WorkspaceName, | ||
}, | ||
|
||
"resource_group_name": commonschema.ResourceGroupName(), | ||
|
||
"location": commonschema.Location(), | ||
|
||
"private_endpoint_connection": { | ||
Type: pluginsdk.TypeSet, | ||
Computed: true, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"tags": commonschema.Tags(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceHealthcareApisWorkspaceCreate(d *pluginsdk.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceClient | ||
subscriptionId := meta.(*clients.Client).Account.SubscriptionId | ||
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
log.Printf("[INFO] preparing arguments for AzureRM Healthcare Workspace creation.") | ||
|
||
id := parse.NewWorkspaceID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) | ||
if d.IsNewResource() { | ||
existing, err := client.Get(ctx, id.ResourceGroup, id.Name) | ||
if err != nil { | ||
if !utils.ResponseWasNotFound(existing.Response) { | ||
return fmt.Errorf("checking for presence of existing %s: %+v", id, err) | ||
} | ||
} | ||
if !utils.ResponseWasNotFound(existing.Response) { | ||
return tf.ImportAsExistsError("azurerm_healthcare_workspace", id.ID()) | ||
} | ||
} | ||
|
||
location := location.Normalize(d.Get("location").(string)) | ||
t := d.Get("tags").(map[string]interface{}) | ||
|
||
parameters := healthcareapis.Workspace{ | ||
Location: &location, | ||
Tags: tags.Expand(t), | ||
} | ||
|
||
future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) | ||
if err != nil { | ||
return fmt.Errorf("creating/ updating %s: %+v", id, err) | ||
} | ||
|
||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
return fmt.Errorf("waiting for creation/update of %s: %+v", id, err) | ||
} | ||
|
||
d.SetId(id.ID()) | ||
|
||
return resourceHealthcareApisWorkspaceRead(d, meta) | ||
} | ||
|
||
func resourceHealthcareApisWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := parse.WorkspaceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resp, err := client.Get(ctx, id.ResourceGroup, id.Name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("retrieving %s: %+v", *id, err) | ||
} | ||
|
||
d.Set("name", id.Name) | ||
d.Set("resource_group_name", id.ResourceGroup) | ||
if locations := resp.Location; locations != nil { | ||
d.Set("location", location.Normalize(*locations)) | ||
} | ||
|
||
if props := resp.Properties; props != nil { | ||
d.Set("private_endpoint_connection", flattenWorkspacePrivateEndpoint(props.PrivateEndpointConnections)) | ||
} | ||
|
||
return tags.FlattenAndSet(d, resp.Tags) | ||
} | ||
|
||
func resourceHealthcareApisWorkspaceUpdate(d *pluginsdk.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceClient | ||
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := parse.WorkspaceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
t := d.Get("tags").(map[string]interface{}) | ||
|
||
parameters := healthcareapis.WorkspacePatchResource{ | ||
Tags: tags.Expand(t), | ||
} | ||
|
||
future, err := client.Update(ctx, id.ResourceGroup, id.Name, parameters) | ||
if err != nil { | ||
return fmt.Errorf("updating %s: %+v", id, err) | ||
} | ||
|
||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
return fmt.Errorf("waiting for update of %s: %+v", id, err) | ||
} | ||
|
||
d.SetId(id.ID()) | ||
|
||
return resourceHealthcareApisWorkspaceRead(d, meta) | ||
} | ||
|
||
func resourceHealthcareApisWorkspaceDelete(d *pluginsdk.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).HealthCare.HealthcareWorkspaceClient | ||
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
id, err := parse.WorkspaceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
future, err := client.Delete(ctx, id.ResourceGroup, id.Name) | ||
if err != nil { | ||
return fmt.Errorf("deleting %s: %+v", id, err) | ||
} | ||
|
||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||
return fmt.Errorf("waiting for the deletion of %s: %+v", *id, err) | ||
} | ||
return nil | ||
} | ||
|
||
func flattenWorkspacePrivateEndpoint(input *[]healthcareapis.PrivateEndpointConnection) []interface{} { | ||
results := make([]interface{}, 0) | ||
if input == nil { | ||
return results | ||
} | ||
|
||
for _, endpoint := range *input { | ||
result := map[string]interface{}{} | ||
if endpoint.Name != nil { | ||
result["name"] = *endpoint.Name | ||
} | ||
|
||
if endpoint.ID != nil { | ||
result["id"] = *endpoint.ID | ||
} | ||
} | ||
return results | ||
} |
Oops, something went wrong.