Skip to content

Commit ccc65a5

Browse files
Fix the terraform plan after running apply (#77)
* fix(job): set terraform state to empty in api return if default scheduling * fix(job): adjustment in validation if the JOB is manual
1 parent 1dd0ad4 commit ccc65a5

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

internal/provider/resource_tsuru_job.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,12 @@ func resourceTsuruJobRead(ctx context.Context, d *schema.ResourceData, meta inte
234234
d.Set("team_owner", job.Job.TeamOwner)
235235

236236
d.Set("container", flattenJobContainer(job.Job.Spec.Container))
237-
d.Set("schedule", job.Job.Spec.Schedule)
237+
238+
if job.Job.Spec.Manual {
239+
d.Set("schedule", "")
240+
} else {
241+
d.Set("schedule", job.Job.Spec.Schedule)
242+
}
238243

239244
if job.Job.Description != "" {
240245
d.Set("description", job.Job.Description)

internal/provider/resource_tsuru_job_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,32 @@ func TestAccResourceTsuruJobBasic(t *testing.T) {
6969
return c.JSON(http.StatusOK, tsuru.JobInfo{Job: *job})
7070
}
7171

72+
if iterationCount == 2 {
73+
job := &tsuru.Job{
74+
Name: name,
75+
Description: "my job description",
76+
TeamOwner: "my-team",
77+
Plan: tsuru.Plan{Name: "c1m1"},
78+
Pool: "prod",
79+
Spec: tsuru.JobSpec{
80+
Schedule: "",
81+
},
82+
}
83+
return c.JSON(http.StatusOK, tsuru.JobInfo{Job: *job})
84+
}
85+
7286
return c.JSON(http.StatusNotFound, nil)
7387
})
7488

7589
fakeServer.PUT("/1.13/jobs/:name", func(c echo.Context) error {
90+
job := tsuru.InputJob{}
91+
c.Bind(&job)
92+
93+
assert.Equal(t, "job01", job.Name)
94+
assert.Equal(t, "", job.Schedule)
95+
assert.Equal(t, true, job.Manual)
96+
97+
iterationCount++
7698
return c.JSON(http.StatusOK, nil)
7799
})
78100

@@ -106,6 +128,17 @@ func TestAccResourceTsuruJobBasic(t *testing.T) {
106128
resource.TestCheckResourceAttr(resourceName, "schedule", "* * * * *"),
107129
),
108130
},
131+
{
132+
Config: testAccResourceTsuruJobManual_basic(),
133+
Check: resource.ComposeAggregateTestCheckFunc(
134+
testAccResourceExists(resourceName),
135+
resource.TestCheckResourceAttr(resourceName, "name", "job01"),
136+
resource.TestCheckResourceAttr(resourceName, "description", "my job description"),
137+
resource.TestCheckResourceAttr(resourceName, "plan", "c1m1"),
138+
resource.TestCheckResourceAttr(resourceName, "team_owner", "my-team"),
139+
resource.TestCheckResourceAttr(resourceName, "pool", "prod"),
140+
),
141+
},
109142
},
110143
})
111144
}
@@ -123,6 +156,18 @@ func testAccResourceTsuruJob_basic() string {
123156
`
124157
}
125158

159+
func testAccResourceTsuruJobManual_basic() string {
160+
return `
161+
resource "tsuru_job" "job" {
162+
name = "job01"
163+
description = "my job description"
164+
plan = "c1m1"
165+
team_owner = "my-team"
166+
pool = "prod"
167+
}
168+
`
169+
}
170+
126171
func TestAccResourceTsuruJobManual(t *testing.T) {
127172
fakeServer := echo.New()
128173

0 commit comments

Comments
 (0)