jw9364
jw9364

Reputation: 41

What is the correct way to reference properties in Cloudformation?

simple question. I want the shortname of a directory service so i can reference the netbios name elsewhere in a CFN file.

Currently just using a parameter to enter it so i can reuse it later... but the short name defaults to the first part of the domain name ( ex. example.com, the short name is automatically example which is what i want)

the problem is if i don't enter it as a parameter, i have no idea how to just reference it..

Does any syntax exist that is !Ref mydirectory.shortname ? I cannot figure/find any info on it

myDirectory:
Type: AWS::DirectoryService::MicrosoftAD
Properties:
  Name:
    Ref: directoryName
  Password: 
    Ref: MicrosoftADPW
  ShortName:
    Ref: ${NetBIOSName}
  Edition: Standard
  VpcSettings: 
    SubnetIds: 
      - !Ref PrivateSubnetA
      - !Ref PrivateSubnetB
    VpcId: !Ref VPC

Upvotes: 0

Views: 725

Answers (1)

guest
guest

Reputation: 901

You should be able to do this with the Fn::Split and Fn::Select functions (I haven't tested this, and don't usually use YAML syntax so it might not be exact):

!Select ["0", !Split[".", !Ref FullyQualifiedName ]]

However, I think this is the wrong way to approach the problem, especially if you have to use the short name in multiple places.

Instead, I would create two parameters, one for the domain name and one for the hostname (which you call shortname). Then combine them using Fn::Sub:

!Sub "${HostName}.${DomainName}"

Upvotes: 2

Related Questions