Skip to content

Commit

Permalink
New Service: Containerapps (#18008)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored Feb 7, 2023
1 parent e3ae00c commit 6bf1f87
Show file tree
Hide file tree
Showing 183 changed files with 14,752 additions and 0 deletions.
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var services = mapOf(
"confidentialledger" to "Confidential Ledger",
"connections" to "Connections",
"consumption" to "Consumption",
"containerapps" to "Container Apps",
"containers" to "Container Services",
"cosmos" to "CosmosDB",
"costmanagement" to "Cost Management",
Expand Down
3 changes: 3 additions & 0 deletions .teamcity/components/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ var serviceTestConfigurationOverrides = mapOf(
//Confidential Ledger
"confidentialledger" to testConfiguration(locationOverride = LocationConfiguration("eastus","southcentralus","westeurope", false)),

// Container App Managed Environments are limited to 5 per location, using 3 as they can take some time to clear
"containerapps" to testConfiguration(parallelism = 3, locationOverride = LocationConfiguration("westeurope","eastus","canadacentral", false)),

// The AKS API has a low rate limit
"containers" to testConfiguration(parallelism = 5, locationOverride = LocationConfiguration("eastus","westeurope","eastus2", false), useDevTestSubscription = true),

Expand Down
3 changes: 3 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
confidentialledger "github.com/hashicorp/terraform-provider-azurerm/internal/services/confidentialledger/client"
connections "github.com/hashicorp/terraform-provider-azurerm/internal/services/connections/client"
consumption "github.com/hashicorp/terraform-provider-azurerm/internal/services/consumption/client"
containerapps "github.com/hashicorp/terraform-provider-azurerm/internal/services/containerapps/client"
containerServices "github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/client"
cosmosdb "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/client"
costmanagement "github.com/hashicorp/terraform-provider-azurerm/internal/services/costmanagement/client"
Expand Down Expand Up @@ -156,6 +157,7 @@ type Client struct {
ConfidentialLedger *confidentialledger.Client
Connections *connections.Client
Consumption *consumption.Client
ContainerApps *containerapps.Client
Containers *containerServices.Client
Cosmos *cosmosdb.Client
CostManagement *costmanagement.Client
Expand Down Expand Up @@ -279,6 +281,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Connections = connections.NewClient(o)
client.Consumption = consumption.NewClient(o)
client.Containers = containerServices.NewContainersClient(o)
client.ContainerApps = containerapps.NewClient(o)
client.Cosmos = cosmosdb.NewClient(o)
client.CostManagement = costmanagement.NewClient(o)
client.CustomProviders = customproviders.NewClient(o)
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/confidentialledger"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/connections"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/consumption"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containerapps"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containers"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/costmanagement"
Expand Down Expand Up @@ -130,6 +131,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
compute.Registration{},
consumption.Registration{},
cosmos.Registration{},
containerapps.Registration{},
costmanagement.Registration{},
dashboard.Registration{},
databoxedge.Registration{},
Expand Down
49 changes: 49 additions & 0 deletions internal/services/containerapps/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package client

import (
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2022-03-01/certificates"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2022-03-01/containerapps"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2022-03-01/containerappsrevisions"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2022-03-01/daprcomponents"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2022-03-01/managedenvironments"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2022-03-01/managedenvironmentsstorages"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
CertificatesClient *certificates.CertificatesClient
ContainerAppClient *containerapps.ContainerAppsClient
ContainerAppRevisionClient *containerappsrevisions.ContainerAppsRevisionsClient
DaprComponentsClient *daprcomponents.DaprComponentsClient
ManagedEnvironmentClient *managedenvironments.ManagedEnvironmentsClient
StorageClient *managedenvironmentsstorages.ManagedEnvironmentsStoragesClient
}

func NewClient(o *common.ClientOptions) *Client {
certificatesClient := certificates.NewCertificatesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&certificatesClient.Client, o.ResourceManagerAuthorizer)

containerAppsClient := containerapps.NewContainerAppsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&containerAppsClient.Client, o.ResourceManagerAuthorizer)

containerAppsRevisionsClient := containerappsrevisions.NewContainerAppsRevisionsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&containerAppsRevisionsClient.Client, o.ResourceManagerAuthorizer)

managedEnvironmentClient := managedenvironments.NewManagedEnvironmentsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&managedEnvironmentClient.Client, o.ResourceManagerAuthorizer)

managedEnvironmentStoragesClient := managedenvironmentsstorages.NewManagedEnvironmentsStoragesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&managedEnvironmentStoragesClient.Client, o.ResourceManagerAuthorizer)

