GithubHelp home page GithubHelp logo

test-mass-forker-org-1 / terraform-spring-boot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/terraform-spring-boot

0.0 0.0 0.0 24 KB

Spring Boot Starter for Terraform

License: MIT License

Java 97.48% HCL 2.52%

terraform-spring-boot's Introduction

Terraform Spring Boot

Introduction

This repository is for Spring Boot Starters of Terraform client.

How to use it

There are two ways you could use this library. One way is to directly use the TerraformClient class which wraps the terraform executable on your local machine; and the other way is to integrate it into a Spring boot application using annotations.

Client library

Simply add the following dependency to your project's pom.xml will enable you to use the TerraformClient class.

<dependency>
    <groupId>com.microsoft.terraform</groupId>
    <artifactId>terraform-client</artifactId>
    <version>1.0.0</version>
</dependency>

And now you are able to provision terraform resources in your Java application. Make sure you have already put a terraform file storage.tf under /some/local/path/ folder; and then use the Java code snippet below to invoke terraform executable operate on the resources defined in storage.tf. In this example, we also assume that you are provisioning Azure specific resource, which means you need to set some Azure related credentials.

TerraformOptions options = new TerraformOptions();
options.setArmSubscriptionId("<Azure Subscription ID>");
options.setArmClientId("<Azure Client ID>");
options.setArmClientSecret("<Azure Client Secret>");
options.setArmTenantId("<Azure Tenant ID>");

try (TerraformClient client = new TerraformClient(options)) {
    client.setOutputListener(System.out::println);
    client.setErrorListener(System.err::println);

    client.setWorkingDirectory("/some/local/path/");
    client.plan().get();
    client.apply().get();
}

Spring boot

Let's still use the terraform file storage.tf under /some/local/path/ folder to provision Azure resources in this example. Rather than create the TerraformClient by ourselves, we let the spring boot framework to wire it for us. First add the following dependency to your pom.xml:

<dependency>
    <groupId>com.microsoft.terraform</groupId>
    <artifactId>terraform-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>

And now let's also introduce the Azure credentials in application.properties:

terraform.armSubscriptionId=<Azure Subscription ID>
terraform.armClientId=<Azure Client ID>
terraform.armClientSecret=<Azure Client Secret>
terraform.armTenantId=<Azure Tenant ID>

The final step is to let the Spring framework wire up everything in your spring boot application:

@SpringBootApplication
public class SpringStarterSampleApp implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(SpringStarterSampleApp.class, args);
    }

    @Autowired
    private TerraformClient terraform;

    @Override
    public void run(String... args) throws Exception {
        try {
            this.terraform.setOutputListener(System.out::println);
            this.terraform.setErrorListener(System.err::println);

            this.terraform.setWorkingDirectory("/some/local/path/");
            this.terraform.plan().get();
            this.terraform.apply().get();
        } finally {
            this.terraform.close();
        }
    }
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

terraform-spring-boot's People

Contributors

microsoftopensource avatar o0x2a avatar msftgits avatar ndedic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.