Skip to content

Commit 7b8d3c1

Browse files
authored
Merge pull request #3 from Heider1988/develop
Develop
2 parents 2bb2a7c + 71e6d88 commit 7b8d3c1

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

.github/workflows/terraform.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ jobs:
4242
role-session-name: GitHub_to_AWS_via_FederatedOIDC
4343
aws-region: ${{ inputs.aws-region}}
4444

45+
- name: Read destroy configuration
46+
id: read-destroy-config
47+
run: |
48+
DESTROY="$(jq -r '.${{inputs.enviroment}}' ./infra/destroy_config.json)"
49+
echo "destroy=$(echo $DESTROY)" >> $GITHUB_OUTPUT
50+
4551
- name: Terraform Init
4652
run: |
4753
cd infra && terraform init \
@@ -53,13 +59,22 @@ jobs:
5359
- name: Terraform Validate
5460
run: terraform validate
5561

62+
- name: Terraform Destroy
63+
if: steps.read-destroy-config.outputs.destroy == 'true'
64+
id: terraform-destroy
65+
run: cd infra &&
66+
terraform workspace select ${{ inputs.enviroment }} || terraform workspace new ${{ inputs.enviroment }} &&
67+
terraform destroy -var-file="./envs/${{ inputs.enviroment }}/terraform.tfvars" -auto-approve
68+
5669
- name: Terraform Plan
70+
if: steps.read-destroy-config.outputs.destroy != 'true'
5771
id: terraform-plan
5872
run: cd infra &&
5973
terraform workspace select ${{inputs.enviroment}} || terraform workspace new ${{inputs.enviroment}} &&
6074
terraform plan -var-file="./envs/${{inputs.enviroment}}/terraform.tfvars" -out="${{inputs.enviroment}}.plan"
6175

6276
- name: Terraform Apply
77+
if: steps.read-destroy-config.outputs.destroy != 'true'
6378
id: terraform-apply
6479
run: cd infra &&
6580
terraform workspace select ${{inputs.enviroment}} || terraform workspace new ${{inputs.enviroment}} &&

infra/destroy_config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"dev" : true,
3+
"prod" : true
4+
}

src/main/java/com/api/terraform/pipeline/terraforminfrapipeline/TerraformInfraPipelineApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ComponentScan;
56

67
@SpringBootApplication
8+
@ComponentScan(basePackages = {"com.api.terraform.pipeline.terraforminfrapipeline", "controller", "dto"})
79
public class TerraformInfraPipelineApplication {
810

911
public static void main(String[] args) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package controller;
2+
3+
import dto.response.TimeResponse;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import java.time.LocalDateTime;
10+
import java.time.ZoneId;
11+
import java.time.format.DateTimeFormatter;
12+
13+
@RestController
14+
@RequestMapping("/api")
15+
public class TesteController {
16+
17+
@GetMapping("/time")
18+
public ResponseEntity<TimeResponse> gettime() {
19+
20+
LocalDateTime brasLocalDateTime = LocalDateTime.now(ZoneId.of("America/Sao_Paulo"));
21+
22+
String formatedTime = brasLocalDateTime.format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"));
23+
24+
return ResponseEntity.ok(new TimeResponse(formatedTime));
25+
}
26+
27+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package dto.response;
2+
3+
public record TimeResponse(String time) {
4+
}

0 commit comments

Comments
 (0)