/// <summary> /// Initializes a new instance of the <see cref="DependencyResolutionWarning"/> class. /// </summary> /// <param name="intrinsic">The intrinsic being warned about.</param> /// <param name="containingResource">The resource that contains the errant intrinsic.</param> /// <param name="location">The the AWS property path to the intrinsic being warned about.</param> protected DependencyResolutionWarning( IIntrinsic intrinsic, IResource containingResource, PropertyPath location) : base(string.Empty) { this.Location = location.Clone(); this.Intrinsic = intrinsic; this.ContainingResource = containingResource; }
/// <summary> /// Initializes a new instance of the <see cref="IntrinsicInfo"/> class. /// </summary> /// <param name="propertyPath">The property path.</param> /// <param name="intrinsic">The intrinsic.</param> /// <param name="resourceMapping">Summary info of the resource targeted by this intrinsic.</param> /// <param name="evaluation">The evaluation.</param> public IntrinsicInfo( PropertyPath propertyPath, IIntrinsic intrinsic, ResourceMapping resourceMapping, object evaluation) { this.targetResource = resourceMapping; this.intrinsic = intrinsic; this.PropertyPath = propertyPath.Clone(); this.InitialEvaluation = evaluation; this.intrinsic.ExtraData = this; }
/// <summary> /// Creates an <see cref="IntrinsicInfo"/> for a Ref intrinsic. /// </summary> /// <param name="refIntrinsic">The reference intrinsic.</param> /// <param name="currentPath">The current path.</param> /// <returns>An <see cref="IntrinsicInfo"/></returns> private IntrinsicInfo ProcessRef(RefIntrinsic refIntrinsic, PropertyPath currentPath) { object evaluation; var target = refIntrinsic.Reference; var param = this.Inputs.FirstOrDefault(i => i.Name == target); if (param != null) { evaluation = param.IsScalar ? (object)param.ScalarIdentity : param.ListIdentity; return(new IntrinsicInfo(currentPath.Clone(), refIntrinsic, null, evaluation)); } if (target.StartsWith("AWS::")) { // An unsupported AWS pseudo parameter like AWS::StackName etc. throw new UnsupportedPseudoParameterWarning( refIntrinsic, this.currentCloudFormationResource, currentPath); } var cloudFormationResource = this.CloudFormationResources .Where(r => TerraformExporterConstants.IgnoredResources.All(ir => ir != r.ResourceType)) .FirstOrDefault(r => r.LogicalResourceId == target); if (cloudFormationResource == null) { // If not found, then reference is to a resource that couldn't be imported eg. a custom resource // or a known unsupported type. throw new UnsupportedResourceWarning(refIntrinsic, this.currentCloudFormationResource, currentPath); } var targetResourceSummary = new ResourceMapping { AwsType = cloudFormationResource.ResourceType, LogicalId = cloudFormationResource.LogicalResourceId, PhysicalId = cloudFormationResource.PhysicalResourceId, TerraformType = this.TerraformResources.First( tr => tr.Name == cloudFormationResource.LogicalResourceId).Type }; evaluation = cloudFormationResource.PhysicalResourceId; return(new IntrinsicInfo(currentPath, refIntrinsic, targetResourceSummary, evaluation)); }
/// <summary> /// Begin processing an intrinsic. /// </summary> /// <param name="intrinsic">The intrinsic.</param> /// <param name="currentPath">The current path.</param> public void EnterIntrinsic(IIntrinsic intrinsic, PropertyPath currentPath) { if (this.lastWarning != null) { // Something that can't be resolved has been found, // so don't process any more here. return; } var clonedPath = currentPath.Clone(); try { if (this.parentIntrinsicPath == null) { // This is a "top level" intrinsic associated directly with a resource attribute. if (this.currentCloudFormationResource.Type == "AWS::Lambda::Permission" && currentPath.Path == "FunctionName" && intrinsic is RefIntrinsic) { // !! NASTY KLUDGE ALERT !! // AWS treats this property as a !Ref which is lambda function's name, but terraform actually wants the ARN here. // If I find more cases like this, then I'll put something into resource traits intrinsic = new GetAttIntrinsic( intrinsic.GetReferencedObjects(this.template).First(), "Arn"); } this.intrinsicInfos.Push(this.currentIntrinsicInfo); this.parentIntrinsicPath = clonedPath; this.currentIntrinsicInfo = this.GetIntrinsicInfo(intrinsic, currentPath); } else { // We have descended the graph to member intrinsic this.intrinsicInfos.Push(this.currentIntrinsicInfo); var intrinsicInfo = this.GetIntrinsicInfo(intrinsic, currentPath); this.currentIntrinsicInfo.NestedIntrinsics.Add(intrinsicInfo); this.currentIntrinsicInfo = intrinsicInfo; } } catch (DependencyResolutionWarning w) { this.lastWarning = w; } }