Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWoolfenden committed Oct 21, 2022
1 parent a92fc80 commit 5a89f70
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ func ParseResources(resources cloudformation.Resources, funcMap tftemplate.FuncM
"AWS::SSM::Document": awsSsmDocument,
"AWS::AutoScaling::LaunchConfiguration": awsLaunchConfiguration,
"AWS::AutoScaling::AutoScalingGroup": awsAutoscalingGroup,
"AWS::DirectoryService::MicrosoftAD": awsDirectoryServiceDirectory,
"AWS::CodeBuild::Project": awsCodebuildProject,
"AWS::CodePipeline::Pipeline": awsCodepipeline,
}

var myContent []byte
Expand All @@ -317,7 +320,7 @@ func ParseResources(resources cloudformation.Resources, funcMap tftemplate.FuncM
}

//needs to pivot on policy template from resource
tmpl, err := tftemplate.New("test").Funcs(funcMap).Parse(string(myContent))
tmpl, err := tftemplate.New("sato").Funcs(funcMap).Parse(string(myContent))

if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions src/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,12 @@ var awsAutoscalingGroup []byte

//go:embed resources/aws_launch_configuration.template
var awsLaunchConfiguration []byte

//go:embed resources/aws_directory_service_directory.template
var awsDirectoryServiceDirectory []byte

//go:embed resources/aws_codebuild_project.template
var awsCodebuildProject []byte

//go:embed resources/aws_codepipeline.template
var awsCodepipeline []byte
1 change: 1 addition & 0 deletions src/resources/aws_cloudformation_stack.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

