func()

in custom-targets/infrastructure-manager/im-deployer/render.go [101:152]


func (r *renderer) render(ctx context.Context) (*clouddeploy.RenderResult, error) {
	fmt.Printf("Downloading render input archive to %s and unarchiving to %s\n", srcArchivePath, srcPath)
	inURI, err := r.req.DownloadAndUnarchiveInput(ctx, r.gcsClient, srcArchivePath, srcPath)
	if err != nil {
		return nil, fmt.Errorf("unable to download and unarchive render input: %v", err)
	}
	fmt.Printf("Downloaded render input archive from %s\n", inURI)

	// Determine the path to the Terraform configuration.
	terraformConfigPath := path.Join(srcPath, r.params.configPath)
	autoVarsPath := path.Join(terraformConfigPath, autoTFVarsFileName)
	fmt.Printf("Generating auto variable definitions file: %s\n", autoVarsPath)
	if err := generateAutoTFVarsFile(autoVarsPath, r.params); err != nil {
		return nil, fmt.Errorf("error generating variable definitions file: %v", err)
	}
	fmt.Printf("Finished generating auto variable definitions file: %s\n", autoVarsPath)

	// Archive the Terraform configuration into a zip file since this is one of the accepted formats
	// by Infrastructure Manager when updating the Deployment resource with Terraform configuration.
	fmt.Printf("Archiving Terraform configuration in %s into zip file for use at deploy time\n", srcPath)
	if err = zipArchiveDir(terraformConfigPath, renderedArchiveName); err != nil {
		return nil, fmt.Errorf("error archiving terraform configuration: %v", err)
	}
	fmt.Println("Uploading archived Terraform configuration")
	tcURI, err := r.req.UploadArtifact(ctx, r.gcsClient, renderedArchiveName, &clouddeploy.GCSUploadContent{LocalPath: renderedArchiveName})
	if err != nil {
		return nil, fmt.Errorf("error uploading archived terraform configuration: %v", err)
	}
	fmt.Printf("Uploaded archived Terraform configuration to %s\n", tcURI)

	fmt.Println("Creating rendered Deployment for use at deploy time")
	renderedDeploymentYAML, err := r.deploymentYAML(tcURI)
	if err != nil {
		return nil, fmt.Errorf("error creating rendered deployment: %v", err)
	}
	fmt.Println("Uploading rendered Deployment")
	dURI, err := r.req.UploadArtifact(ctx, r.gcsClient, renderedDeploymentFileName, &clouddeploy.GCSUploadContent{Data: renderedDeploymentYAML})
	if err != nil {
		return nil, fmt.Errorf("error uploading rendered deployment: %v", err)
	}
	fmt.Printf("Uploaded rendered Deployment to %s\n", dURI)

	renderResult := &clouddeploy.RenderResult{
		ResultStatus: clouddeploy.RenderSucceeded,
		ManifestFile: dURI,
		Metadata: map[string]string{
			clouddeploy.CustomTargetSourceMetadataKey:    imDeployerSampleName,
			clouddeploy.CustomTargetSourceSHAMetadataKey: clouddeploy.GitCommit,
		},
	}
	return renderResult, nil
}