Skip to content
Permalink
Browse files

added tf-s3-archetype (issue #69)

  • Loading branch information
s1234a6i authored and Clayton7510 committed Jul 31, 2019
1 parent bf8841e commit f3f399149bf381692440f464db1509f876a93dae
Showing with 649 additions and 5 deletions.
  1. BIN .DS_Store
  2. +23 −2 README.md
  3. +2 −1 tf-build-tools/pom.xml
  4. +1 −1 tf-build-tools/tf-cmd-api/pom.xml
  5. +1 −1 tf-build-tools/tf-maven-plugin/pom.xml
  6. +32 −0 tf-build-tools/tf-s3-archetype/pom.xml
  7. +21 −0 tf-build-tools/tf-s3-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
  8. +167 −0 tf-build-tools/tf-s3-archetype/src/main/resources/archetype-resources/pom.xml
  9. +24 −0 tf-build-tools/tf-s3-archetype/src/main/resources/archetype-resources/src/main/tf/s3/inputs.tf
  10. +40 −0 tf-build-tools/tf-s3-archetype/src/main/resources/archetype-resources/src/main/tf/s3/main.tf
  11. +9 −0 tf-build-tools/tf-s3-archetype/src/main/resources/archetype-resources/src/main/tf/s3/outputs.tf
  12. +2 −0 ...ild-tools/tf-s3-archetype/src/main/resources/archetype-resources/src/main/tf/s3/tfvars/dev.tfvars
  13. +2 −0 ...ld-tools/tf-s3-archetype/src/main/resources/archetype-resources/src/main/tf/s3/tfvars/test.tfvars
  14. +27 −0 ...ls/tf-s3-archetype/src/main/resources/archetype-resources/src/main/tf/s3_replicated_src/inputs.tf
  15. +86 −0 ...ools/tf-s3-archetype/src/main/resources/archetype-resources/src/main/tf/s3_replicated_src/main.tf
  16. +9 −0 ...s/tf-s3-archetype/src/main/resources/archetype-resources/src/main/tf/s3_replicated_src/outputs.tf
  17. +13 −0 ...main/resources/archetype-resources/src/main/tf/s3_replicated_src/policies/assume-role-policy.json
  18. +65 −0 ...main/resources/archetype-resources/src/main/tf/s3_replicated_src/policies/replication-policy.json
  19. +2 −0 ...-archetype/src/main/resources/archetype-resources/src/main/tf/s3_replicated_src/tfvars/dev.tfvars
  20. +2 −0 ...archetype/src/main/resources/archetype-resources/src/main/tf/s3_replicated_src/tfvars/test.tfvars
  21. +116 −0 tf-build-tools/tf-s3-archetype/src/main/resources/archetype-resources/src/test/groovy/S3Spec.groovy
  22. +5 −0 tf-build-tools/tf-s3-archetype/src/test/resources/projects/basic/archetype.properties
  23. 0 tf-build-tools/tf-s3-archetype/src/test/resources/projects/basic/goal.txt
BIN +6 KB .DS_Store
Binary file not shown.
@@ -3,12 +3,13 @@
[tf-maven-plugin-snapshot]:https://oss.sonatype.org/content/repositories/snapshots/com/deliveredtechnologies/tf-maven-plugin/
[tf-cmd-api-snapshot]:https://oss.sonatype.org/content/repositories/snapshots/com/deliveredtechnologies/tf-cmd-api/
[maven-badge]:https://img.shields.io/badge/maven%20central-0.4-green.svg
[maven-snapshot-badge]:https://img.shields.io/badge/SNAPSHOT-0.4-green.svg
[maven-snapshot-badge]:https://img.shields.io/badge/SNAPSHOT-0.5-green.svg

![terraform-maven](.docs/MavenTerraform.png)

---


![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)
[![Build Status](https://travis-ci.org/deliveredtechnologies/terraform-maven.svg?branch=develop&maxAge=600&service=github)](https://travis-ci.org/deliveredtechnologies/terraform-maven)
[![Coverage Status](https://coveralls.io/repos/github/deliveredtechnologies/terraform-maven/badge.svg?branch=develop)](https://coveralls.io/github/deliveredtechnologies/terraform-maven?branch=develop)
@@ -35,6 +36,7 @@ The Terraform Maven Plugin brings Maven to Terraform, which greatly enhances Ter
* [tf:deploy](#tfdeploy)
* [tf:clean](#tfclean)
* [Setting Up a Terraform Maven Project](#setting-up-a-terraform-maven-project)
* [Setting Up a Terraform Maven Project Using an ArcheType](#setting-up-a-terraform-maven-project-using-an-archetype)
* [How to Use Terraform Maven Projects](#how-to-use-terraform-maven-projects)
* [Articles](#articles)

@@ -351,7 +353,26 @@ Deletes all 'terraform' files from terraform configurations along with the Terra
</build>
```

_**Note: An archetype that creates new Terraform Maven projects is a planned enhancement._
### Setting Up a Terraform Maven Project Using an ArcheType

Instead of doing all the above steps you can simply build the module/project by running the [Maven Archetype Plugin](https://maven.apache.org/guides/mini/guide-creating-archetypes.html) which creates project from an archetype.

An example on how to generate the project using an archetype is shown below.

```bash
mvn -B -DarchetypeGroupId=com.deliveredtechnologies -DarchetypeArtifactId="tf-s3-archetype" -DgroupId=<custom_group_name> -DartifactId=<custom-artifact_name>
```

Maven Non-Interactive mode creates a project with the name that you passed in <custom_articatId_name> under <custom_groupId_name>.

or

```bash
mvn -DarchetypeGroupId=com.deliveredtechnologies -DarchetypeArtifactId="tf-s3-archetype"
```

After running the above command mvn interactive console prompts for the required arguments (ex: groupId and artifactId) and creates the project accordingly.


### How to Use Terraform Maven Projects

@@ -6,11 +6,12 @@
<groupId>com.deliveredtechnologies</groupId>
<artifactId>tf-build-tools</artifactId>
<packaging>pom</packaging>
<version>0.4</version>
<version>0.5-SNAPSHOT</version>
<description>Terraform Build Tools: The parent POM project for Java and Terraform Tools</description>
<modules>
<module>tf-cmd-api</module>
<module>tf-maven-plugin</module>
<module>tf-s3-archetype</module>
</modules>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
@@ -5,7 +5,7 @@
<parent>
<artifactId>tf-build-tools</artifactId>
<groupId>com.deliveredtechnologies</groupId>
<version>0.4</version>
<version>0.5-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tf-cmd-api</artifactId>
@@ -4,7 +4,7 @@
<parent>
<groupId>com.deliveredtechnologies</groupId>
<artifactId>tf-build-tools</artifactId>
<version>0.4</version>
<version>0.5-SNAPSHOT</version>
</parent>
<artifactId>tf-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.deliveredtechnologies</groupId>
<artifactId>tf-build-tools</artifactId>
<version>0.5-SNAPSHOT</version>
</parent>
<artifactId>tf-s3-archetype</artifactId>
<packaging>pom</packaging>

<name>tf-s3-archetype</name>

<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>2.4</version>
</extension>
</extensions>

<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="tf-s3"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fileSets>
<fileSet encoding="UTF-8">
<directory>src/main/tf</directory>
<includes>
<include>**/*.tf</include>
<include>**/*.tfvars</include>
<include>**/*.json</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<tf-maven-version>0.4-SNAPSHOT</tf-maven-version>
</properties>
<artifactId>${artifactId}</artifactId>
<groupId>${groupId}</groupId>
<version>${version}</version>
<pluginRepositories>
<pluginRepository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.deliveredtechnologies</groupId>
<artifactId>tf-cmd-api</artifactId>
<version>${tf-maven-version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.3-groovy-2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.584</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>default-install</id>
<phase>never</phase>
</execution>
</executions>
</plugin>
<plugin>
<!-- disables default jar packaging: https://stackoverflow.com/questions/2188746/what-is-the-best-way-to-avoid-maven-jar -->
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>never</phase>
<configuration>
<finalName>unwanted</finalName>
<classifier>unwanted</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.deliveredtechnologies</groupId>
<artifactId>tf-maven-plugin</artifactId>
<version>${tf-maven-version}</version>
<executions>
<execution>
<id>terraform-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>terraform-install</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>terraform-package</id>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
</execution>
<execution>
<id>terraform-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration></configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.7.0</version>
<executions>
<execution>
<goals>
<goal>addTestSources</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,24 @@
variable "region" {
description = "region where the bucket will be created or the source region; defaults to us-east-1"
type = "string"
default = "us-east-1"
}

variable "bucket_name" {
description = "name of the bucket; defaults to a 'bucket-{random id}'"
type = "string"
default = ""
}

variable "environment" {
description = "value of the 'Environment' tag"
type = "string"
default = "dev"
}

variable "is_versioned" {
description = "true if versioning is to be enabled, otherwise false; defaults to false"
type = "string"
default = false
}

@@ -0,0 +1,40 @@
provider "aws" {
region = "${var.region}"
}

resource "random_id" "bucket_name" {
prefix = "bucket-"
byte_length = 8
}

locals {
bucket_name = "${length(var.bucket_name) == 0 ? random_id.bucket_name.hex : var.bucket_name}"
}

resource "aws_kms_key" "kmskey" {
description = "This key is used to encrypt bucket objects"
deletion_window_in_days = 10
}

resource "aws_s3_bucket" "bucket" {
bucket = "${local.bucket_name}"
acl = "private"
force_destroy = "true"

versioning {
enabled = "${var.is_versioned}"
}

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = "${aws_kms_key.kmskey.arn}"
sse_algorithm = "aws:kms"
}
}
}

tags = {
environment = "${var.environment}"
}
}
@@ -0,0 +1,9 @@
output "bucket_arn" {
description = "bucket arn"
value = "${aws_s3_bucket.bucket.arn}"
}

output "kms_key_arn" {
description = "kms key arn for the bucket encryption"
value = "${aws_kms_key.kmskey.arn}"
}
@@ -0,0 +1,2 @@
region = "us-east-2"
environment = "dev"
@@ -0,0 +1,2 @@
region = "us-east-2"
environment = "test"

0 comments on commit f3f3991

Please sign in to comment.
You can’t perform that action at this time.