daprComponentClient := daprcomponents.NewDaprComponentsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&daprComponentClient.Client, o.ResourceManagerAuthorizer)

return &Client{
CertificatesClient: &certificatesClient,
ContainerAppClient: &containerAppsClient,
ContainerAppRevisionClient: &containerAppsRevisionsClient,
DaprComponentsClient: &daprComponentClient,
ManagedEnvironmentClient: &managedEnvironmentClient,
StorageClient: &managedEnvironmentStoragesClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package containerapps

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2022-03-01/certificates"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containerapps/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type ContainerAppEnvironmentCertificateDataSource struct{}

type ContainerAppEnvironmentCertificateDataSourceModel struct {
Name string `tfschema:"name"`
ManagedEnvironmentId string `tfschema:"container_app_environment_id"`

// Read Only
SubjectName string `tfschema:"subject_name"`
Issuer string `tfschema:"issuer"`
IssueDate string `tfschema:"issue_date"`
ExpirationDate string `tfschema:"expiration_date"`
Thumbprint string `tfschema:"thumbprint"`
Tags map[string]interface{} `tfschema:"tags"`
}

var _ sdk.DataSource = ContainerAppEnvironmentCertificateDataSource{}

func (r ContainerAppEnvironmentCertificateDataSource) ModelObject() interface{} {
return &ContainerAppEnvironmentCertificateDataSourceModel{}
}

func (r ContainerAppEnvironmentCertificateDataSource) ResourceType() string {
return "azurerm_container_app_environment_certificate"
}

func (r ContainerAppEnvironmentCertificateDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.CertificateName,
Description: "The name of the Container Apps Certificate.",
},

"container_app_environment_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: certificates.ValidateManagedEnvironmentID,
Description: "The Container App Managed Environment ID to configure this Certificate on.",
},
}
}

func (r ContainerAppEnvironmentCertificateDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"subject_name": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The Subject Name for the Certificate.",
},

"issuer": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The Certificate Issuer.",
},

"issue_date": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The date of issue for the Certificate.",
},

"expiration_date": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The expiration date for the Certificate.",
},

"thumbprint": {
Type: pluginsdk.TypeString,
Computed: true,
Description: "The Thumbprint of the Certificate.",
},

"tags": commonschema.TagsDataSource(),
}
}

func (r ContainerAppEnvironmentCertificateDataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.ContainerApps.CertificatesClient

var cert ContainerAppEnvironmentCertificateDataSourceModel
if err := metadata.Decode(&cert); err != nil {
return err
}

envId, err := certificates.ParseManagedEnvironmentID(cert.ManagedEnvironmentId)
if err != nil {
return err
}

id := certificates.NewCertificateID(envId.SubscriptionId, envId.ResourceGroupName, envId.ManagedEnvironmentName, cert.Name)

existing, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("reading %s: %+v", id, err)
}

cert.Name = id.CertificateName
cert.ManagedEnvironmentId = envId.ID()

if model := existing.Model; model != nil {
cert.Tags = tags.Flatten(model.Tags)

if props := model.Properties; props != nil {
cert.Issuer = pointer.From(props.Issuer)
cert.IssueDate = pointer.From(props.IssueDate)
cert.ExpirationDate = pointer.From(props.ExpirationDate)
cert.Thumbprint = pointer.From(props.Thumbprint)
cert.SubjectName = pointer.From(props.SubjectName)
}
}

metadata.SetID(id)

return metadata.Encode(&cert)
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package containerapps_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type ContainerAppEnvironmentCertificateDataSource struct{}

func TestAccContainerAppEnvironmentCertificateDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_container_app_environment_certificate", "test")
r := ContainerAppEnvironmentCertificateDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("subject_name").IsSet(),
check.That(data.ResourceName).Key("thumbprint").IsSet(),
check.That(data.ResourceName).Key("issue_date").IsSet(),
check.That(data.ResourceName).Key("expiration_date").IsSet(),
check.That(data.ResourceName).Key("issuer").IsSet(),
),
},
})
}

func (d ContainerAppEnvironmentCertificateDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
data "azurerm_container_app_environment_certificate" "test" {
name = azurerm_container_app_environment_certificate.test.name
container_app_environment_id = azurerm_container_app_environment_certificate.test.container_app_environment_id
}
`, ContainerAppEnvironmentCertificateResource{}.basic(data))
}
Loading

0 comments on commit 6bf1f87

Please sign in to comment.