Skip to content

Commit a82a279

Browse files
committed
support for autonomous wallet generation as a resource
1 parent 79ef3f7 commit a82a279

9 files changed

+278
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
- Support for ADBS Apex added
88
- Support for Platform Integration: KMS Integration-Exadata (Phase 1)
99

10+
### Deprecated
11+
- Data source `oci_database_autonomous_database_wallet` is being deprecated in favor of resource `oci_database_autonomous_database_wallet`
12+
1013
## 4.6.0 (December 09, 2020)
1114

1215
### Added

examples/database/adb/autonomous_data_warehouse_wallet.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ resource "random_string" "autonomous_data_warehouse_wallet_password" {
66
special = true
77
}
88

9-
data "oci_database_autonomous_database_wallet" "autonomous_data_warehouse_wallet" {
9+
resource "oci_database_autonomous_database_wallet" "autonomous_data_warehouse_wallet" {
1010
autonomous_database_id = oci_database_autonomous_database.autonomous_data_warehouse.id
1111
password = random_string.autonomous_data_warehouse_wallet_password.result
1212
base64_encode_content = "true"
1313
}
1414

1515
resource "local_file" "autonomous_data_warehouse_wallet_file" {
16-
content_base64 = data.oci_database_autonomous_database_wallet.autonomous_data_warehouse_wallet.content
16+
content_base64 = oci_database_autonomous_database_wallet.autonomous_data_warehouse_wallet.content
1717
filename = "${path.module}/autonomous_data_warehouse_wallet.zip"
1818
}
1919

examples/database/adb/autonomous_database_wallet.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ resource "random_string" "autonomous_database_wallet_password" {
66
special = true
77
}
88

9-
data "oci_database_autonomous_database_wallet" "autonomous_database_wallet" {
9+
resource "oci_database_autonomous_database_wallet" "autonomous_database_wallet" {
1010
autonomous_database_id = oci_database_autonomous_database.autonomous_database.id
1111
password = random_string.autonomous_database_wallet_password.result
1212
base64_encode_content = "true"
1313
}
1414

1515
resource "local_file" "autonomous_database_wallet_file" {
16-
content_base64 = data.oci_database_autonomous_database_wallet.autonomous_database_wallet.content
16+
content_base64 = oci_database_autonomous_database_wallet.autonomous_database_wallet.content
1717
filename = "${path.module}/autonomous_database_wallet.zip"
1818
}
1919

oci/database_autonomous_database_wallet_data_source.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ func DatabaseAutonomousDatabaseWalletDataSource() *schema.Resource {
2222
Read: readSingularDatabaseAutonomousDatabaseWallet,
2323
Schema: map[string]*schema.Schema{
2424
"autonomous_database_id": {
25-
Type: schema.TypeString,
26-
Required: true,
25+
Type: schema.TypeString,
26+
Required: true,
27+
Deprecated: ResourceDeprecatedForAnother("data.oci_database_autonomous_database_wallet", "oci_database_autonomous_database_wallet"),
2728
},
2829
"base64_encode_content": {
2930
Type: schema.TypeBool,
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package oci
5+
6+
import (
7+
"context"
8+
"encoding/base64"
9+
"io/ioutil"
10+
11+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
12+
13+
oci_database "github.com/oracle/oci-go-sdk/v30/database"
14+
)
15+
16+
func init() {
17+
RegisterResource("oci_database_autonomous_database_wallet", DatabaseAutonomousDatabaseWalletResource())
18+
}
19+
20+
func DatabaseAutonomousDatabaseWalletResource() *schema.Resource {
21+
return &schema.Resource{
22+
Timeouts: DefaultTimeout,
23+
Create: createDatabaseAutonomousDatabaseWallet,
24+
Read: readDatabaseAutonomousDatabaseWallet,
25+
Delete: deleteDatabaseAutonomousDatabaseWallet,
26+
Schema: map[string]*schema.Schema{
27+
// Required
28+
"autonomous_database_id": {
29+
Type: schema.TypeString,
30+
Required: true,
31+
ForceNew: true,
32+
},
33+
"password": {
34+
Type: schema.TypeString,
35+
Required: true,
36+
ForceNew: true,
37+
Sensitive: true,
38+
},
39+
40+
// Optional
41+
"base64_encode_content": {
42+
Type: schema.TypeBool,
43+
Optional: true,
44+
Default: false,
45+
ForceNew: true,
46+
},
47+
"generate_type": {
48+
Type: schema.TypeString,
49+
Optional: true,
50+
Default: "SINGLE",
51+
ForceNew: true,
52+
DiffSuppressFunc: EqualIgnoreCaseSuppressDiff,
53+
},
54+
55+
// Computed
56+
"content": {
57+
Type: schema.TypeString,
58+
Computed: true,
59+
},
60+
},
61+
}
62+
}
63+
64+
func createDatabaseAutonomousDatabaseWallet(d *schema.ResourceData, m interface{}) error {
65+
sync := &DatabaseAutonomousDatabaseWalletResourceCrud{}
66+
sync.D = d
67+
sync.Client = m.(*OracleClients).databaseClient()
68+
69+
return CreateResource(d, sync)
70+
}
71+
72+
func readDatabaseAutonomousDatabaseWallet(d *schema.ResourceData, m interface{}) error {
73+
return nil
74+
}
75+
76+
func deleteDatabaseAutonomousDatabaseWallet(d *schema.ResourceData, m interface{}) error {
77+
return nil
78+
}
79+
80+
type DatabaseAutonomousDatabaseWalletResourceCrud struct {
81+
BaseCrud
82+
Client *oci_database.DatabaseClient
83+
Res *[]byte
84+
DisableNotFoundRetries bool
85+
}
86+
87+
func (s *DatabaseAutonomousDatabaseWalletResourceCrud) ID() string {
88+
return GenerateDataSourceHashID("DatabaseAutonomousDatabaseWalletResource-", DatabaseAutonomousDatabaseWalletResource(), s.D)
89+
}
90+
91+
func (s *DatabaseAutonomousDatabaseWalletResourceCrud) Create() error {
92+
request := oci_database.GenerateAutonomousDatabaseWalletRequest{}
93+
94+
if autonomousDatabaseId, ok := s.D.GetOkExists("autonomous_database_id"); ok {
95+
tmp := autonomousDatabaseId.(string)
96+
request.AutonomousDatabaseId = &tmp
97+
}
98+
99+
if generateType, ok := s.D.GetOkExists("generate_type"); ok {
100+
request.GenerateType = oci_database.GenerateAutonomousDatabaseWalletDetailsGenerateTypeEnum(generateType.(string))
101+
}
102+
103+
if password, ok := s.D.GetOkExists("password"); ok {
104+
tmp := password.(string)
105+
request.Password = &tmp
106+
}
107+
108+
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "database")
109+
110+
response, err := s.Client.GenerateAutonomousDatabaseWallet(context.Background(), request)
111+
if err != nil {
112+
return err
113+
}
114+
115+
if response.Content != nil {
116+
defer response.Content.Close()
117+
if contentBytes, err := ioutil.ReadAll(response.Content); err == nil {
118+
s.Res = &contentBytes
119+
} else {
120+
return err
121+
}
122+
}
123+
124+
return nil
125+
}
126+
127+
func (s *DatabaseAutonomousDatabaseWalletResourceCrud) SetData() error {
128+
if s.Res == nil {
129+
return nil
130+
}
131+
132+
s.D.SetId(GenerateDataSourceHashID("DatabaseAutonomousDatabaseWalletResource-", DatabaseAutonomousDatabaseWalletResource(), s.D))
133+
134+
base64EncodeContent := false
135+
if tmp, ok := s.D.GetOkExists("base64_encode_content"); ok {
136+
base64EncodeContent = tmp.(bool)
137+
}
138+
139+
if base64EncodeContent {
140+
s.D.Set("content", base64.StdEncoding.EncodeToString(*s.Res))
141+
} else {
142+
s.D.Set("content", string(*s.Res))
143+
}
144+
145+
return nil
146+
}

oci/database_autonomous_database_wallet_test.go

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import (
1414
)
1515

1616
var (
17+
AutonomousDatabaseWalletRequiredOnlyResource = AutonomousDatabaseWalletResourceDependencies +
18+
generateResourceFromRepresentationMap("oci_database_autonomous_database_wallet", "test_autonomous_database_wallet", Required, Create, autonomousDatabaseWalletRepresentation)
19+
20+
AutonomousDatabaseWalletResourceConfig = AutonomousDatabaseWalletResourceDependencies +
21+
generateResourceFromRepresentationMap("oci_database_autonomous_database_wallet", "test_autonomous_database_wallet", Optional, Update, autonomousDatabaseWalletRepresentation)
22+
1723
adbWalletDbName = randomString(1, charsetWithoutDigits) + randomString(13, charset)
1824

1925
autonomousDatabaseWalletSingularDataSourceRepresentation = map[string]interface{}{
@@ -23,7 +29,14 @@ var (
2329
"base64_encode_content": Representation{repType: Optional, create: `true`},
2430
}
2531

26-
AutonomousDatabaseWalletResourceConfig = generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Required, Create,
32+
autonomousDatabaseWalletRepresentation = map[string]interface{}{
33+
"autonomous_database_id": Representation{repType: Required, create: `${oci_database_autonomous_database.test_autonomous_database.id}`},
34+
"password": Representation{repType: Required, create: `BEstrO0ng_#11`},
35+
"base64_encode_content": Representation{repType: Optional, create: `true`},
36+
"generate_type": Representation{repType: Optional, create: `ALL`},
37+
}
38+
39+
AutonomousDatabaseWalletResourceDependencies = generateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", Required, Create,
2740
getUpdatedRepresentationCopy("db_name", Representation{repType: Required, create: adbWalletDbName}, autonomousDatabaseRepresentation))
2841
)
2942

@@ -37,6 +50,8 @@ func TestDatabaseAutonomousDatabaseWalletResource_basic(t *testing.T) {
3750
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
3851
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
3952

53+
resourceName := "oci_database_autonomous_database_wallet.test_autonomous_database_wallet"
54+
4055
singularDatasourceName := "data.oci_database_autonomous_database_wallet.test_autonomous_database_wallet"
4156

4257
resource.Test(t, resource.TestCase{
@@ -45,11 +60,38 @@ func TestDatabaseAutonomousDatabaseWalletResource_basic(t *testing.T) {
4560
"oci": provider,
4661
},
4762
Steps: []resource.TestStep{
63+
// verify create
64+
{
65+
Config: config + compartmentIdVariableStr + AutonomousDatabaseWalletResourceDependencies +
66+
generateResourceFromRepresentationMap("oci_database_autonomous_database_wallet", "test_autonomous_database_wallet", Required, Create, autonomousDatabaseWalletRepresentation),
67+
Check: resource.ComposeAggregateTestCheckFunc(
68+
resource.TestCheckResourceAttrSet(resourceName, "autonomous_database_id"),
69+
resource.TestCheckResourceAttr(resourceName, "password", "BEstrO0ng_#11"),
70+
),
71+
},
72+
73+
// delete before next create
74+
{
75+
Config: config + compartmentIdVariableStr + AutonomousDatabaseWalletResourceDependencies,
76+
},
77+
// verify create with optionals
78+
{
79+
Config: config + compartmentIdVariableStr + AutonomousDatabaseWalletResourceDependencies +
80+
generateResourceFromRepresentationMap("oci_database_autonomous_database_wallet", "test_autonomous_database_wallet", Optional, Create, autonomousDatabaseWalletRepresentation),
81+
Check: resource.ComposeAggregateTestCheckFunc(
82+
resource.TestCheckResourceAttrSet(resourceName, "autonomous_database_id"),
83+
resource.TestCheckResourceAttr(resourceName, "base64_encode_content", "true"),
84+
resource.TestCheckResourceAttrSet(resourceName, "content"),
85+
resource.TestCheckResourceAttr(resourceName, "generate_type", "ALL"),
86+
resource.TestCheckResourceAttr(resourceName, "password", "BEstrO0ng_#11"),
87+
),
88+
},
89+
4890
// verify singular datasource
4991
{
5092
Config: config +
5193
generateDataSourceFromRepresentationMap("oci_database_autonomous_database_wallet", "test_autonomous_database_wallet", Required, Create, autonomousDatabaseWalletSingularDataSourceRepresentation) +
52-
compartmentIdVariableStr + AutonomousDatabaseWalletResourceConfig,
94+
compartmentIdVariableStr + AutonomousDatabaseWalletResourceDependencies,
5395
Check: resource.ComposeAggregateTestCheckFunc(
5496
resource.TestCheckResourceAttrSet(singularDatasourceName, "autonomous_database_id"),
5597
resource.TestCheckResourceAttr(singularDatasourceName, "generate_type", "SINGLE"),
@@ -62,7 +104,7 @@ func TestDatabaseAutonomousDatabaseWalletResource_basic(t *testing.T) {
62104
{
63105
Config: config +
64106
generateDataSourceFromRepresentationMap("oci_database_autonomous_database_wallet", "test_autonomous_database_wallet", Optional, Create, autonomousDatabaseWalletSingularDataSourceRepresentation) +
65-
compartmentIdVariableStr + AutonomousDatabaseWalletResourceConfig,
107+
compartmentIdVariableStr + AutonomousDatabaseWalletResourceDependencies,
66108
Check: resource.ComposeAggregateTestCheckFunc(
67109
resource.TestCheckResourceAttrSet(singularDatasourceName, "autonomous_database_id"),
68110
resource.TestCheckResourceAttr(singularDatasourceName, "generate_type", "ALL"),

website/docs/d/database_autonomous_database_wallet.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ description: |-
88
---
99

1010
# Data Source: oci_database_autonomous_database_wallet
11+
**Deprecated. Use [oci_database_autonomous_database_wallet](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/database_autonomous_database_wallet) instead.**
12+
1113
This data source provides details about a specific Autonomous Database Wallet resource in Oracle Cloud Infrastructure Database service.
1214

1315
Creates and downloads a wallet for the specified Autonomous Database.

website/docs/guides/deprecated_resources.html.markdown

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@ Data Sources do not have deprecation guide as one should be able to directly rep
3434

3535
**IMPORTANT**: Before executing any deprecation guide, please ensure that you have backed up your Terraform state file to avoid any **data loss**.
3636

37-
| Version | Type | Old Deprecated Resource Name | New Resource Name | Migration? | Guide |
38-
|---------|-------------|-----------------------------------------|-------------------------------------|------------|--------|
39-
| 3.97.0 | Resource | `oci_dns_records` | `oci_dns_rrset` | N/A | N/A |
40-
| 3.97.0 | Resource | `oci_dns_record` | `oci_dns_rrset` | N/A | N/A |
41-
| 3.18 | Resource | `oci_autonomous_data_warehouse` | `oci_autonomous_database` | Yes | N/A |
42-
| 3.18 | Data Source | `oci_autonomous_data_warehouse` | `oci_autonomous_database` | N/A | N/A |
43-
| 3.18 | Data Source | `oci_autonomous_data_warehouses` | `oci_autonomous_databases` | N/A | N/A |
44-
| 3.18 | Resource | `oci_autonomous_data_warehouse_backup` | `oci_autonomous_database_backup` | Yes | N/A |
45-
| 3.18 | Data Source | `oci_autonomous_data_warehouse_backup` | `oci_autonomous_database_backup` | N/A | N/A |
46-
| 3.18 | Data Source | `oci_autonomous_data_warehouse_backups` | `oci_autonomous_database_backups` | N/A | N/A |
47-
| 2.1.12 | Resource | `oci_swift_password` | `oci_identity_auth_token` | No | N/A |
48-
| 2.1.12 | Data Source | `oci_swift_passwords` | `oci_identity_auth_tokens` | N/A | N/A |
37+
| Version | Type | Old Deprecated Resource Name | New Resource Name | Migration? | Guide |
38+
|---------|-------------|-------------------------------------------|-------------------------------------------|------------|--------|
39+
| 4.7.0 | Data Source | `oci_database_autonomous_database_wallet` | `oci_database_autonomous_database_wallet` | N/A | N/A |
40+
| 3.97.0 | Resource | `oci_dns_records` | `oci_dns_rrset` | N/A | N/A |
41+
| 3.97.0 | Resource | `oci_dns_record` | `oci_dns_rrset` | N/A | N/A |
42+
| 3.18 | Resource | `oci_autonomous_data_warehouse` | `oci_autonomous_database` | Yes | N/A |
43+
| 3.18 | Data Source | `oci_autonomous_data_warehouse` | `oci_autonomous_database` | N/A | N/A |
44+
| 3.18 | Data Source | `oci_autonomous_data_warehouses` | `oci_autonomous_databases` | N/A | N/A |
45+
| 3.18 | Resource | `oci_autonomous_data_warehouse_backup` | `oci_autonomous_database_backup` | Yes | N/A |
46+
| 3.18 | Data Source | `oci_autonomous_data_warehouse_backup` | `oci_autonomous_database_backup` | N/A | N/A |
47+
| 3.18 | Data Source | `oci_autonomous_data_warehouse_backups` | `oci_autonomous_database_backups` | N/A | N/A |
48+
| 2.1.12 | Resource | `oci_swift_password` | `oci_identity_auth_token` | No | N/A |
49+
| 2.1.12 | Data Source | `oci_swift_passwords` | `oci_identity_auth_tokens` | N/A | N/A |
4950

5051
### Deprecated Fields
5152

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
subcategory: "Database"
3+
layout: "oci"
4+
page_title: "Oracle Cloud Infrastructure: oci_database_autonomous_database_wallet"
5+
sidebar_current: "docs-oci-resource-database-autonomous_database_wallet"
6+
description: |-
7+
Provides the Autonomous Database Wallet resource in Oracle Cloud Infrastructure Database service
8+
---
9+
10+
# oci_database_autonomous_database_wallet
11+
This resource provides the Autonomous Database Wallet resource in Oracle Cloud Infrastructure Database service.
12+
13+
Creates and downloads a wallet for the specified Autonomous Database.
14+
15+
If passing the base64 encoded content to a `local_file` resource, please use the `content_base64` attribute of the `local_file` resource.
16+
See this [example](https://github.com/terraform-providers/terraform-provider-oci/blob/master/examples/database/adb/autonomous_data_warehouse_wallet.tf) for more details.
17+
18+
Recreate the resource to create and download a new wallet.
19+
20+
## Example Usage
21+
22+
```hcl
23+
resource "oci_database_autonomous_database_wallet" "test_autonomous_database_wallet" {
24+
#Required
25+
autonomous_database_id = oci_database_autonomous_database.test_autonomous_database.id
26+
password = var.autonomous_database_wallet_password
27+
28+
#Optional
29+
base64_encode_content = "false"
30+
generate_type = var.autonomous_database_wallet_generate_type
31+
}
32+
```
33+
34+
## Argument Reference
35+
36+
The following arguments are supported:
37+
38+
* `autonomous_database_id` - (Required) The database [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm).
39+
* `base64_encode_content` - (Optional) Encodes the downloaded zipped wallet in base64. It is recommended to set this to `true` to avoid corrupting the zip file in Terraform state. The default value is `false` to preserve backwards compatibility with Terraform v0.11 configurations.
40+
* `generate_type` - (Optional) The type of wallet to generate.
41+
42+
**Shared Exadata infrastructure usage:**
43+
* `SINGLE` - used to generate a wallet for a single database
44+
* `ALL` - used to generate wallet for all databases in the region
45+
46+
**Dedicated Exadata infrastructure usage:** Value must be `NULL` if attribute is used.
47+
* `password` - (Required) The password to encrypt the keys inside the wallet. The password must be at least 8 characters long and must include at least 1 letter and either 1 numeric character or 1 special character.
48+
49+
50+
** IMPORTANT **
51+
Any change to a property that does not support update will force the destruction and recreation of the resource with the new property values
52+
53+
## Attributes Reference
54+
55+
The following attributes are exported:
56+
57+
* `content` - content of the downloaded zipped wallet for the Autonomous Database. If `base64_encode_content` is set to `true`, then this content will be base64 encoded.
58+
59+
## Import
60+
61+
Import is not supported for this resource.
62+

0 commit comments

Comments
 (0)