Skip to content

Commit

Permalink
add ssh key support and 401 error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HotNoob committed May 25, 2024
1 parent b28259f commit d2fd114
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions create_oracle_arm_instance.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@


#oci session authenticate
#select your location, in my case i used ca-toronto-1, this will likely be different for you
#if prompted for a profile name, type in "DEFAULT", or whatever you set $profile to be
#after logging in, fillout tenancy id below.
#then run the script and use output to fill out the rest of the setup variables ($tenancyId, $imageId, $subnetId, $availDomain)
#then run the script and use output to fill out the rest of the setup variables ($tenancyId, $imageId, $subnetId, $availDomain )

#your account's tenancy id
#on oracle cloud, go to profile -> tenancy: {your tenancy name here} -> {click} -> under Tenancy Information -> Copy OCID
Expand All @@ -24,6 +25,11 @@ $subnetId = "ocid1.subnet.oc1.***.***"
#oci iam availability-domain list -c {your tenancy id (OCID) here}
$availDomain = "IGuL:***"

#ssh key to be put in authorized_keys
# ssh-rsa *** rsa-key***
$sshKey = 'ssh-rsa ***'


###### RUN SETUP FOR ABOVE VARIABLE VALUES ####
### ONCE variables have been set, set $setup = 0
[bool] $setup = 1
Expand All @@ -43,6 +49,10 @@ $authParams = " --config-file $configFile --profile $profile --auth security_to
$requestInterval = 60 #interval in seconds
$max = 60*60*24 / $requestInterval

If($sshKey)
{
$sshKey = "--metadata `"{'ssh_authorized_keys':'$sshKey'}`""
}



Expand Down Expand Up @@ -105,7 +115,7 @@ For ($i = 0; $i -lt $max; $i++)

#request instance creation
#must be single line, cuz iex / powershell syntax bs
$response = & iex "& oci compute instance launch --no-retry --availability-domain $availDomain $authParams --compartment-id $tenancyId --image-id $imageId --shape 'VM.Standard.A1.Flex' --shape-config `"{`'ocpus`':$cpus,`'memoryInGBs`':$ram}`" --subnet-id $subnetId " 2>&1
$response = & iex "& oci compute instance launch --no-retry $sshKey --availability-domain $availDomain $authParams --compartment-id $tenancyId --image-id $imageId --shape 'VM.Standard.A1.Flex' --shape-config `"{`'ocpus`':$cpus,`'memoryInGBs`':$ram}`" --subnet-id $subnetId " 2>&1

If($silent -eq 0)
{
Expand Down Expand Up @@ -162,6 +172,14 @@ For ($i = 0; $i -lt $max; $i++)
Read-Host -Prompt "Press any key to continue..."
Exit;
}

If($json.status -eq 401) #401
{
Write-Output "Status 401 = Authentication Failed / Expired."
Write-Output "Please Run: oci session authenticate"
Read-Host -Prompt "Press any key to continue..."
Exit;
}
}
catch
{
Expand Down

1 comment on commit d2fd114

@HotNoob
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to help address issue #3

Please sign in to comment.