Skip to content
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/Data Source: azurerm_App_Service_Certificate_Order #4454

Merged
merged 16 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 221 additions & 0 deletions azurerm/data_source_app_service_certificate_order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
package azurerm

import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmAppServiceCertificateOrder() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmAppServiceCertificateOrderRead,

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

"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(),
hund030 marked this conversation as resolved.
Show resolved Hide resolved

"location": azure.SchemaLocationForDataSource(),

"auto_renew": {
Type: schema.TypeBool,
Computed: true,
},

"certificates": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"certificate_name": {
Type: schema.TypeString,
Computed: true,
},

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

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

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

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

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

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

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

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

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

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

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

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

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

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

"is_private_key_external": {
Type: schema.TypeBool,
Computed: true,
},

"app_service_certificate_not_renewable_reasons": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"signed_certificate": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: appServiceCertificateDetailsSchema(),
},
},

"root": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: appServiceCertificateDetailsSchema(),
},
},

"intermediate": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: appServiceCertificateDetailsSchema(),
},
},

"tags": tags.SchemaDataSource(),
},
}
}

func dataSourceArmAppServiceCertificateOrderRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).web.CertificatesOrderClient

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

ctx := meta.(*ArmClient).StopContext
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: App Service Certificate Order %q (Resource Group %q) was not found", name, resourceGroup)
}

return fmt.Errorf("Error making Read request on AzureRM App Service Certificate Order %q: %+v", name, err)
}

d.SetId(*resp.ID)

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)

if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}

if props := resp.AppServiceCertificateOrderProperties; props != nil {
d.Set("auto_renew", props.AutoRenew)
d.Set("csr", props.Csr)
d.Set("distinguished_name", props.DistinguishedName)
d.Set("key_size", props.KeySize)
d.Set("validity_in_years", props.ValidityInYears)
d.Set("domain_verification_token", props.DomainVerificationToken)
d.Set("status", string(props.Status))
d.Set("serial_number", props.SerialNumber)
d.Set("is_private_key_external", props.IsPrivateKeyExternal)
d.Set("certificates", flattenArmCertificateOrderCertificate(props.Certificates))
d.Set("app_service_certificate_not_renewable_reasons", utils.FlattenStringSlice(props.AppServiceCertificateNotRenewableReasons))

if productType := props.ProductType; productType == web.StandardDomainValidatedSsl {
d.Set("product_type", "standard")
} else if productType == web.StandardDomainValidatedWildCardSsl {
d.Set("product_type", "wildcard")
}

if lastCertificateIssuanceTime := props.LastCertificateIssuanceTime; lastCertificateIssuanceTime != nil {
d.Set("last_certificate_issuance_time", lastCertificateIssuanceTime.Format(time.RFC3339))
}

if nextAutoRenewalTimeStamp := props.NextAutoRenewalTimeStamp; nextAutoRenewalTimeStamp != nil {
d.Set("next_auto_renewal_time_stamp", nextAutoRenewalTimeStamp.Format(time.RFC3339))
}

if expirationTime := props.ExpirationTime; expirationTime != nil {
d.Set("expiration_time", expirationTime.Format(time.RFC3339))
}

d.Set("signed_certificate", flattenArmCertificateOrderCertificateDetails(props.SignedCertificate))
d.Set("root", flattenArmCertificateOrderCertificateDetails(props.Root))
d.Set("intermediate", flattenArmCertificateOrderCertificateDetails(props.Intermediate))
}

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

import (
"fmt"
"testing"

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

func TestAccDataSourceAzureRMAppServiceCertificateOrder_basic(t *testing.T) {
dataSourceName := "data.azurerm_app_service_certificate_order.test"
rInt := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAppServiceCertificateOrder_basic(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "csr"),
resource.TestCheckResourceAttrSet(dataSourceName, "domain_verification_token"),
resource.TestCheckResourceAttr(dataSourceName, "distinguished_name", "CN=example.com"),
resource.TestCheckResourceAttr(dataSourceName, "product_type", "standard"),
),
},
},
})
}

func TestAccDataSourceAzureRMAppServiceCertificateOrder_wildcard(t *testing.T) {
dataSourceName := "data.azurerm_app_service_certificate_order.test"
rInt := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAppServiceCertificateOrder_wildcard(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "csr"),
resource.TestCheckResourceAttrSet(dataSourceName, "domain_verification_token"),
resource.TestCheckResourceAttr(dataSourceName, "distinguished_name", "CN=*.example.com"),
resource.TestCheckResourceAttr(dataSourceName, "product_type", "wildcard"),
),
},
},
})
}

