Skip to content

Commit

Permalink
Add oci_certificates_certificate_bundle and oci_certificates_certific…
Browse files Browse the repository at this point in the history
…ate_authority_bundle data sources
  • Loading branch information
F21 committed Nov 6, 2024
1 parent 77156f7 commit b31a6a9
Show file tree
Hide file tree
Showing 28 changed files with 3,144 additions and 1 deletion.
33 changes: 33 additions & 0 deletions internal/client/certificates_clients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
// Licensed under the Mozilla Public License v2.0

package client

import (
oci_certificates "github.com/oracle/oci-go-sdk/v65/certificates"
oci_common "github.com/oracle/oci-go-sdk/v65/common"
)

func init() {
RegisterOracleClient("oci_certificates.CertificatesClient", &OracleClient{InitClientFn: initCertificatesCertificatesClient})
}

func initCertificatesCertificatesClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
client, err := oci_certificates.NewCertificatesClientWithConfigurationProvider(configProvider)
if err != nil {
return nil, err
}
err = configureClient(&client.BaseClient)
if err != nil {
return nil, err
}

if serviceClientOverrides.HostUrlOverride != "" {
client.Host = serviceClientOverrides.HostUrlOverride
}
return &client, nil
}

func (m *OracleClients) CertificatesClient() *oci_certificates.CertificatesClient {
return m.GetClient("oci_certificates.CertificatesClient").(*oci_certificates.CertificatesClient)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
// Licensed under the Mozilla Public License v2.0

package integrationtest

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/oracle/terraform-provider-oci/httpreplay"
"github.com/oracle/terraform-provider-oci/internal/acctest"

"github.com/oracle/terraform-provider-oci/internal/utils"
)

var (
CertificatesCertificateAuthorityBundleSingularDataSourceRepresentation = map[string]interface{}{
"certificate_authority_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_certificates_management_certificate_authority.test_certificate_authority.id}`},
"stage": acctest.Representation{RepType: acctest.Optional, Create: `CURRENT`},
}

CertificatesCertificateAuthorityBundleResourceConfig = acctest.GenerateResourceFromRepresentationMap("oci_certificates_management_certificate_authority", "test_certificate_authority", acctest.Required, acctest.Create, certificateAuthorityRepresentation)
)

// issue-routing-tag: certificates/default
func TestCertificatesCertificateAuthorityBundleResource_basic(t *testing.T) {
httpreplay.SetScenario("TestCertificatesCertificateAuthorityBundleResource_basic")
defer httpreplay.SaveScenario()

config := acctest.ProviderTestConfig()

compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)

singularDatasourceName := "data.oci_certificates_certificate_authority_bundle.test_certificate_authority_bundle"

acctest.SaveConfigContent("", "", "", t)
acctest.ResourceTest(t, nil, []resource.TestStep{
// verify singular datasource
{
Config: config +
acctest.GenerateDataSourceFromRepresentationMap("oci_certificates_certificate_authority_bundle", "test_certificate_authority_bundle", acctest.Optional, acctest.Create, CertificatesCertificateAuthorityBundleSingularDataSourceRepresentation) +
compartmentIdVariableStr + CertificatesCertificateAuthorityBundleResourceConfig,
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
resource.TestCheckResourceAttrSet(singularDatasourceName, "cert_chain_pem"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "certificate_authority_id"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "certificate_authority_name"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "certificate_pem"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "serial_number"),
resource.TestCheckResourceAttr(singularDatasourceName, "stages.#", "2"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
resource.TestCheckResourceAttr(singularDatasourceName, "validity.#", "1"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "validity.0.time_of_validity_not_before"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "validity.0.time_of_validity_not_after"),
resource.TestCheckResourceAttr(singularDatasourceName, "version_number", "1"),
),
},
})
}
64 changes: 64 additions & 0 deletions internal/integrationtest/certificates_certificate_bundle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
// Licensed under the Mozilla Public License v2.0

