@@ -23,19 +23,6 @@ resource "local_file" "dockerfile" {
2323 content = data. template_file . dockerfile . rendered
2424}
2525
26- # creates the server.xml
27- resource "local_file" "server_xml" {
28- filename = " ${ path . module } /server.xml"
29- content = data. template_file . server_xml [0 ]. rendered
30- count = (var. application_type == " WAR" ) ? 1 : 0
31- }
32-
33- # create catalina.sh
34- resource "local_file" "catalina" {
35- filename = " ${ path . module } /catalina.sh"
36- content = data. template_file . catalina_sh [0 ]. rendered
37- count = (var. application_type == " WAR" ) ? 1 : 0
38- }
3926
4027# creates the OCI config file
4128resource "local_file" "wallet" {
@@ -57,14 +44,30 @@ resource "local_file" "deploy_image" {
5744 count = var. nb_copies
5845}
5946
47+ # Repository used to store deployment shell script
48+ resource "oci_artifacts_repository" "application_repository" {
49+ compartment_id = var. compartment_id
50+ is_immutable = true
51+ repository_type = " GENERIC"
52+ display_name = " ${ local . application_name } -repository"
53+ }
54+
55+ resource "oci_generic_artifacts_content_artifact_by_path" "update_container_instance_script" {
56+ depends_on = [
57+ oci_artifacts_repository . application_repository
58+ ]
59+
60+ artifact_path = local. deploy_artifact_path
61+ repository_id = oci_artifacts_repository. application_repository . id
62+ version = local. deploy_artifact_version
63+ source = " ${ path . module } /update_container_instance.sh"
64+ }
6065
61- # Update the config repo with the required bits in the WAR case :
62- resource "null_resource" "create_config_repo_war " {
66+ # Update the config repo with the required bits:
67+ resource "null_resource" "create_config_repo " {
6368 depends_on = [
6469 oci_devops_repository . config_repo ,
6570 local_file . dockerfile ,
66- # local_file.api_key_pem,
67- # local_file.oci_config,
6871 local_file . wallet ,
6972 local_file . self_signed_certificate ,
7073 local_file . oci_build_config ,
@@ -92,190 +95,37 @@ resource "null_resource" "create_config_repo_war" {
9295 working_dir = " ${ path . module } "
9396 }
9497
95- # copy Dockerfile to app directory
96- provisioner "local-exec" {
97- command = " cp Dockerfile ./${ local . config_repo_name } /Dockerfile"
98- on_failure = fail
99- working_dir = " ${ path . module } "
100- }
101-
102- # copy server.xml to app directory
103- provisioner "local-exec" {
104- command = " cp server.xml ./${ local . config_repo_name } /server.xml"
105- on_failure = fail
106- working_dir = " ${ path . module } "
107- }
108-
109- # copy catalina.sh to app directory
110- provisioner "local-exec" {
111- command = " cp catalina.sh ./${ local . config_repo_name } /catalina.sh"
112- on_failure = fail
113- working_dir = " ${ path . module } "
114- }
115-
116- # copy wallet to app directory
117- provisioner "local-exec" {
118- command = " cat wallet.zip.b64 | base64 --decode > ./${ local . config_repo_name } /wallet.zip"
119- on_failure = fail
120- working_dir = " ${ path . module } "
121- }
122-
12398 # copy config to app directory
12499 provisioner "local-exec" {
125100 command = " cp build_spec.yaml ./${ local . config_repo_name } /build_spec.yaml"
126101 on_failure = fail
127102 working_dir = " ${ path . module } "
128103 }
129104
130- provisioner "local-exec" {
131- command = " openssl pkcs12 -export -in certificate.pem -inkey private-key.pem -name self_signed -password \" pass:${ random_password . keystore_password . result } \" > server.p12"
132- on_failure = fail
133- working_dir = " ${ path . module } "
134- }
135-
136- provisioner "local-exec" {
137- command = " keytool -importkeystore -noprompt -srckeystore server.p12 -destkeystore self.keystore -srcstoretype pkcs12 -alias self_signed -srcstorepass \" ${ random_password . keystore_password . result } \" -deststorepass \" ${ random_password . keystore_password . result } \" "
138- on_failure = fail
139- working_dir = " ${ path . module } "
140- }
141-
142- # copy keystore
143- provisioner "local-exec" {
144- command = " cp self.keystore ./${ local . config_repo_name } /self.keystore"
145- on_failure = fail
146- working_dir = " ${ path . module } "
147- }
148-
149- # add wallet to git
150- provisioner "local-exec" {
151- command = " git add wallet.zip"
152- on_failure = fail
153- working_dir = " ${ path . module } /${ local . config_repo_name } "
154- }
155-
156105 # add build.yaml to git
157106 provisioner "local-exec" {
158107 command = " git add build_spec.yaml"
159108 on_failure = fail
160109 working_dir = " ${ path . module } /${ local . config_repo_name } "
161110 }
162111
163- # add Dockerfile to git
164- provisioner "local-exec" {
165- command = " git add Dockerfile"
166- on_failure = fail
167- working_dir = " ${ path . module } /${ local . config_repo_name } "
168- }
169-
170- # add catalina.sh to git
171- provisioner "local-exec" {
172- command = " git add catalina.sh"
173- on_failure = fail
174- working_dir = " ${ path . module } /${ local . config_repo_name } "
175- }
176-
177- # add server.xml to git
178- provisioner "local-exec" {
179- command = " git add server.xml"
180- on_failure = fail
181- working_dir = " ${ path . module } /${ local . config_repo_name } "
182- }
183-
184- # add keystore to git
185- provisioner "local-exec" {
186- command = " git add ./self.keystore"
187- on_failure = fail
188- working_dir = " ${ path . module } /${ local . config_repo_name } "
189- }
190-
191- # Commit changes
192- provisioner "local-exec" {
193- command = " git commit -m \" Initial commit by Terraform script\" "
194- on_failure = fail
195- working_dir = " ${ path . module } /${ local . config_repo_name } "
196- }
197-
198- # Push changes
199- provisioner "local-exec" {
200- command = " git push"
201- on_failure = fail
202- working_dir = " ${ path . module } /${ local . config_repo_name } "
203- }
204-
205- count = (var. application_type == " WAR" ) ? 1 : 0
206-
207- }
208-
209- # Update the config repo with the required bits in the JAR case:
210- resource "null_resource" "create_config_repo_jar" {
211- depends_on = [
212- oci_devops_repository . config_repo ,
213- local_file . dockerfile ,
214- # local_file.api_key_pem,
215- # local_file.oci_config,
216- local_file . wallet ,
217- local_file . self_signed_certificate ,
218- local_file . oci_build_config ,
219- random_password . wallet_password
220- ]
221-
222- # clone new repository
223- provisioner "local-exec" {
224- command = " git clone ${ local . config_repo_url } "
225- on_failure = fail
226- working_dir = " ${ path . module } "
227- }
228-
229- # clone new repository
230- provisioner "local-exec" {
231- command = " git config --global user.email \" ${ local . login } \" "
232- on_failure = fail
233- working_dir = " ${ path . module } "
234- }
235-
236- # clone new repository
237- provisioner "local-exec" {
238- command = " git config --global user.name \" ${ local . service-username } \" "
239- on_failure = fail
240- working_dir = " ${ path . module } "
241- }
242-
243112 # copy Dockerfile to app directory
244113 provisioner "local-exec" {
245114 command = " cp Dockerfile ./${ local . config_repo_name } /Dockerfile"
246115 on_failure = fail
247116 working_dir = " ${ path . module } "
248117 }
249118
250- # copy wallet to app directory
251- provisioner "local-exec" {
252- command = " cat wallet.zip.b64 | base64 --decode > ./${ local . config_repo_name } /wallet.zip"
253- on_failure = fail
254- working_dir = " ${ path . module } "
255- }
256-
257- # copy config to app directory
258- provisioner "local-exec" {
259- command = " cp build_spec.yaml ./${ local . config_repo_name } /build_spec.yaml"
260- on_failure = fail
261- working_dir = " ${ path . module } "
262- }
263-
264- provisioner "local-exec" {
265- command = " openssl pkcs12 -export -in certificate.pem -inkey private-key.pem -name self_signed -password \" pass:${ random_password . keystore_password . result } \" > server.p12"
266- on_failure = fail
267- working_dir = " ${ path . module } "
268- }
269-
119+ # add Dockerfile to git
270120 provisioner "local-exec" {
271- command = " keytool -importkeystore -noprompt -srckeystore server.p12 -destkeystore self.keystore -srcstoretype pkcs12 -alias self_signed -srcstorepass \" ${ random_password . keystore_password . result } \" -deststorepass \" ${ random_password . keystore_password . result } \" "
121+ command = " git add Dockerfile "
272122 on_failure = fail
273- working_dir = " ${ path . module } "
123+ working_dir = " ${ path . module } / ${ local . config_repo_name } "
274124 }
275125
276- # copy keystore
126+ # copy wallet to app directory
277127 provisioner "local-exec" {
278- command = " cp self.keystore ./${ local . config_repo_name } /self.keystore "
128+ command = " cat wallet.zip.b64 | base64 --decode > ./${ local . config_repo_name } /wallet.zip "
279129 on_failure = fail
280130 working_dir = " ${ path . module } "
281131 }
@@ -287,27 +137,19 @@ resource "null_resource" "create_config_repo_jar" {
287137 working_dir = " ${ path . module } /${ local . config_repo_name } "
288138 }
289139
290- # add build.yaml to git
291140 provisioner "local-exec" {
292- command = " git add build_spec.yaml "
141+ command = " openssl pkcs12 -export -in certificate.pem -inkey private-key.pem -name self_signed -password \" pass: ${ random_password . keystore_password . result } \" > server.p12 "
293142 on_failure = fail
294- working_dir = " ${ path . module } / ${ local . config_repo_name } "
143+ working_dir = " ${ path . module } "
295144 }
296145
297- # add Dockerfile to git
298- provisioner "local-exec" {
299- command = " git add Dockerfile"
300- on_failure = fail
301- working_dir = " ${ path . module } /${ local . config_repo_name } "
302- }
146+ count = (local. use-image ? 0 : 1 )
147+ }
303148
304- # add keystore to git
305- provisioner "local-exec" {
306- command = " git add ./self.keystore"
307- on_failure = fail
308- working_dir = " ${ path . module } /${ local . config_repo_name } "
309- }
149+ resource "null_resource" "commit_config_repo" {
310150
151+ depends_on = [ null_resource. language_specific_files ]
152+
311153 # Commit changes
312154 provisioner "local-exec" {
313155 command = " git commit -m \" Initial commit by Terraform script\" "
@@ -322,26 +164,5 @@ resource "null_resource" "create_config_repo_jar" {
322164 working_dir = " ${ path . module } /${ local . config_repo_name } "
323165 }
324166
325- count = (var. application_type == " JAR" ) ? 1 : 0
326-
327- }
328-
329-
330- # Repository used to store deployment shell script
331- resource "oci_artifacts_repository" "application_repository" {
332- compartment_id = var. compartment_id
333- is_immutable = true
334- repository_type = " GENERIC"
335- display_name = " ${ local . application_name } -repository"
336- }
337-
338- resource "oci_generic_artifacts_content_artifact_by_path" "update_container_instance_script" {
339- depends_on = [
340- oci_artifacts_repository . application_repository
341- ]
342-
343- artifact_path = local. deploy_artifact_path
344- repository_id = oci_artifacts_repository. application_repository . id
345- version = local. deploy_artifact_version
346- source = " ${ path . module } /update_container_instance.sh"
167+ count = (local. use-image ? 0 : 1 )
347168}
0 commit comments