func TestAccDataSourceAzureRMAppServiceCertificateOrder_complete(t *testing.T) {
dataSourceName := "data.azurerm_app_service_certificate_order.test"
rInt := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAppServiceCertificateOrder_complete(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "csr"),
resource.TestCheckResourceAttrSet(dataSourceName, "domain_verification_token"),
resource.TestCheckResourceAttr(dataSourceName, "distinguished_name", "CN=example.com"),
resource.TestCheckResourceAttr(dataSourceName, "product_type", "standard"),
resource.TestCheckResourceAttr(dataSourceName, "validity_in_years", "1"),
resource.TestCheckResourceAttr(dataSourceName, "auto_renew", "false"),
resource.TestCheckResourceAttr(dataSourceName, "key_size", "4096"),
),
},
},
})
}

func testAccDataSourceAppServiceCertificateOrder_basic(rInt int, location string) string {
config := testAccAzureRMAppServiceCertificateOrder_basic(rInt, location)
return fmt.Sprintf(`
%s

data "azurerm_app_service_certificate_order" "test" {
name = "${azurerm_app_service_certificate_order.test.name}"
resource_group_name = "${azurerm_app_service_certificate_order.test.resource_group_name}"
}
`, config)
}

func testAccDataSourceAppServiceCertificateOrder_wildcard(rInt int, location string) string {
config := testAccAzureRMAppServiceCertificateOrder_wildcard(rInt, location)
return fmt.Sprintf(`
%s

data "azurerm_app_service_certificate_order" "test" {
name = "${azurerm_app_service_certificate_order.test.name}"
resource_group_name = "${azurerm_app_service_certificate_order.test.resource_group_name}"
}
`, config)
}

func testAccDataSourceAppServiceCertificateOrder_complete(rInt int, location string) string {
config := testAccAzureRMAppServiceCertificateOrder_complete(rInt, location, 4096)
return fmt.Sprintf(`
%s

data "azurerm_app_service_certificate_order" "test" {
name = "${azurerm_app_service_certificate_order.test.name}"
resource_group_name = "${azurerm_app_service_certificate_order.test.resource_group_name}"
}
`, config)
}
21 changes: 13 additions & 8 deletions azurerm/internal/services/web/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
)

type Client struct {
AppServicePlansClient *web.AppServicePlansClient
AppServicesClient *web.AppsClient
CertificatesClient *web.CertificatesClient
BaseClient *web.BaseClient
AppServicePlansClient *web.AppServicePlansClient
AppServicesClient *web.AppsClient
CertificatesClient *web.CertificatesClient
CertificatesOrderClient *web.AppServiceCertificateOrdersClient
BaseClient *web.BaseClient
}

func BuildClient(o *common.ClientOptions) *Client {
Expand All @@ -22,13 +23,17 @@ func BuildClient(o *common.ClientOptions) *Client {
CertificatesClient := web.NewCertificatesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&CertificatesClient.Client, o.ResourceManagerAuthorizer)

CertificatesOrderClient := web.NewAppServiceCertificateOrdersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&CertificatesOrderClient.Client, o.ResourceManagerAuthorizer)

BaseClient := web.NewWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&BaseClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AppServicePlansClient: &AppServicePlansClient,
AppServicesClient: &AppServicesClient,
CertificatesClient: &CertificatesClient,
BaseClient: &BaseClient,
AppServicePlansClient: &AppServicePlansClient,
AppServicesClient: &AppServicesClient,
CertificatesClient: &CertificatesClient,
CertificatesOrderClient: &CertificatesOrderClient,
BaseClient: &BaseClient,
}
}
2 changes: 2 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_api_management_user": dataSourceArmApiManagementUser(),
"azurerm_app_service_plan": dataSourceAppServicePlan(),
"azurerm_app_service": dataSourceArmAppService(),
"azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(),
"azurerm_application_insights": dataSourceArmApplicationInsights(),
"azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(),
"azurerm_automation_variable_bool": dataSourceArmAutomationVariableBool(),
Expand Down Expand Up @@ -167,6 +168,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_api_management_user": resourceArmApiManagementUser(),
"azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(),
"azurerm_app_service_certificate": resourceArmAppServiceCertificate(),
"azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(),
"azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(),
"azurerm_app_service_plan": resourceArmAppServicePlan(),
"azurerm_app_service_slot": resourceArmAppServiceSlot(),
Expand Down
Loading