package integrationtest

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/oracle/terraform-provider-oci/httpreplay"
"github.com/oracle/terraform-provider-oci/internal/acctest"

"github.com/oracle/terraform-provider-oci/internal/utils"
)

var (
CertificatesCertificateBundleSingularDataSourceRepresentation = map[string]interface{}{
"certificate_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_certificates_management_certificate.test_certificate.id}`},
"certificate_bundle_type": acctest.Representation{RepType: acctest.Optional, Create: `CERTIFICATE_CONTENT_WITH_PRIVATE_KEY`},
"stage": acctest.Representation{RepType: acctest.Optional, Create: `CURRENT`},
}

CertificatesCertificateBundleResourceConfig = acctest.GenerateResourceFromRepresentationMap("oci_certificates_management_certificate", "test_certificate", acctest.Required, acctest.Create, certificatesManagementCertificateRepresentation)
)

// issue-routing-tag: certificates/default
func TestCertificatesCertificateBundleResource_basic(t *testing.T) {
httpreplay.SetScenario("TestCertificatesCertificateBundleResource_basic")
defer httpreplay.SaveScenario()

config := acctest.ProviderTestConfig()

compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)

singularDatasourceName := "data.oci_certificates_certificate_bundle.test_certificate_bundle"

acctest.SaveConfigContent("", "", "", t)
acctest.ResourceTest(t, nil, []resource.TestStep{
// verify singular datasource
{
Config: config +
acctest.GenerateDataSourceFromRepresentationMap("oci_certificates_certificate_bundle", "test_certificate_bundle", acctest.Optional, acctest.Create, CertificatesCertificateBundleSingularDataSourceRepresentation) +
compartmentIdVariableStr + CertificatesCertificateBundleResourceConfig,
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
resource.TestCheckResourceAttrSet(singularDatasourceName, "cert_chain_pem"),
resource.TestCheckResourceAttr(singularDatasourceName, "certificate_bundle_type", "CERTIFICATE_CONTENT_WITH_PRIVATE_KEY"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "certificate_id"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "certificate_name"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "certificate_pem"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "private_key_pem"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "serial_number"),
resource.TestCheckResourceAttr(singularDatasourceName, "stages.#", "2"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
resource.TestCheckResourceAttr(singularDatasourceName, "validity.#", "1"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "validity.0.time_of_validity_not_before"),
resource.TestCheckResourceAttrSet(singularDatasourceName, "validity.0.time_of_validity_not_after"),
resource.TestCheckResourceAttr(singularDatasourceName, "version_number", "1"),
),
},
})
}
5 changes: 4 additions & 1 deletion internal/provider/register_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
tf_blockchain "github.com/oracle/terraform-provider-oci/internal/service/blockchain"
tf_budget "github.com/oracle/terraform-provider-oci/internal/service/budget"
tf_capacity_management "github.com/oracle/terraform-provider-oci/internal/service/capacity_management"
tf_certificates "github.com/oracle/terraform-provider-oci/internal/service/certificates"
tf_certificates_management "github.com/oracle/terraform-provider-oci/internal/service/certificates_management"
tf_cloud_bridge "github.com/oracle/terraform-provider-oci/internal/service/cloud_bridge"
tf_cloud_guard "github.com/oracle/terraform-provider-oci/internal/service/cloud_guard"
Expand Down Expand Up @@ -194,6 +195,9 @@ func init() {
if common.CheckForEnabledServices("capacitymanagement") {
tf_capacity_management.RegisterDatasource()
}
if common.CheckForEnabledServices("certificates") {
tf_certificates.RegisterDatasource()
}
if common.CheckForEnabledServices("certificatesmanagement") {
tf_certificates_management.RegisterDatasource()
}
Expand Down Expand Up @@ -500,5 +504,4 @@ func init() {
if common.CheckForEnabledServices("zpr") {
tf_zpr.RegisterDatasource()
}

}
Loading

0 comments on commit b31a6a9

Please sign in to comment.