Skip to content

Commit 53f8b76

Browse files
committed
terraform 1.0, and use iam token to create db
1 parent ebc584f commit 53f8b76

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

terraform/create-database.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# create a database
2+
set -e
3+
4+
echo "Retrieving IAM tokens for Cloudant API key..."
5+
IAM_TOKENS=$(curl -X POST 'https://iam.cloud.ibm.com/identity/token' \
6+
-H 'Content-Type: application/x-www-form-urlencoded' \
7+
-d "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=$CLOUDANT_IAM_APIKEY")
8+
9+
API_BEARER_TOKEN=$(echo $IAM_TOKENS | jq -r .access_token)
10+
11+
echo "Creating database..."
12+
curl -f -H "Authorization: Bearer $API_BEARER_TOKEN" -X PUT "$CLOUDANT_URL/$CLOUDANT_DATABASE"

terraform/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ resource "ibm_resource_key" "RKcloudantManager" {
115115

116116
# create the database
117117
provisioner "local-exec" {
118-
command = "curl -X PUT ${ibm_resource_key.RKcloudantManager.credentials.url}/secure-file-storage-metadata"
118+
command = "./create-database.sh"
119+
environment = {
120+
CLOUDANT_IAM_APIKEY = nonsensitive(ibm_resource_key.RKcloudantManager.credentials.apikey)
121+
CLOUDANT_URL = nonsensitive(ibm_resource_key.RKcloudantManager.credentials.url)
122+
CLOUDANT_DATABASE = "secure-file-storage-metadata"
123+
}
119124
}
120125
}
121126

122-
123127
# service access key for AppID
124128
resource "ibm_resource_key" "RKappid" {
125129
name = "${var.basename}-accKey-appid"

terraform/workspace.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "schematics_secure-file-storage",
33
"type": [
4-
"terraform_v0.14"
4+
"terraform_v1.0"
55
],
66
"description": "Deploy services for solution tutorial on applying e2e security (secure file storage)",
77
"tags": [
@@ -14,7 +14,7 @@
1414
},
1515
"template_data": [{
1616
"folder": ".",
17-
"type": "terraform_v0.14",
17+
"type": "terraform_v1.0",
1818
"variablestore": [{
1919
"name": "project_name",
2020
"value": "secure-file-storage",

0 commit comments

Comments
 (0)