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

Add oci_certificates_certificate_bundle and oci_certificates_certificate_authority_bundle data sources #1951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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