Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs-templates/resources/stack_template.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_stack_template (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

{{tffile "docs-examples/resources/stack_template/resource.tf"}}
Expand Down
4 changes: 0 additions & 4 deletions docs-templates/resources/stack_template_revision.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_stack_template_revision (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

{{tffile "docs-examples/resources/stack_template_revision/resource.tf"}}
Expand Down
4 changes: 0 additions & 4 deletions docs-templates/resources/workflow_step_template.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_workflow_step_template (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

{{tffile "docs-examples/resources/workflow_step_template/resource.tf"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_workflow_step_template_revision (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

{{tffile "docs-examples/resources/workflow_step_template_revision/resource.tf"}}
Expand Down
4 changes: 0 additions & 4 deletions docs-templates/resources/workflow_template.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_workflow_template (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

{{tffile "docs-examples/resources/workflow_template/resource.tf"}}
Expand Down
4 changes: 0 additions & 4 deletions docs-templates/resources/workflow_template_revision.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_workflow_template_revision (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

{{tffile "docs-examples/resources/workflow_template_revision/resource.tf"}}
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/stack_template_revision.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ output "stack_template_revision_output" {
- `actions` (Attributes Map) JSON-encoded map of actions for the stack template revision. (see [below for nested schema](#nestedatt--actions))
- `alias` (String) Human-readable alias for the revision (e.g., `v1.0.0`).
- `context_tags` (Map of String) Context tags for stack template revision
- `deprecation` (Attributes) Deprecation information for this resource. (see [below for nested schema](#nestedatt--deprecation))
- `deprecation` (Attributes) Deprecation information for this resource. Revision can only be deprecated once it is published. (see [below for nested schema](#nestedatt--deprecation))
- `description` (String) Long description for the stack template revision.
- `is_public` (String) Whether the stack template is publicly available. Valid values:
<span style="background-color: #eff0f0; color: #e53835;">0</span> (false),
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/workflow_step_template_revision.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ output "workflow_step_template_revision_info" {

- `alias` (String) Alias for the revision to easily identify it.
- `context_tags` (Map of String) Contextual key-value tags that provide additional context to the main tags.
- `deprecation` (Attributes) Deprecation information for this resource. (see [below for nested schema](#nestedatt--deprecation))
- `deprecation` (Attributes) Deprecation information for this resource. Revision can only be deprecated once it is published. (see [below for nested schema](#nestedatt--deprecation))
- `is_public` (String) Whether the workflow step template is publicly available. Valid values:
<span style="background-color: #eff0f0; color: #e53835;">0</span> (false),
<span style="background-color: #eff0f0; color: #e53835;">1</span> (true)
Expand Down
4 changes: 0 additions & 4 deletions docs/resources/stack_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_stack_template (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

```terraform
Expand Down
6 changes: 1 addition & 5 deletions docs/resources/stack_template_revision.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_stack_template_revision (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

```terraform
Expand Down Expand Up @@ -105,7 +101,7 @@ resource "stackguardian_stack_template_revision" "with_vcs" {
- `actions` (Attributes Map) JSON-encoded map of actions for the stack template revision. (see [below for nested schema](#nestedatt--actions))
- `alias` (String) Human-readable alias for the revision (e.g., `v1.0.0`).
- `context_tags` (Map of String) Context tags for stack template revision
- `deprecation` (Attributes) Deprecation information for this resource. (see [below for nested schema](#nestedatt--deprecation))
- `deprecation` (Attributes) Deprecation information for this resource. Revision can only be deprecated once it is published. (see [below for nested schema](#nestedatt--deprecation))
- `description` (String) Long description for the stack template revision.
- `is_public` (String) Whether the stack template is publicly available. Valid values:
<span style="background-color: #eff0f0; color: #e53835;">0</span> (false),
Expand Down
4 changes: 0 additions & 4 deletions docs/resources/workflow_step_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_workflow_step_template (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

```terraform
Expand Down
6 changes: 1 addition & 5 deletions docs/resources/workflow_step_template_revision.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_workflow_step_template_revision (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

```terraform
Expand Down Expand Up @@ -66,7 +62,7 @@ resource "stackguardian_workflow_step_template_revision" "example" {

- `alias` (String) Alias for the revision to easily identify it.
- `context_tags` (Map of String) Contextual key-value tags that provide additional context to the main tags.
- `deprecation` (Attributes) Deprecation information for this resource. (see [below for nested schema](#nestedatt--deprecation))
- `deprecation` (Attributes) Deprecation information for this resource. Revision can only be deprecated once it is published. (see [below for nested schema](#nestedatt--deprecation))
- `description` (String) A brief description of the workflow step template revision. Must be less than 256 characters.
- `is_public` (String) Whether the workflow step template is publicly available. Valid values:
<span style="background-color: #eff0f0; color: #e53835;">0</span> (false),
Expand Down
4 changes: 0 additions & 4 deletions docs/resources/workflow_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_workflow_template (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

```terraform
Expand Down
4 changes: 0 additions & 4 deletions docs/resources/workflow_template_revision.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ description: |-

# stackguardian_workflow_template_revision (Resource)

<div style="background-color: orange; padding: 12px; border-radius: 6px; color: white; font-weight: bold;">
⚠️ This feature is currently in BETA.
</div>

## Example Usage

```terraform
Expand Down
2 changes: 1 addition & 1 deletion internal/constants/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const (
AWSRegion = "AWS region where the bucket is placed"
Auth = "Authentication required by the runner to access the backend storage. Required only for type \"aws_s3\""
IntegrationId = "SG Connector Id. Required only for type \"aws_s3\" eg: /integrations/test-connector"
Deprecation = "Deprecation information for this resource."
Deprecation = "Deprecation information for this resource. Revision can only be deprecated once it is published."
DeprecationEffectiveDate = "Effective date when this resource will be deprecated and no longer available for use."
)

Expand Down
169 changes: 136 additions & 33 deletions internal/resource/stack_template_revision/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"net/http"
"os"
"testing"
"time"

sgsdkgo "github.com/StackGuardian/sg-sdk-go"
sgclient "github.com/StackGuardian/sg-sdk-go/client"
sgoption "github.com/StackGuardian/sg-sdk-go/option"
"github.com/StackGuardian/sg-sdk-go/stacktemplaterevisions"
"github.com/StackGuardian/sg-sdk-go/stacktemplates"
"github.com/StackGuardian/sg-sdk-go/workflowtemplates"
"github.com/StackGuardian/terraform-provider-stackguardian/internal/acctest"
Expand Down Expand Up @@ -77,42 +79,29 @@ func deleteStackTemplateRevisionFixture(revisionId string) {
client.StackTemplateRevisions.DeleteStackTemplateRevision(context.TODO(), org, revisionId, true)
}

// --- Terraform config generators ---

func testAccStackTemplateRevisionConfig(stackTemplateID, wfTemplateID, alias string) string {
return fmt.Sprintf(`
resource "stackguardian_stack_template_revision" "test" {
parent_template_id = "%s"
alias = "%s"
notes = "Test revision notes"
description = "Test revision description"
source_config_kind = "TERRAFORM"

workflows_config = {
workflows = [
{
id = "d8dfaf15-2ad9-da29-8af0-c6b288b12089"
template_id = "%s"
resource_name = "wf-1"

terraform_config = {
managed_terraform_state = true
terraform_version = "1.5.7"
}
}
]
}
}
`, stackTemplateID, alias, wfTemplateID)
func deprecateStackTemplateRevisionFixture(revisionId string) {
client := getClient()
effectiveDate := fmt.Sprintf("%d", time.Date(2026, 12, 31, 0, 0, 0, 0, time.UTC).Unix())
message := "This revision is deprecated"
client.StackTemplateRevisions.UpdateStackTemplateRevision(context.TODO(), org, revisionId, &stacktemplaterevisions.UpdateStackTemplateRevisionRequest{
Deprecation: sgsdkgo.Optional(stacktemplaterevisions.Deprecation{
EffectiveDate: &effectiveDate,
Message: &message,
}),
})
}

func testAccStackTemplateRevisionConfigUpdated(stackTemplateID, wfTemplateID, alias string) string {
// --- Terraform config generators ---

// testAccStackTemplateRevisionConfig generates a basic stack template revision config.
// notes and description are the displayed strings for those fields.
func testAccStackTemplateRevisionConfig(stackTemplateID, wfTemplateID, alias, notes, description string) string {
return fmt.Sprintf(`
resource "stackguardian_stack_template_revision" "test" {
parent_template_id = "%s"
alias = "%s"
notes = "Updated revision notes"
description = "Updated revision description"
notes = "%s"
description = "%s"
source_config_kind = "TERRAFORM"

workflows_config = {
Expand All @@ -130,7 +119,7 @@ resource "stackguardian_stack_template_revision" "test" {
]
}
}
`, stackTemplateID, alias, wfTemplateID)
`, stackTemplateID, alias, notes, description, wfTemplateID)
}

func testAccStackTemplateRevisionWithWorkflowsConfig(stackTemplateID, wfTemplateID, alias string) string {
Expand Down Expand Up @@ -205,7 +194,7 @@ func TestAccStackTemplateRevision_Basic(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccStackTemplateRevisionConfig(stackTemplateID, wfTemplateID, revisionAlias),
Config: testAccStackTemplateRevisionConfig(stackTemplateID, wfTemplateID, revisionAlias, "Test revision notes", "Test revision description"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "alias", revisionAlias),
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "notes", "Test revision notes"),
Expand All @@ -218,7 +207,7 @@ func TestAccStackTemplateRevision_Basic(t *testing.T) {
},
// Update and Read testing
{
Config: testAccStackTemplateRevisionConfigUpdated(stackTemplateID, wfTemplateID, revisionAlias),
Config: testAccStackTemplateRevisionConfig(stackTemplateID, wfTemplateID, revisionAlias, "Updated revision notes", "Updated revision description"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "alias", revisionAlias),
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "notes", "Updated revision notes"),
Expand Down Expand Up @@ -276,3 +265,117 @@ func TestAccStackTemplateRevision_WithWorkflowsConfig(t *testing.T) {
},
})
}

func TestAccStackTemplateRevision_Lifecycle(t *testing.T) {
stackTemplateName := "tf-provider-stack-template-lifecycle"
wfTemplateName := "tf-provider-wft-lifecycle-for-stack"
alias := "v1"

// Safety-net cleanup. Defers run LIFO, so registration order here is the
// reverse of execution order:
// execution: deprecate revision → delete revision → delete stack template → delete workflow template
defer deleteWorkflowTemplateFixture(wfTemplateName)
defer deleteStackTemplateFixture(stackTemplateName)
defer deleteStackTemplateRevisionFixture(fmt.Sprintf("%s:1", stackTemplateName))
defer deprecateStackTemplateRevisionFixture(fmt.Sprintf("%s:1", stackTemplateName))

customHeader := http.Header{}
customHeader.Set("x-sg-internal-auth-orgid", "sg-provider-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_1_0),
},
ProtoV6ProviderFactories: acctest.ProviderFactories(customHeader),
Steps: []resource.TestStep{
// Step 1: Create parent stack template, parent workflow template, and revision
{
Config: testAccStackTemplateRevisionLifecycleConfig(stackTemplateName, wfTemplateName, alias, "", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackguardian_stack_template.parent", "template_name", stackTemplateName),
resource.TestCheckResourceAttrSet("stackguardian_stack_template.parent", "id"),
resource.TestCheckResourceAttr("stackguardian_workflow_template.wf_parent", "template_name", wfTemplateName),
resource.TestCheckResourceAttrSet("stackguardian_workflow_template.wf_parent", "id"),
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "alias", alias),
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "notes", "Initial revision"),
resource.TestCheckResourceAttrSet("stackguardian_stack_template_revision.test", "id"),
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "parent_template_id", stackTemplateName),
),
},
// Step 2: Publish the revision
{
Config: testAccStackTemplateRevisionLifecycleConfig(stackTemplateName, wfTemplateName, alias, "1", false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "is_public", "1"),
),
},
// Step 3: Deprecate the revision
{
Config: testAccStackTemplateRevisionLifecycleConfig(stackTemplateName, wfTemplateName, alias, "1", true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "deprecation.message", "This revision is deprecated"),
resource.TestCheckResourceAttr("stackguardian_stack_template_revision.test", "deprecation.effective_date", fmt.Sprintf("%d", time.Date(2026, 12, 31, 0, 0, 0, 0, time.UTC).Unix())),
),
},
// Terraform destroy automatically deletes the revision, stack template, and workflow template
},
})
}

// testAccStackTemplateRevisionLifecycleConfig generates the lifecycle Terraform config.
// isPublic controls the revision's is_public value (pass "" to omit).
// deprecated=true adds a deprecation block to the revision.
func testAccStackTemplateRevisionLifecycleConfig(stackTemplateName, wfTemplateName, alias, isPublic string, deprecated bool) string {
isPublicLine := ""
if isPublic != "" {
isPublicLine = fmt.Sprintf(" is_public = %q\n", isPublic)
}
deprecationBlock := ""
if deprecated {
deprecationBlock = fmt.Sprintf(`
deprecation = {
effective_date = "%d"
message = "This revision is deprecated"
}`, time.Date(2026, 12, 31, 0, 0, 0, 0, time.UTC).Unix())
}
return fmt.Sprintf(`
resource "stackguardian_workflow_template" "wf_parent" {
template_name = "%s"
source_config_kind = "TERRAFORM"
is_public = "0"
tags = ["test", "lifecycle"]
}

resource "stackguardian_stack_template" "parent" {
template_name = "%s"
source_config_kind = "TERRAFORM"
is_public = "0"
tags = ["test", "lifecycle"]
}

resource "stackguardian_stack_template_revision" "test" {
parent_template_id = stackguardian_stack_template.parent.id
alias = "%s"
notes = "Initial revision"
description = "Lifecycle test revision"
source_config_kind = "TERRAFORM"
%s
workflows_config = {
workflows = [
{
id = "d8dfaf15-2ad9-da29-8af0-c6b288b12089"
template_id = stackguardian_workflow_template.wf_parent.id
resource_name = "wf-1"

terraform_config = {
managed_terraform_state = true
terraform_version = "1.5.7"
}
}
]
}
%s
}
`, wfTemplateName, stackTemplateName, alias, isPublicLine, deprecationBlock)
}
Loading
Loading