1
1
#! /bin/bash
2
+
3
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
4
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
5
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
6
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+
8
+ # Generates and returns a `refresh_token` from vRealize Automation Cloud or vRealize Automation for use by the Terraform P\provider.
9
+ #
10
+ # terraform {
11
+ # required_providers {
12
+ # vra = {
13
+ # source = "vmware/vra"
14
+ # version = ">= x.y.z"
15
+ # }
16
+ # }
17
+ # required_version = ">= 0.13"
18
+ # }
2
19
#
3
- # Script to generate a refresh token for vRA8 on prem or vRA Cloud.
4
- # This will prompt for the following values if they are not already set:
5
- # username
6
- # Sets environment variables for VRA_REFRESH_TOKEN and VRA_URL which can be consumed by the
7
- # TF provider more securely than leaving the token in cleartext.
8
- #
20
+ # provider "vra" {
21
+ # url = "https://api.mgmt.cloud.vmware.com"
22
+ # refresh_token = "mx7w9**********************zB3UC"
23
+ # insecure = false
24
+ # }
9
25
#
10
- if ! [ -x " $( command -v jq) " ]
26
+ # Sets environment variables for `VRA_REFRESH_TOKEN` and `VRA_URL` for use by the Terraform provider.
27
+
28
+ # ## Check for an installtion of jq. ###
29
+
30
+ if ! [ -x " $( command -v jq) " ]
11
31
then
12
- echo -e " \nthe jq utility is missing. See https://stedolan.github.io/jq/ for instructions to get it \n"
32
+ echo -e " \nThe jq utility is missing. See https://stedolan.github.io/jq/ for installation instructions. \n"
13
33
exit 1
14
34
fi
15
35
16
- # Check for an already existing username value
17
- if [[ -v username ]]
36
+ # ## Check for an existing endpoint value. ###
37
+
38
+ if [[ -v VRA_URL || -v fqdn ]]
39
+ then
40
+ echo -e " \nFQDN variable found: $fqdn . Skipping...\n"
41
+ export VRA_URL=" https://$fqdn "
42
+ else
43
+ echo -e " \nEnter the FQDN for the vRealize Automation services:"
44
+ read fqdn
45
+ export VRA_URL=" https://$fqdn "
46
+ fi
47
+
48
+ # ## Check for an existing username value. ###
49
+
50
+ if [[ -v username ]]
18
51
then
19
- echo -e " \nusername variable found: $username \n"
20
- else
21
- echo -e " \nPlease enter username to connect to vra with "
52
+ echo -e " \nUsername variable found: $username . Skipping... \n"
53
+ else
54
+ echo -e " \nEnter the username to authenticate with vRealize Automation: "
22
55
read username
23
56
fi
24
57
25
- # Check for an already existing password value
58
+ # ## Check for an existing password value. ###
59
+
26
60
if [[ -v password ]]
27
61
then
28
- echo -e " \npassword variable found\n"
62
+ echo -e " \nPassword variable found. Skipping... \n"
29
63
else
30
- echo -e " \nPlease enter password to connect to vra with\n "
64
+ echo -e " \nEnter the password to authenticate with vRealize Automation: "
31
65
read -s password
32
66
fi
33
67
34
- # Check for an already existing LDAP/AD domain value
68
+ # ## Check for an a existing domain value. ###
69
+
35
70
if [[ -v domain ]]
36
71
then
37
- echo -e " \nExisting domain variable found: $domain \n"
72
+ echo -e " \nDomain variable found: $domain . Skipping... \n"
38
73
else
39
- echo -e " \nPlease enter domain to connect to vra with (for AD/LDAP users) or press Enter if you not want to use domain "
74
+ echo -e " \nEnter the domain or press enter to skip: "
40
75
read domain
41
76
fi
42
77
43
- if [[ -v VRA_URL || -v host ]]
44
- then
45
- echo -e " \nfound a value for the vra/cas server\n"
46
- export VRA_URL=" https://$host "
47
- else
48
- echo -e " \nPlease enter the hostname/fqdn of the VRA8 server/ or cloud identity server"
49
- read host
50
- export VRA_URL=" https://$host "
51
- fi
78
+ # ## Generate the refresh token. ###
52
79
53
- # use different json bodies with curl depending on whether or not a domain
54
- # was specified
55
- echo -e " \nGetting Token"
80
+ echo -e " \nGenerating Refresh Token..."
56
81
if [[ $domain == " " ]]
57
82
then
58
- export VRA_REFRESH_TOKEN=` curl -vvvk -X POST \
83
+ export VRA_REFRESH_TOKEN=` curl -k -X POST \
59
84
" $VRA_URL /csp/gateway/am/api/login?access_token" \
60
85
-H ' Content-Type: application/json' \
61
86
-s \
@@ -75,11 +100,15 @@ else
75
100
}' | jq -r .refresh_token`
76
101
fi
77
102
78
-
79
- # clean up password
80
- unset password
81
-
82
- echo -e " \nRefresh Token"
83
- echo " ----------------------------"
103
+ echo " "
104
+ echo " ----------Refresh Token----------"
84
105
echo $VRA_REFRESH_TOKEN
85
- echo " ----------------------------"
106
+ echo " ---------------------------------"
107
+ echo " "
108
+ echo " Environmental variables..."
109
+ echo " "
110
+ echo " VRA_URL = " $VRA_URL
111
+ echo " VRA_REFRESH_TOKEN = " $VRA_REFRESH_TOKEN
112
+
113
+ # ## Clear the password value. ###
114
+ unset password
0 commit comments