We usually create consumer org mainly via API Manager console but with evolving CICD world and cases where we need to create several Consumer orgs, we might want to automate it.
Below is a sample script which can be used to create a Consume Org along with its owner (This example assume we are loading user in Local User Registry).
#!/bin/sh
if [ -z "$1" ]; then
echo "Error: APIC platform api url not provided. Please provide platform api url as a command line argument."
exit 1
fi
server=$1 # provider server as command line argument
#porg details
user=progusername
password=porgpassword
porg_name=student0
catalog=externalgw
realm=provider/default-idp-2
# build consumer user file
echo "username: user1">cOrg-user.txt
echo "email: user1@example.com">>cOrg-user.txt
echo "first_name: User">>cOrg-user.txt
echo "last_name: Test">>cOrg-user.txt
echo "password: Passw0rd">>cOrg-user.txt
# build consumer org file
echo "name: TestCOrg">cOrg.txt
echo "title: TestCOrg">>cOrg.txt
# apic login
./apic login --username $user --password $password --server $server --realm $realm
sleep 1
echo create new user in catalog:$catalog
# create user
result=$(./apic users:create --server $server --org $porg_name --user-registry $catalog-catalog cOrg-user.txt)
echo $result
# get user url
userurl=$(echo $result | cut -d' ' -f 4)
echo $userurl
# add userurl as owner_url in Corg file
owner_url="owner_url: $userurl"
echo $owner_url>>cOrg.txt
echo create new consumer org
# create consumer org with user created above as owner
./apic consumer-orgs:create --server $server --org $porg_name --catalog $catalog cOrg.txt
sleep 2
echo consumer org and owner created
# apic logout
./apic logout --server $server