Skip to content

Commit

Permalink
New Resource & DataSource: azurerm_healthcare_service (#4221)
Browse files Browse the repository at this point in the history
Fixes #3989
  • Loading branch information
kutsovmqs authored and katbyte committed Oct 25, 2019
1 parent ea50430 commit a975734
Show file tree
Hide file tree
Showing 18 changed files with 2,728 additions and 0 deletions.
3 changes: 3 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/graph"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hdinsight"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/healthcare"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto"
Expand Down Expand Up @@ -111,6 +112,7 @@ type ArmClient struct {
Frontdoor *frontdoor.Client
Graph *graph.Client
HDInsight *hdinsight.Client
Healthcare *healthcare.Client
IoTHub *iothub.Client
KeyVault *keyvault.Client
Kusto *kusto.Client
Expand Down Expand Up @@ -245,6 +247,7 @@ func getArmClient(authConfig *authentication.Config, skipProviderRegistration bo
client.Frontdoor = frontdoor.BuildClient(o)
client.Graph = graph.BuildClient(o)
client.HDInsight = hdinsight.BuildClient(o)
client.Healthcare = healthcare.BuildClient(o)
client.IoTHub = iothub.BuildClient(o)
client.KeyVault = keyvault.BuildClient(o)
client.Kusto = kusto.BuildClient(o)
Expand Down
157 changes: 157 additions & 0 deletions azurerm/data_source_healthcare_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package azurerm

import (
"fmt"
"log"

"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/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmHealthcareService() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmHealthcareServiceRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
},

"location": azure.SchemaLocation(),

"resource_group_name": azure.SchemaResourceGroupName(),

"kind": {
Type: schema.TypeString,
Computed: true,
},

"cosmosdb_throughput": {
Type: schema.TypeInt,
Computed: true,
},

"access_policy_object_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"authentication_configuration": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"authority": {
Type: schema.TypeString,
Computed: true,
},
"audience": {
Type: schema.TypeString,
Computed: true,
},
"smart_proxy_enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},

"cors_configuration": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allowed_origins": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"allowed_headers": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"allowed_methods": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"max_age_in_seconds": {
Type: schema.TypeInt,
Computed: true,
},
"allow_credentials": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},

"tags": tagsSchema(),
},
}
}

func dataSourceArmHealthcareServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Healthcare.HealthcareServiceClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[WARN] Healthcare Service %q was not found (Resource Group %q)", name, resourceGroup)
d.SetId("")
return fmt.Errorf("HealthCare Service %q was not found in Resource Group %q", name, resourceGroup)
}
return fmt.Errorf("Error making Read request on Azure Healthcare Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)
if kind := resp.Kind; string(kind) != "" {
d.Set("kind", kind)
}

if properties := resp.Properties; properties != nil {
if accessPolicies := properties.AccessPolicies; accessPolicies != nil {
d.Set("access_policy_object_ids", flattenHealthcareAccessPolicies(accessPolicies))
}

if config := properties.CosmosDbConfiguration; config != nil {
d.Set("cosmosdb_throughput", config.OfferThroughput)
}

if authConfig := properties.AuthenticationConfiguration; authConfig != nil {
if err := d.Set("authentication_configuration", flattenHealthcareAuthConfig(authConfig)); err != nil {
return fmt.Errorf("Error setting `authentication_configuration`: %+v", flattenHealthcareAuthConfig(authConfig))
}
}

if corsConfig := properties.CorsConfiguration; corsConfig != nil {
if err := d.Set("cors_configuration", flattenHealthcareCorsConfig(corsConfig)); err != nil {
return fmt.Errorf("Error setting `cors_configuration`: %+v", flattenHealthcareCorsConfig(corsConfig))
}
}
}

return tags.FlattenAndSet(d, resp.Tags)
}
46 changes: 46 additions & 0 deletions azurerm/data_source_healthcare_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
)

func TestAccAzureRMDataSourceHealthcareService_basic(t *testing.T) {
dataSourceName := "data.azurerm_healthcare_service.test"
ri := tf.AccRandTimeInt() / 10
location := testLocation()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMHealthcareServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMDataSourceHealthcareService_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "name"),
resource.TestCheckResourceAttrSet(dataSourceName, "location"),
resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"),
resource.TestCheckResourceAttrSet(dataSourceName, "kind"),
resource.TestCheckResourceAttrSet(dataSourceName, "cosmosdb_throughput"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"),
),
},
},
})
}

func testAccAzureRMDataSourceHealthcareService_basic(rInt int, location string) string {
resource := testAccAzureRMHealthcareService_basic(rInt)
return fmt.Sprintf(`
%s
data "azurerm_healthcare_service" "test" {
name = "${azurerm_healthcare_service.test.name}"
resource_group_name = "${azurerm_healthcare_service.test.resource_group_name}"
location = "${azurerm_resource_group.test.location}"
}
`, resource)
}
19 changes: 19 additions & 0 deletions azurerm/internal/services/healthcare/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package healthcare

import (
healthcare "github.com/Azure/azure-sdk-for-go/services/healthcareapis/mgmt/2019-09-16/healthcareapis"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
HealthcareServiceClient *healthcare.ServicesClient
}

func BuildClient(o *common.ClientOptions) *Client {
HealthcareServiceClient := healthcare.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&HealthcareServiceClient.Client, o.ResourceManagerAuthorizer)

return &Client{
HealthcareServiceClient: &HealthcareServiceClient,
}
}
2 changes: 2 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_firewall": dataSourceArmFirewall(),
"azurerm_image": dataSourceArmImage(),
"azurerm_hdinsight_cluster": dataSourceArmHDInsightSparkCluster(),
"azurerm_healthcare_service": dataSourceArmHealthcareService(),
"azurerm_maps_account": dataSourceArmMapsAccount(),
"azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(),
"azurerm_key_vault_key": dataSourceArmKeyVaultKey(),
Expand Down Expand Up @@ -289,6 +290,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_hdinsight_rserver_cluster": resourceArmHDInsightRServerCluster(),
"azurerm_hdinsight_spark_cluster": resourceArmHDInsightSparkCluster(),
"azurerm_hdinsight_storm_cluster": resourceArmHDInsightStormCluster(),
"azurerm_healthcare_service": resourceArmHealthcareService(),
"azurerm_image": resourceArmImage(),
"azurerm_iot_dps": resourceArmIotDPS(),
"azurerm_iot_dps_certificate": resourceArmIotDPSCertificate(),
Expand Down
1 change: 1 addition & 0 deletions azurerm/required_resource_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func requiredResourceProviders() map[string]struct{} {
"Microsoft.EventGrid": {},
"Microsoft.EventHub": {},
"Microsoft.HDInsight": {},
"Microsoft.Healthcare": {},
"Microsoft.KeyVault": {},
"Microsoft.Kusto": {},
"microsoft.insights": {},
Expand Down
Loading

0 comments on commit a975734

Please sign in to comment.