resource "aws_cloudformation_stack" "{{.item}}" {
name="{{.item}}"
{{- if .resource.NotificationARNs}}
Expand Down
99 changes: 99 additions & 0 deletions src/resources/aws_codebuild_project.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
resource "aws_codebuild_project" "{{.item}}" {
Artifacts = {*codebuild.Project_Artifacts | 0xc0002b5540}
BadgeEnabled = {*bool | 0x0} nil
BuildBatchConfig = {*codebuild.Project_ProjectBuildBatchConfig | 0x0} nil
Cache = {*codebuild.Project_ProjectCache | 0x0} nil
ConcurrentBuildLimit = {*int | 0x0} nil
Description = {*string | 0x0} nil
EncryptionKey = {*string | 0x0} nil
Environment = {*codebuild.Project_Environment | 0xc0002af800}
FileSystemLocations = {[]codebuild.Project_ProjectFileSystemLocation} nil
LogsConfig = {*codebuild.Project_LogsConfig | 0x0} nil
Name = {*string | 0xc00027ae10} "goformation-stackStagingBuild"
QueuedTimeoutInMinutes = {*int | 0x0} nil
ResourceAccessRole = {*string | 0x0} nil
SecondaryArtifacts = {[]codebuild.Project_Artifacts} nil
SecondarySourceVersions = {[]codebuild.Project_ProjectSourceVersion} nil
SecondarySources = {[]codebuild.Project_Source} nil
ServiceRole = {string} ""
Source = {*codebuild.Project_Source | 0xc0002ad8c0}
SourceVersion = {*string | 0x0} nil
Tags = {[]tags.Tag} nil
TimeoutInMinutes = {*int | 0x0} nil
Triggers = {*codebuild.Project_ProjectTriggers | 0x0} nil
Visibility = {*string | 0x0} nil
VpcConfig = {*codebuild.Project_VpcConfig | 0x0} nil
name = "test-project"
description = "test_codebuild_project"
build_timeout = "5"
service_role = aws_iam_role.example.arn

artifacts {
type = "NO_ARTIFACTS"
}

cache {
type = "S3"
location = aws_s3_bucket.example.bucket
}

environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/standard:1.0"
type = "LINUX_CONTAINER"
image_pull_credentials_type = "CODEBUILD"

environment_variable {
name = "SOME_KEY1"
value = "SOME_VALUE1"
}

environment_variable {
name = "SOME_KEY2"
value = "SOME_VALUE2"
type = "PARAMETER_STORE"
}
}

logs_config {
cloudwatch_logs {
group_name = "log-group"
stream_name = "log-stream"
}

s3_logs {
status = "ENABLED"
location = "${aws_s3_bucket.example.id}/build-log"
}
}

source {
type = "GITHUB"
location = "https://github.com/mitchellh/packer.git"
git_clone_depth = 1

git_submodules_config {
fetch_submodules = true
}
}

source_version = "master"

vpc_config {
vpc_id = aws_vpc.example.id

subnets = [
aws_subnet.example1.id,
aws_subnet.example2.id,
]

security_group_ids = [
aws_security_group.example1.id,
aws_security_group.example2.id,
]
}

tags = {
Environment = "Test"
}
}
66 changes: 66 additions & 0 deletions src/resources/aws_codepipeline.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
resource "aws_codepipeline" "{{.item}}" {
{{- if .resource.ArtifactStore}}
artifact_store {
location = "{{ .resource.ArtifactStore.Location}}"
type = "{{ .resource.ArtifactStore.Type}}"
{{- if .resource.ArtifactStore.EncryptionKey}}
encryption_key {
id = "{{ .resource.ArtifactStore.EncryptionKey.Id}}"
type = "{{ .resource.ArtifactStore.EncryptionKey.Type}}"
}
{{- end}}
}
{{- end}}
{{- if .resource.ArtifactStores}}
{{- range $i, $a := .resource.ArtifactStores}}
artifact_store {
location = "{{ $a.Location}}"
type = "{{ $a.resource.ArtifactStore.Type}}"
{{- if $a.EncryptionKey}}
encryption_key {
id = "{{ $a.EncryptionKey.Id}}"
type = "{{ $a.EncryptionKey.Type}}"
}
{{- end}}
}
{{- end}}
{{- end}}
{{- if .resource.Name}}
name = "{{.resource.Name}}"
{{- else}}
name = "{{.item}}"
{{- end}}
role_arn = "{{.resource.RoleArn}}"
{{- range $i, $a := .resource.Stages}}
stage {
name = "{{$a.Name}}"
{{- range $j, $b := $a.Actions}}
action {
category = "{{$b.ActionTypeId.Category}}"
owner = "{{$b.ActionTypeId.Owner}}"
name = "{{$b.Name}}"
provider = "{{$b.ActionTypeId.Provider}}"
version = "{{$b.ActionTypeId.Version}}"
{{- if $b.Configuration}}
configuration {
{{- range $i, $c := $b.Configuration}}
"{{$i}}" = "{{$c}}"
{{- end }}
}
{{- end}}
inputs_artifacts="{{$b.InputArtifacts}}"
output_artifacts="{{$b.OutputArtifacts}}"
namespace="{{$b.Namespace}}"
region="{{$b.Region}}"
role_arn="{{$b.RoleArn}}"
run_order="{{$b.RunOrder}}"
}
{{- end}}
}
{{- end}}
{{- if .resource.Tags}}
tags = {
{{Tags .resource.Tags}}
}
{{- end}}
}
13 changes: 13 additions & 0 deletions src/resources/aws_directory_service_directory.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "aws_directory_service_directory" "{{.item}}" {
name = "{{.resource.Name}}"
password = "{{.resource.Password}}"
{{- if .resource.VpcSettings}}
vpc_settings {
vpc_id = "{{.resource.VpcSettings.VpcId}}"
subnet_ids = {{.resource.VpcSettings.SubnetIds}}
}
{{- end}}
edition = "{{ .resource.Edition}}"
enable_sso={{ Boolean .resource.EnableSso}}
shortname="{{ .resource.ShortName}}"
}

0 comments on commit 5a89f70

Please sign in to comment.