mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/aws: Add support to set iam_role_arn on cloudformation Stack (#12547)
Fixes: #11266 ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCloudFormation_basic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/03/09 01:39:16 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCloudFormation_basic -timeout 120m === RUN TestAccAWSCloudFormation_basic --- PASS: TestAccAWSCloudFormation_basic (89.38s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 89.416s ```
This commit is contained in:
parent
74710ae71a
commit
78768e00f2
@ -58,6 +58,10 @@ func dataSourceAwsCloudFormationStack() *schema.Resource {
|
|||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
"iam_role_arn": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
"tags": {
|
"tags": {
|
||||||
Type: schema.TypeMap,
|
Type: schema.TypeMap,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@ -86,6 +90,7 @@ func dataSourceAwsCloudFormationStackRead(d *schema.ResourceData, meta interface
|
|||||||
d.Set("description", stack.Description)
|
d.Set("description", stack.Description)
|
||||||
d.Set("disable_rollback", stack.DisableRollback)
|
d.Set("disable_rollback", stack.DisableRollback)
|
||||||
d.Set("timeout_in_minutes", stack.TimeoutInMinutes)
|
d.Set("timeout_in_minutes", stack.TimeoutInMinutes)
|
||||||
|
d.Set("iam_role_arn", stack.RoleARN)
|
||||||
|
|
||||||
if len(stack.NotificationARNs) > 0 {
|
if len(stack.NotificationARNs) > 0 {
|
||||||
d.Set("notification_arns", schema.NewSet(schema.HashString, flattenStringList(stack.NotificationARNs)))
|
d.Set("notification_arns", schema.NewSet(schema.HashString, flattenStringList(stack.NotificationARNs)))
|
||||||
|
@ -22,12 +22,12 @@ func resourceAwsCloudFormationStack() *schema.Resource {
|
|||||||
Delete: resourceAwsCloudFormationStackDelete,
|
Delete: resourceAwsCloudFormationStackDelete,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
"template_body": &schema.Schema{
|
"template_body": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@ -37,42 +37,42 @@ func resourceAwsCloudFormationStack() *schema.Resource {
|
|||||||
return template
|
return template
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"template_url": &schema.Schema{
|
"template_url": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
"capabilities": &schema.Schema{
|
"capabilities": {
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
Set: schema.HashString,
|
Set: schema.HashString,
|
||||||
},
|
},
|
||||||
"disable_rollback": &schema.Schema{
|
"disable_rollback": {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
"notification_arns": &schema.Schema{
|
"notification_arns": {
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
Set: schema.HashString,
|
Set: schema.HashString,
|
||||||
},
|
},
|
||||||
"on_failure": &schema.Schema{
|
"on_failure": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
"parameters": &schema.Schema{
|
"parameters": {
|
||||||
Type: schema.TypeMap,
|
Type: schema.TypeMap,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
"outputs": &schema.Schema{
|
"outputs": {
|
||||||
Type: schema.TypeMap,
|
Type: schema.TypeMap,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
"policy_body": &schema.Schema{
|
"policy_body": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@ -82,20 +82,24 @@ func resourceAwsCloudFormationStack() *schema.Resource {
|
|||||||
return json
|
return json
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"policy_url": &schema.Schema{
|
"policy_url": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
"timeout_in_minutes": &schema.Schema{
|
"timeout_in_minutes": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
"tags": &schema.Schema{
|
"tags": {
|
||||||
Type: schema.TypeMap,
|
Type: schema.TypeMap,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
"iam_role_arn": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,6 +157,9 @@ func resourceAwsCloudFormationStackCreate(d *schema.ResourceData, meta interface
|
|||||||
log.Printf("[DEBUG] CloudFormation timeout: %d", retryTimeout)
|
log.Printf("[DEBUG] CloudFormation timeout: %d", retryTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if v, ok := d.GetOk("iam_role_arn"); ok {
|
||||||
|
input.RoleARN = aws.String(v.(string))
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] Creating CloudFormation Stack: %s", input)
|
log.Printf("[DEBUG] Creating CloudFormation Stack: %s", input)
|
||||||
resp, err := conn.CreateStack(&input)
|
resp, err := conn.CreateStack(&input)
|
||||||
@ -297,6 +304,7 @@ func resourceAwsCloudFormationStackRead(d *schema.ResourceData, meta interface{}
|
|||||||
|
|
||||||
d.Set("name", stack.StackName)
|
d.Set("name", stack.StackName)
|
||||||
d.Set("arn", stack.StackId)
|
d.Set("arn", stack.StackId)
|
||||||
|
d.Set("iam_role_arn", stack.RoleARN)
|
||||||
|
|
||||||
if stack.TimeoutInMinutes != nil {
|
if stack.TimeoutInMinutes != nil {
|
||||||
d.Set("timeout_in_minutes", int(*stack.TimeoutInMinutes))
|
d.Set("timeout_in_minutes", int(*stack.TimeoutInMinutes))
|
||||||
@ -385,6 +393,10 @@ func resourceAwsCloudFormationStackUpdate(d *schema.ResourceData, meta interface
|
|||||||
input.StackPolicyURL = aws.String(d.Get("policy_url").(string))
|
input.StackPolicyURL = aws.String(d.Get("policy_url").(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.HasChange("iam_role_arn") {
|
||||||
|
input.RoleARN = aws.String(d.Get("iam_role_arn").(string))
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] Updating CloudFormation stack: %s", input)
|
log.Printf("[DEBUG] Updating CloudFormation stack: %s", input)
|
||||||
stack, err := conn.UpdateStack(input)
|
stack, err := conn.UpdateStack(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,7 +20,7 @@ func TestAccAWSCloudFormation_basic(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig,
|
Config: testAccAWSCloudFormationConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.network", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.network", &stack),
|
||||||
@ -38,7 +38,7 @@ func TestAccAWSCloudFormation_yaml(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_yaml,
|
Config: testAccAWSCloudFormationConfig_yaml,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.yaml", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.yaml", &stack),
|
||||||
@ -56,7 +56,7 @@ func TestAccAWSCloudFormation_defaultParams(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_defaultParams,
|
Config: testAccAWSCloudFormationConfig_defaultParams,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.asg-demo", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.asg-demo", &stack),
|
||||||
@ -75,7 +75,7 @@ func TestAccAWSCloudFormation_allAttributes(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_allAttributesWithBodies,
|
Config: testAccAWSCloudFormationConfig_allAttributesWithBodies,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.full", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.full", &stack),
|
||||||
@ -93,7 +93,7 @@ func TestAccAWSCloudFormation_allAttributes(t *testing.T) {
|
|||||||
resource.TestCheckResourceAttr("aws_cloudformation_stack.full", "timeout_in_minutes", "10"),
|
resource.TestCheckResourceAttr("aws_cloudformation_stack.full", "timeout_in_minutes", "10"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_allAttributesWithBodies_modified,
|
Config: testAccAWSCloudFormationConfig_allAttributesWithBodies_modified,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.full", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.full", &stack),
|
||||||
@ -124,13 +124,13 @@ func TestAccAWSCloudFormation_withParams(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_withParams,
|
Config: testAccAWSCloudFormationConfig_withParams,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with_params", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with_params", &stack),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_withParams_modified,
|
Config: testAccAWSCloudFormationConfig_withParams_modified,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with_params", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with_params", &stack),
|
||||||
@ -149,13 +149,13 @@ func TestAccAWSCloudFormation_withUrl_withParams(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_templateUrl_withParams,
|
Config: testAccAWSCloudFormationConfig_templateUrl_withParams,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-url-and-params", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-url-and-params", &stack),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_templateUrl_withParams_modified,
|
Config: testAccAWSCloudFormationConfig_templateUrl_withParams_modified,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-url-and-params", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-url-and-params", &stack),
|
||||||
@ -173,7 +173,7 @@ func TestAccAWSCloudFormation_withUrl_withParams_withYaml(t *testing.T) {
|
|||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSCloudFormationConfig_templateUrl_withParams_withYaml,
|
Config: testAccAWSCloudFormationConfig_templateUrl_withParams_withYaml,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-url-and-params-and-yaml", &stack),
|
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-url-and-params-and-yaml", &stack),
|
||||||
|
@ -47,4 +47,5 @@ The following attributes are exported:
|
|||||||
* `parameters` - A map of parameters that specify input parameters for the stack.
|
* `parameters` - A map of parameters that specify input parameters for the stack.
|
||||||
* `tags` - A map of tags associated with this stack.
|
* `tags` - A map of tags associated with this stack.
|
||||||
* `template_body` - Structure containing the template body.
|
* `template_body` - Structure containing the template body.
|
||||||
|
* `iam_role_arn` - The ARN of the IAM role used to create the stack.
|
||||||
* `timeout_in_minutes` - The amount of time that can pass before the stack status becomes `CREATE_FAILED`
|
* `timeout_in_minutes` - The amount of time that can pass before the stack status becomes `CREATE_FAILED`
|
||||||
|
@ -65,6 +65,7 @@ The following arguments are supported:
|
|||||||
* `policy_url` - (Optional) Location of a file containing the stack policy.
|
* `policy_url` - (Optional) Location of a file containing the stack policy.
|
||||||
Conflicts w/ `policy_body`.
|
Conflicts w/ `policy_body`.
|
||||||
* `tags` - (Optional) A list of tags to associate with this stack.
|
* `tags` - (Optional) A list of tags to associate with this stack.
|
||||||
|
* `iam_role_arn` - (Optional) The ARN of an IAM role that AWS CloudFormation assumes to create the stack. If you don't specify a value, AWS CloudFormation uses the role that was previously associated with the stack. If no role is available, AWS CloudFormation uses a temporary session that is generated from your user credentials.
|
||||||
* `timeout_in_minutes` - (Optional) The amount of time that can pass before the stack status becomes `CREATE_FAILED`.
|
* `timeout_in_minutes` - (Optional) The amount of time that can pass before the stack status becomes `CREATE_FAILED`.
|
||||||
|
|
||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
Loading…
Reference in New Issue
Block a user