8
8
9
9
# creates the git repo called "config-repo"
10
10
resource "oci_devops_repository" "config_repo" {
11
+ depends_on = [ oci_identity_api_key . user_api_key ]
11
12
name = local. config_repo_name
12
13
project_id = local. project_id
13
14
repository_type = " HOSTED"
@@ -19,18 +20,21 @@ resource "oci_devops_repository" "config_repo" {
19
20
resource "tls_private_key" "rsa_api_key" {
20
21
algorithm = " RSA"
21
22
rsa_bits = 4096
23
+ count = (local. use-image ? 0 : 1 )
22
24
}
23
25
24
26
resource "oci_identity_api_key" "user_api_key" {
25
- # Required
26
- key_value = tls_private_key. rsa_api_key . public_key_pem
27
- user_id = var. current_user_ocid
27
+ # Required
28
+ key_value = tls_private_key. rsa_api_key [0 ]. public_key_pem
29
+ user_id = var. current_user_ocid
30
+ count = (local. use-image ? 0 : 1 )
28
31
}
29
32
30
33
resource "local_file" "api_private_key" {
31
34
depends_on = [ tls_private_key . rsa_api_key ]
32
35
filename = " ${ path . module } /api-private-key.pem"
33
- content = tls_private_key. rsa_api_key . private_key_pem
36
+ content = tls_private_key. rsa_api_key [0 ]. private_key_pem
37
+ count = (local. use-image ? 0 : 1 )
34
38
}
35
39
36
40
resource "local_file" "ssh_config" {
@@ -95,6 +99,7 @@ resource "null_resource" "create_config_repo" {
95
99
local_file . self_signed_certificate ,
96
100
local_file . oci_build_config ,
97
101
local_file . ssh_config ,
102
+ local_file . api_private_key ,
98
103
random_password . wallet_password
99
104
]
100
105
@@ -105,46 +110,26 @@ resource "null_resource" "create_config_repo" {
105
110
working_dir = " ${ path . module } "
106
111
}
107
112
108
- # copy private key
109
- provisioner "local-exec" {
110
- command = " cp api-private-key.pem ~/.ssh/private-key.pem"
111
- on_failure = fail
112
- working_dir = " ${ path . module } "
113
- }
114
-
115
113
# copy ssh-config
116
114
provisioner "local-exec" {
117
115
command = " cp ssh_config ~/.ssh/config"
118
116
on_failure = fail
119
117
working_dir = " ${ path . module } "
120
118
}
121
-
122
- provisioner "local-exec" {
123
- command = " less ~/.ssh/config"
124
- on_failure = fail
125
- working_dir = " ${ path . module } "
126
- }
127
-
128
- provisioner "local-exec" {
129
- command = " less ~/.ssh/private-key.pem"
130
- on_failure = fail
131
- working_dir = " ${ path . module } "
132
- }
133
-
134
119
provisioner "local-exec" {
135
- command = " chmod 400 ~/.ssh/private-key.pem "
120
+ command = " chmod 600 ~/.ssh/config "
136
121
on_failure = fail
137
122
working_dir = " ${ path . module } "
138
123
}
139
124
125
+ # copy private key
140
126
provisioner "local-exec" {
141
- command = " chmod 600 ~/.ssh/config "
127
+ command = " cp api-private-key.pem ~/.ssh/api-private-key.pem "
142
128
on_failure = fail
143
129
working_dir = " ${ path . module } "
144
130
}
145
-
146
131
provisioner "local-exec" {
147
- command = " ls -lai ~/.ssh"
132
+ command = " chmod 400 ~/.ssh/api-private-key.pem "
148
133
on_failure = fail
149
134
working_dir = " ${ path . module } "
150
135
}
0 commit comments