-
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.
New Resource & DataSource: azurerm_healthcare_service (#4221)
Fixes #3989
- Loading branch information
Showing
18 changed files
with
2,728 additions
and
0 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
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,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) | ||
} |
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,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) | ||
} |
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,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, | ||
} | ||
} |
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
Oops, something went wrong.