|
1 | 1 | locals {
|
2 | 2 | watsonx_assistant_url = "https://api.${var.watson_assistant_region}.assistant.watson.cloud.ibm.com/instances/${var.watson_assistant_instance_id}"
|
3 |
| - watsonx_discovery_url = "https://api.${var.watson_discovery_region}.discovery.watson.cloud.ibm.com/instances/${var.watson_discovery_instance_id}" |
| 3 | + watsonx_discovery_url = "//api.${var.watson_discovery_region}.discovery.watson.cloud.ibm.com/instances/${var.watson_discovery_instance_id}" |
4 | 4 | sensitive_tokendata = sensitive(data.ibm_iam_auth_token.tokendata.iam_access_token)
|
5 | 5 | }
|
6 | 6 |
|
@@ -91,52 +91,69 @@ module "configure_project" {
|
91 | 91 | cos_crn = module.cos.cos_instance_crn
|
92 | 92 | }
|
93 | 93 |
|
94 |
| -# get zip file from code repo |
95 |
| -# add deployment space - not for demo scope |
96 |
| - |
97 |
| -# discovery project creation |
98 |
| -# possibly change type of project here - TBC |
99 |
| -resource "null_resource" "discovery_project_creation" { |
100 |
| - triggers = { |
101 |
| - always_run = timestamp() |
102 |
| - } |
103 |
| - |
104 |
| - provisioner "local-exec" { |
105 |
| - command = "${path.module}/watson-scripts/discovery-project-creation.sh \"${local.watsonx_discovery_url}\"" |
106 |
| - interpreter = ["/bin/bash", "-c"] |
107 |
| - quiet = true |
108 |
| - environment = { |
109 |
| - IAM_TOKEN = local.sensitive_tokendata |
110 |
| - } |
111 |
| - } |
| 94 | +# Discovery project creation |
| 95 | +resource "restapi_object" "configure_discovery_project" { |
| 96 | + depends_on = [data.ibm_iam_auth_token.tokendata] |
| 97 | + path = local.watsonx_discovery_url |
| 98 | + read_path = "${local.watsonx_discovery_url}/v2/projects/{id}?version=2023-03-31" |
| 99 | + read_method = "GET" |
| 100 | + create_path = "${local.watsonx_discovery_url}/v2/projects?version=2023-03-31" |
| 101 | + create_method = "POST" |
| 102 | + id_attribute = "project_id" |
| 103 | + destroy_method = "DELETE" |
| 104 | + destroy_path = "${local.watsonx_discovery_url}/v2/projects/{id}?version=2023-03-31" |
| 105 | + data = <<-EOT |
| 106 | + { |
| 107 | + "name": "gen-ai-rag-sample-app-project", |
| 108 | + "type": "document_retrieval" |
| 109 | + } |
| 110 | + EOT |
| 111 | + update_method = "POST" |
| 112 | + update_path = "${local.watsonx_discovery_url}/v2/projects/{id}?version=2023-03-31" |
| 113 | + update_data = <<-EOT |
| 114 | + { |
| 115 | + "name": "gen-ai-rag-sample-app-project", |
| 116 | + "type": "document_retrieval" |
| 117 | + } |
| 118 | + EOT |
112 | 119 | }
|
113 | 120 |
|
114 |
| -# discovery collection creation |
115 |
| -resource "null_resource" "discovery_collection_creation" { |
116 |
| - depends_on = [null_resource.discovery_project_creation] |
117 |
| - triggers = { |
118 |
| - always_run = timestamp() |
119 |
| - } |
120 |
| - |
121 |
| - provisioner "local-exec" { |
122 |
| - command = "${path.module}/watson-scripts/discovery-collection-creation.sh \"${local.watsonx_discovery_url}\"" |
123 |
| - interpreter = ["/bin/bash", "-c"] |
124 |
| - quiet = true |
125 |
| - environment = { |
126 |
| - IAM_TOKEN = local.sensitive_tokendata |
127 |
| - } |
128 |
| - } |
| 121 | +# Discovery collection creation |
| 122 | +resource "restapi_object" "configure_discovery_collection" { |
| 123 | + depends_on = [data.ibm_iam_auth_token.tokendata, restapi_object.configure_discovery_project] |
| 124 | + path = local.watsonx_discovery_url |
| 125 | + read_path = "${local.watsonx_discovery_url}/v2/projects/${restapi_object.configure_discovery_project.id}/collections/{id}?version=2023-03-31" |
| 126 | + read_method = "GET" |
| 127 | + create_path = "${local.watsonx_discovery_url}/v2/projects/${restapi_object.configure_discovery_project.id}/collections?version=2023-03-31" |
| 128 | + create_method = "POST" |
| 129 | + id_attribute = "collection_id" |
| 130 | + destroy_method = "DELETE" |
| 131 | + destroy_path = "${local.watsonx_discovery_url}/v2/projects/${restapi_object.configure_discovery_project.id}/collections/{id}?version=2023-03-31" |
| 132 | + data = <<-EOT |
| 133 | + { |
| 134 | + "name": "gen-ai-rag-sample-app-data", |
| 135 | + "description": "Sample data" |
| 136 | + } |
| 137 | + EOT |
| 138 | + update_method = "POST" |
| 139 | + update_path = "${local.watsonx_discovery_url}/v2/projects/${restapi_object.configure_discovery_project.id}/collections/{id}?version=2023-03-31" |
| 140 | + update_data = <<-EOT |
| 141 | + { |
| 142 | + "name": "gen-ai-rag-sample-app-data", |
| 143 | + "description": "Sample data" |
| 144 | + } |
| 145 | + EOT |
129 | 146 | }
|
130 | 147 |
|
131 | 148 | # discovery file upload
|
132 | 149 | resource "null_resource" "discovery_file_upload" {
|
133 |
| - depends_on = [null_resource.discovery_collection_creation] |
| 150 | + depends_on = [restapi_object.configure_discovery_collection] |
134 | 151 | triggers = {
|
135 | 152 | always_run = timestamp()
|
136 | 153 | }
|
137 | 154 |
|
138 | 155 | provisioner "local-exec" {
|
139 |
| - command = "${path.module}/watson-scripts/discovery-file-upload.sh \"${local.watsonx_discovery_url}\" \"${path.module}/artifacts/WatsonDiscovery\" " |
| 156 | + command = "${path.module}/watson-scripts/discovery-file-upload.sh \"https:${local.watsonx_discovery_url}\" \"${restapi_object.configure_discovery_project.id}\" \"${restapi_object.configure_discovery_collection.id}\" \"${path.module}/artifacts/WatsonDiscovery\" " |
140 | 157 | interpreter = ["/bin/bash", "-c"]
|
141 | 158 | quiet = true
|
142 | 159 | environment = {
|
@@ -171,17 +188,6 @@ data "external" "assistant_get_integration_id" {
|
171 | 188 | }
|
172 | 189 | }
|
173 | 190 |
|
174 |
| -# get discovery project ID |
175 |
| -data "external" "discovery_project_id" { |
176 |
| - depends_on = [null_resource.discovery_project_creation] |
177 |
| - program = ["bash", "${path.module}/watson-scripts/discovery-get-project.sh"] |
178 |
| - query = { |
179 |
| - tokendata = local.sensitive_tokendata |
180 |
| - watson_discovery_url = local.watsonx_discovery_url |
181 |
| - } |
182 |
| -} |
183 |
| - |
184 |
| - |
185 | 191 | # Update CI pipeline with Assistant instance ID
|
186 | 192 | resource "ibm_cd_tekton_pipeline_property" "watsonx_assistant_id_pipeline_property_ci" {
|
187 | 193 | provider = ibm.ibm_resources
|
|
0 commit comments