Skip to content

Commit

Permalink
added tf-s3-archetype (issue #69)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1234a6i authored and Clayton7510 committed Jul 31, 2019
1 parent bf8841e commit f3f3991
Show file tree
Hide file tree
Showing 23 changed files with 649 additions and 5 deletions.
Binary file added .DS_Store
Binary file not shown.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion tf-build-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tf-build-tools/tf-cmd-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion tf-build-tools/tf-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
32 changes: 32 additions & 0 deletions tf-build-tools/tf-s3-archetype/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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
}

Original file line number Diff line number Diff line change
@@ -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}"
}
}
Original file line number Diff line number Diff line change
@@ -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}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
region = "us-east-2"
environment = "dev"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
region = "us-east-2"
environment = "test"
Loading

0 comments on commit f3f3991

Please sign in to comment.