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 Aug 29, 2023
1 parent 154610f commit 89e3f05
Show file tree
Hide file tree
Showing 68 changed files with 3,801 additions and 258 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
Expand All @@ -35,10 +35,10 @@ require (
github.com/hashicorp/go-plugin v1.4.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.1 // indirect
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-json v0.12.0 // indirect
github.com/hashicorp/terraform-json v0.15.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.3.0 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -58,7 +58,7 @@ require (
github.com/sony/gobreaker v0.5.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/zclconf/go-cty v1.8.4 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
go.opencensus.io v0.22.4 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0 h1:pMen7vLs8nvgEYhywH3KDWJIJTeEr2ULsVWHWYHQyBs=
Expand Down Expand Up @@ -195,6 +197,8 @@ github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8=
Expand All @@ -208,6 +212,8 @@ github.com/hashicorp/terraform-exec v0.14.0 h1:UQoUcxKTZZXhyyK68Cwn4mApT4mnFPmEX
github.com/hashicorp/terraform-exec v0.14.0/go.mod h1:qrAASDq28KZiMPDnQ02sFS9udcqEkRly002EA2izXTA=
github.com/hashicorp/terraform-json v0.12.0 h1:8czPgEEWWPROStjkWPUnTQDXmpmZPlkQAwYYLETaTvw=
github.com/hashicorp/terraform-json v0.12.0/go.mod h1:pmbq9o4EuL43db5+0ogX10Yofv1nozM+wskr/bGFJpI=
github.com/hashicorp/terraform-json v0.15.0 h1:/gIyNtR6SFw6h5yzlbDbACyGvIhKtQi8mTsbkNd79lE=
github.com/hashicorp/terraform-json v0.15.0/go.mod h1:+L1RNzjDU5leLFZkHTFTbJXaoqUC6TqXlFgDoOXrtvk=
github.com/hashicorp/terraform-plugin-go v0.3.0 h1:AJqYzP52JFYl9NABRI7smXI1pNjgR5Q/y2WyVJ/BOZA=
github.com/hashicorp/terraform-plugin-go v0.3.0/go.mod h1:dFHsQMaTLpON2gWhVWT96fvtlc/MF1vSy3OdMhWBzdM=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0 h1:SuI59MqNjYDrL7EfqHX9V6P/24isgqYx/FdglwVs9bg=
Expand Down Expand Up @@ -340,6 +346,8 @@ github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q
github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty v1.8.4 h1:pwhhz5P+Fjxse7S7UriBrMu6AUJSZM5pKqGem1PjGAs=
github.com/zclconf/go-cty v1.8.4/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0=
github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
Expand Down
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"),
),
},
})
}
2 changes: 2 additions & 0 deletions internal/provider/register_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
tf_bds "github.com/oracle/terraform-provider-oci/internal/service/bds"
tf_blockchain "github.com/oracle/terraform-provider-oci/internal/service/blockchain"
tf_budget "github.com/oracle/terraform-provider-oci/internal/service/budget"
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 @@ -134,6 +135,7 @@ func init() {
tf_bds.RegisterDatasource()
tf_blockchain.RegisterDatasource()
tf_budget.RegisterDatasource()
tf_certificates.RegisterDatasource()
tf_certificates_management.RegisterDatasource()
tf_cloud_bridge.RegisterDatasource()
tf_cloud_guard.RegisterDatasource()
Expand Down
Loading

0 comments on commit 89e3f05

Please sign in to comment.