Skip to content

Commit 1a83cf9

Browse files
Merge pull request #55 from Uddipaan-Hazarika/develop
HUBS-1695 | Add example documentation for database specific VDB provi…
2 parents 498070c + 5cbf47a commit 1a83cf9

File tree

23 files changed

+2437
-0
lines changed

23 files changed

+2437
-0
lines changed

docs/guides/provider_guide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Guide: <guide name> Delphix Provider Guide
2+
3+
## Delphix Provider Guide
4+
[We have provided a handful of examples in our GitHub repository to help you get a jump start with our Delphix Provider.](https://github.com/delphix-integrations/terraform-provider-delphix/tree/main/examples) These examples range from Terraform resource templates, quick Terraform examples, and full Jenkins pipelines. We update this repository based on our implementation experience, so be sure to check back for updates!
5+
6+
If you have a suggested template, request, or modification, please submit it in our [GitHub Issues section.](https://github.com/delphix-integrations/terraform-provider-delphix)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Summary
2+
The Jenkinsfile presents a simple CI/CD scenario where it provisions a VDB, runs an automated test (like Selenium or JUnit) against that application & dataset, and then destroys the VDB. On testing failure, which will happen every time, a bookmark is created. This Jenksinfile leverages the DCT Terrafrom Provider and an API Curl command to show the full breadth of possibilites. All other steps are mocked out.
3+
4+
### Simple Getting Stated
5+
1) Create a Jenkinsfile Pipeline Job
6+
2) Insert or reference the associated `Jenkinsfile` file.
7+
- Note: This Jenkinsfile also references the Terraform files in the `../simple-provision` folder. Feel free to fork, update, and modify those.
8+
3) Update the following values:
9+
- DCT_HOSTNAME - Example: `123.0.0.0`
10+
- DCT_API_KEY - Example: `2.abc...`
11+
- [Manage this value through the Jenkins' Credentials plugin](https://docs.cloudbees.com/docs/cloudbees-ci/latest/cloud-secure-guide/injecting-secrets)
12+
- In a pinch, update it directly.
13+
- SOURCE_VDB - Example: `Oracle_QA`
14+
4) Run Jenkins Job
15+
16+
Note: I suggest you reduce the sleep timers in early testing scenarios .
17+
18+
19+
### Known Issues
20+
On VDB destroy, the underlying Bookmark's snapshot will be deleted and the Bookmark will become "dangling".
21+
Instead, I recommend using an "Enable/Disable" command instead of "Provision/Destroy" or skip the destroy VDB on failure.
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
pipeline {
2+
agent any
3+
4+
environment {
5+
def provision_successful = false
6+
def vdb_id = ""
7+
def vdb_name = ""
8+
def DCT_HOSTNAME = "<INSERT>"
9+
def SOURCE_VDB = "<INSERT>"
10+
test_error = 'false'
11+
}
12+
13+
stages {
14+
15+
stage ('Build Application') {
16+
steps {
17+
echo ('Building...')
18+
sleep (50)
19+
}
20+
}
21+
22+
stage ('Stand Up Full Application') {
23+
parallel {
24+
stage ('Apply Application Install') {
25+
steps{
26+
echo ('Provisioning Test App...')
27+
sleep (30)
28+
}
29+
}
30+
stage ('Create Database w/ Terraform') {
31+
steps {
32+
script {
33+
echo ('Provisioning VDB...')
34+
git branch: 'main', changelog: false, poll: false, url: 'https://github.com/delphix-integrations/terraform-provider-delphix.git'
35+
// sh ('ls -R')
36+
sh ('terraform -chdir=examples/simple-provision init')
37+
withCredentials([string(credentialsId: 'DCT_API_KEY', variable: 'KEY')]) {
38+
sh ('terraform -chdir=examples/simple-provision apply -var="source_data_id_1=$SOURCE_VDB" -var="dct_hostname=$DCT_HOSTNAME" -var="dct_api_key=$KEY" -auto-approve')
39+
}
40+
vdb_id = sh(script: 'terraform -chdir=examples/simple-provision output vdb_id_1', returnStdout: true)
41+
vdb_id = vdb_id.replaceAll('\\"', "").trim()
42+
vdb_name = sh(script: 'terraform -chdir=examples/simple-provision output vdb_name_1', returnStdout: true)
43+
echo ("vdb_id:" + vdb_id)
44+
echo ("vdb_name:" + vdb_name)
45+
provision_successful = true
46+
}
47+
}
48+
}
49+
}
50+
}
51+
52+
stage ('Combine') {
53+
steps {
54+
echo ('Combining...')
55+
sleep (10)
56+
}
57+
}
58+
59+
stage ('Run Tests') {
60+
parallel {
61+
stage ('UI') {
62+
stages {
63+
stage ('Run UI Tests') {
64+
steps{
65+
echo ('UI Tests...')
66+
sleep (150)
67+
}
68+
}
69+
stage ('Send UI Test Results') {
70+
steps{
71+
echo ('Send UI Test Results...')
72+
sleep (5)
73+
}
74+
}
75+
}
76+
}
77+
stage ('Unit') {
78+
stages {
79+
stage ('Run Unit Tests') {
80+
steps {
81+
script {
82+
echo ('Unit Tests...')
83+
sleep (70)
84+
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
85+
echo ('Identified 7 failing Unit Tests!')
86+
test_error = 'true';
87+
sh "exit 1"
88+
}
89+
}
90+
}
91+
}
92+
stage ('Send Unit Test Results') {
93+
steps{
94+
echo ('Send Unit Test Results...')
95+
sleep (6)
96+
}
97+
}
98+
}
99+
}
100+
stage ('Integ.') {
101+
stages {
102+
stage ('Run Integration Tests') {
103+
steps{
104+
echo ('UI Tests...')
105+
sleep (130)
106+
}
107+
}
108+
stage ('Send Integration Test Results') {
109+
steps{
110+
echo ('Send Integration Test Results...')
111+
sleep (4)
112+
}
113+
}
114+
}
115+
}
116+
}
117+
}
118+
119+
stage ('Bookmark Database') {
120+
when {
121+
equals expected: 'true', actual: test_error
122+
}
123+
steps{
124+
script {
125+
echo ('Bookmark VDB... ')
126+
withCredentials([string(credentialsId: 'DCT_API_KEY', variable: 'KEY')]) {
127+
sh """
128+
curl -X 'POST' -k \
129+
'https://$DCT_HOSTNAME/v3/bookmarks' \
130+
-H 'accept: application/json' \
131+
-H 'Authorization: apk ${KEY}' \
132+
-H 'Content-Type: application/json' \
133+
-d '{
134+
"name": "JKNS-BOOKMARK-$BUILD_NUMBER",
135+
"vdb_ids": [
136+
"${vdb_id}"
137+
],
138+
"retain_forever": true,
139+
"make_current_account_owner": true
140+
}'
141+
"""
142+
}
143+
}
144+
}
145+
}
146+
147+
stage ('Destroy Full Application') {
148+
parallel {
149+
stage ('Destroy Application') {
150+
steps {
151+
script {
152+
echo ('Destroying Application...')
153+
sleep (30)
154+
}
155+
}
156+
}
157+
stage ('Destroy Database w/ Terraform') {
158+
steps {
159+
script {
160+
if (provision_successful) {
161+
sleep (60)
162+
echo ('Destroying Test App and VDB...')
163+
withCredentials([string(credentialsId: 'DCT_API_KEY', variable: 'KEY')]) {
164+
sh ('terraform -chdir=examples/simple-provision destroy -var="source_data_id_1=$SOURCE_VDB" -var="dct_hostname=$DCT_HOSTNAME" -var="dct_api_key=$KEY" -auto-approve')
165+
}
166+
} else {
167+
echo ('No App or VDB to destroy...')
168+
}
169+
}
170+
}
171+
}
172+
}
173+
}
174+
}
175+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
### Simple Getting Stated
3+
4+
1) Update the dct_hostname and dct_api_key variables in the `variables.tf` or in Terrafrom Cloud with the DCT Server and API Key.
5+
For example:
6+
- DCT: uv123abcfei59h6qajyy.vm.cld.sr
7+
- API Key: 2.ZAAgpjHxljW7A7g...
8+
9+
2) Update `Oracle_QA` with an applicable VDB name and run the following commands.
10+
```
11+
# Create all resources
12+
terraform apply -var="source_data_id_1=Oracle_QA"
13+
14+
# Destroy resources
15+
terraform destroy"
16+
```
17+
18+
19+
### Troubleshoot: Invalid Resource State
20+
21+
If you find that you've lost the sync between DCT and Terraform, use the `terraform state rm` command to help reconfigure without starting over.
22+
```
23+
terraform state rm delphix_vdb.provision_vdb_1
24+
25+
terraform state rm delphix_vdb_group.create_vdb_group
26+
```
27+
28+
[Documentation](https://developer.hashicorp.com/terraform/cli/commands/state/rm)

examples/simple-provision/main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Configure the connection to Data Control Tower
2+
provider "delphix" {
3+
host = var.dct_hostname
4+
key = var.dct_api_key
5+
tls_insecure_skip = true
6+
}
7+
8+
# Provision a VDB 1
9+
resource "delphix_vdb" "provision_vdb_1" {
10+
name = "tfmtest1"
11+
source_data_id = var.source_data_id_1
12+
auto_select_repository = true
13+
}
14+
15+
# Create a VDB Group with VDB 1
16+
resource "delphix_vdb_group" "create_vdb_group" {
17+
name = "Terraform Demo Group"
18+
vdb_ids = [
19+
delphix_vdb.provision_vdb_1.id
20+
]
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
###
2+
# VDB Group Information
3+
###
4+
output "vdb_group_id" {
5+
value = delphix_vdb_group.create_vdb_group.id
6+
}
7+
8+
output "vdb_group_name" {
9+
value = delphix_vdb_group.create_vdb_group.name
10+
}
11+
12+
###
13+
# VDB 1 Information
14+
###
15+
output "vdb_id_1" {
16+
value = delphix_vdb.provision_vdb_1.id
17+
}
18+
19+
output "vdb_name_1" {
20+
value = delphix_vdb.provision_vdb_1.name
21+
}
22+
23+
output "vdb_ip_address_1" {
24+
value = delphix_vdb.provision_vdb_1.ip_address
25+
}
26+
27+
output "vdb_database_type_1" {
28+
value = delphix_vdb.provision_vdb_1.database_type
29+
}
30+
31+
output "vdb_database_version_1" {
32+
value = delphix_vdb.provision_vdb_1.database_version
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
variable "dct_hostname" {
2+
type = string
3+
description = "dct hostname config file [default: workspace variable set]"
4+
}
5+
6+
variable "dct_api_key" {
7+
type = string
8+
description = "dct api key config file [default: workspace variable set]"
9+
}
10+
11+
variable "source_data_id_1" {
12+
description = "Name or ID of the VDB or Data Source to provision from. [User Defined]"
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
delphix = {
4+
source = "delphix-integrations/delphix"
5+
version = "1.0.0"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)