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 all 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
196 changes: 196 additions & 0 deletions azurerm/data_source_app_service_certificate_order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package azurerm

import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"
"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/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.SchemaResourceGroupNameForDataSource(),

"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,
},

"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_thumbprint": {
Type: schema.TypeString,
Computed: true,
},

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

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

"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("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 expirationTime := props.ExpirationTime; expirationTime != nil {
d.Set("expiration_time", expirationTime.Format(time.RFC3339))
}

if signedCertificate := props.SignedCertificate; signedCertificate != nil {
d.Set("signed_certificate_thumbprint", signedCertificate.Thumbprint)
}

if root := props.Root; root != nil {
d.Set("root_thumbprint", root.Thumbprint)
}

if intermediate := props.Intermediate; intermediate != nil {
d.Set("intermediate_thumbprint", intermediate.Thumbprint)
}
}

return tags.FlattenAndSet(d, resp.Tags)
}
130 changes: 130 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,130 @@
package azurerm

import (
"fmt"
"os"
"testing"

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

func TestAccDataSourceAzureRMAppServiceCertificateOrder_basic(t *testing.T) {
if os.Getenv("ARM_RUN_TEST_APP_SERVICE_CERTIFICATE") == "" {
t.Skip("Skipping as ARM_RUN_TEST_APP_SERVICE_CERTIFICATE is not specified")
return
}

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) {
if os.Getenv("ARM_RUN_TEST_APP_SERVICE_CERTIFICATE") == "" {
t.Skip("Skipping as ARM_RUN_TEST_APP_SERVICE_CERTIFICATE is not specified")
return
}

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) {
if os.Getenv("ARM_RUN_TEST_APP_SERVICE_CERTIFICATE") == "" {
t.Skip("Skipping as ARM_RUN_TEST_APP_SERVICE_CERTIFICATE is not specified")
return
}

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 @@ -60,6 +60,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_app_service_plan": dataSourceAppServicePlan(),
"azurerm_app_service_certificate": dataSourceAppServiceCertificate(),
"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 @@ -173,6 +174,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