Skip to content

Commit 4cef006

Browse files
author
Jason Schmidt
authored
fix: update digital ocean token configuration variable and insert warning (#210)
* fix: add warning on namespace to config * fix: use auth for doctl to test credentials * fix: re-namespace digital ocean token to correct ns for pulumi * fix: typo identified in #198 * fix: slight change to error for DO token * fix: additional changes requested on PR
1 parent 036b5b6 commit 4cef006

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

config/pulumi/Pulumi.stackname.yaml.example

+24
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@
1313
# NOTE: Currently, many of the stacks stood up by this process have sanity checks
1414
# that will fill in default values if values are not found in this file.
1515
#
16+
# IMPORTANT NOTE ON NAMESPACE NAMES!
17+
#
18+
# You CANNOT name your namespace with the same name as a Pulumi provider. As an
19+
# example, you cannot call your AWS namespace "aws" or your Digital Ocean
20+
# namespace "digitalocean". If you do so you will get undefined and bizarre errors
21+
# back from Pulumi at runtime.
22+
#
23+
# Known verboten namespaces:
24+
# - aws
25+
# - digitalocean
26+
# - gcp
27+
# - linode
28+
# - azure
29+
#
30+
# This list is subject to change and may not be complete; it is recommended that if
31+
# you experience errors with a provider you check this.
32+
#
33+
# One important exception; if you are providing auth credentials for a given
34+
# provider you will likely be defining them into that providers namespace. So, the
35+
# Digital Ocean token does go in "digitalocean:token".
36+
#
37+
# So far 3 maintainers have fallen into this trap and spent hours trying to sort it.
38+
# Hopefully this helps you from falling into the same trap.
39+
#
1640
################################################################################
1741

1842
config:

extras/jenkins/DigitalOcean/Jenkinsfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pipeline {
137137
$WORKSPACE/pulumi/python/venv/bin/pulumi config set docean:node_count "3" -C pulumi/python/config -s marajenkdo${BUILD_NUMBER}
138138
$WORKSPACE/pulumi/python/venv/bin/pulumi config set docean:region "sfo3" -C pulumi/python/config -s marajenkdo${BUILD_NUMBER}
139139
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kic-helm:fqdn "mara${BUILD_NUMBER}.docean.mantawang.com" -C pulumi/python/config -s marajenkdo${BUILD_NUMBER}
140-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set docean:token "${DO_TOKEN}" --plaintext -C pulumi/python/config -s marajenkdo${BUILD_NUMBER}
140+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set digitalocean:token "${DO_TOKEN}" --plaintext -C pulumi/python/config -s marajenkdo${BUILD_NUMBER}
141141
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:adminpass "${MARA_PASSWORD}" --secret -C pulumi/python/kubernetes/secrets -s marajenkdo${BUILD_NUMBER}
142142
$WORKSPACE/pulumi/python/venv/bin/pulumi config set sirius:accounts_pwd "${MARA_PASSWORD}" --secret -C pulumi/python/kubernetes/secrets -s marajenkdo${BUILD_NUMBER}
143143
$WORKSPACE/pulumi/python/venv/bin/pulumi config set sirius:demo_login_pwd "password" --secret -C pulumi/python/kubernetes/secrets -s marajenkdo${BUILD_NUMBER}

pulumi/python/automation/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def usage():
8282
-d, --debug Enable debug output on all of the commands executed
8383
-b, --banner-type= Banner type to indicate which project is being executed (e.g. {', '.join(BANNER_TYPES)})
8484
-h, --help Prints help information
85-
-s, --stack Specifies the Pulumi stack to use
85+
-s, --stack= Specifies the Pulumi stack to use
8686
-p, --provider= Specifies the provider used (e.g. {', '.join(PROVIDERS)})
8787
8888
OPERATIONS:

pulumi/python/automation/providers/do.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def validate_credentials_cmd(self) -> str:
4141
:return: command to be executed
4242
"""
4343
return f'{self.base_cmd()} account get'
44+
def auth_credentials_cmd(self) -> str:
45+
"""
46+
Runs the doctl auth command for helm usage later in MARA
47+
:return: command to be executed
48+
"""
49+
return f'{self.base_cmd()} auth init'
4450

4551
def save_kubernetes_cluster_cmd(self, cluster_name: str) -> str:
4652
"""
@@ -113,8 +119,8 @@ def new_stack_config(self, env_config, defaults: Union[Dict[Hashable, Any], list
113119
config = super().new_stack_config(env_config, defaults)
114120

115121
if 'DIGITALOCEAN_TOKEN' not in env_config:
116-
config['docean:token'] = input("Digital Ocean API token (this is stored in plain-text - "
117-
"alternatively this can be specified as the environment variable "
122+
config['digitalocean:token'] = input("Digital Ocean API token (this is stored in plain-text - "
123+
"YOU WILL ALSO NEED TO SPECIFY IT IN THE ENVIRONMENT VARIABLE "
118124
"DIGITALOCEAN_TOKEN): ")
119125

120126
token = DigitalOceanProvider.token(stack_config={'config': config}, env_config=env_config)
@@ -176,7 +182,7 @@ def validate_stack_config(self,
176182
super().validate_stack_config(stack_config=stack_config, env_config=env_config)
177183
token = DigitalOceanProvider.token(stack_config=stack_config, env_config=env_config)
178184
do_cli = DoctlCli(access_token=token)
179-
_, err = external_process.run(cmd=do_cli.validate_credentials_cmd())
185+
_, err = external_process.run(cmd=do_cli.auth_credentials_cmd())
180186
if err:
181187
print(f'Digital Ocean authentication error: {err}', file=sys.stderr)
182188
sys.exit(3)
@@ -217,16 +223,16 @@ def token(stack_config: Union[Mapping[str, Any], MutableMapping[str, auto._confi
217223
return env_config['DIGITALOCEAN_TOKEN']
218224

219225
# We were given a reference to a StackConfigParser object
220-
if 'config' in stack_config and 'docean:token' in stack_config['config']:
221-
return stack_config['config']['docean:token']
226+
if 'config' in stack_config and 'digitalocean:token' in stack_config['config']:
227+
return stack_config['config']['digitalocean:token']
222228

223229
# We were given a reference to a Pulumi Stack configuration
224-
if 'docean:token' in stack_config:
225-
return stack_config['docean:token'].value
230+
if 'digitalocean:token' in stack_config:
231+
return stack_config['digitalocean:token'].value
226232

227233
# Otherwise
228234
msg = 'When using the Digital Ocean provider, an API token must be specified - ' \
229-
'this token can be specified with the Pulumi config parameter docean:token ' \
235+
'this token can be specified with the Pulumi config parameter digitalocean:token ' \
230236
'or the environment variable DIGITALOCEAN_TOKEN'
231237
raise InvalidConfigurationException(msg)
232238

0 commit comments

Comments
 (0)