github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/resource_aws_opsworks_application_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/aws/awserr"
     9  	"github.com/aws/aws-sdk-go/service/opsworks"
    10  	"github.com/hashicorp/terraform/helper/resource"
    11  	"github.com/hashicorp/terraform/terraform"
    12  )
    13  
    14  func TestAccAWSOpsworksApplication(t *testing.T) {
    15  	resource.Test(t, resource.TestCase{
    16  		PreCheck:     func() { testAccPreCheck(t) },
    17  		Providers:    testAccProviders,
    18  		CheckDestroy: testAccCheckAwsOpsworksApplicationDestroy,
    19  		Steps: []resource.TestStep{
    20  			resource.TestStep{
    21  				Config: testAccAwsOpsworksApplicationCreate,
    22  				Check: resource.ComposeTestCheckFunc(
    23  					resource.TestCheckResourceAttr(
    24  						"aws_opsworks_application.tf-acc-app", "name", "tf-ops-acc-application",
    25  					),
    26  					resource.TestCheckResourceAttr(
    27  						"aws_opsworks_application.tf-acc-app", "type", "other",
    28  					),
    29  					resource.TestCheckResourceAttr(
    30  						"aws_opsworks_application.tf-acc-app", "enable_ssl", "false",
    31  					),
    32  					resource.TestCheckResourceAttr(
    33  						"aws_opsworks_application.tf-acc-app", "ssl_configuration", "",
    34  					),
    35  					resource.TestCheckResourceAttr(
    36  						"aws_opsworks_application.tf-acc-app", "domains", "",
    37  					),
    38  					resource.TestCheckResourceAttr(
    39  						"aws_opsworks_application.tf-acc-app", "app_source", "",
    40  					),
    41  					resource.TestCheckResourceAttr(
    42  						"aws_opsworks_application.tf-acc-app", "environment.3077298702.key", "key1",
    43  					),
    44  					resource.TestCheckResourceAttr(
    45  						"aws_opsworks_application.tf-acc-app", "environment.3077298702.value", "value1",
    46  					),
    47  					resource.TestCheckResourceAttr(
    48  						"aws_opsworks_application.tf-acc-app", "environment.3077298702.secret", "",
    49  					),
    50  				),
    51  			},
    52  			resource.TestStep{
    53  				Config: testAccAwsOpsworksApplicationUpdate,
    54  				Check: resource.ComposeTestCheckFunc(
    55  					resource.TestCheckResourceAttr(
    56  						"aws_opsworks_application.tf-acc-app", "name", "tf-ops-acc-application",
    57  					),
    58  					resource.TestCheckResourceAttr(
    59  						"aws_opsworks_application.tf-acc-app", "type", "rails",
    60  					),
    61  					resource.TestCheckResourceAttr(
    62  						"aws_opsworks_application.tf-acc-app", "enable_ssl", "true",
    63  					),
    64  					resource.TestCheckResourceAttr(
    65  						"aws_opsworks_application.tf-acc-app", "ssl_configuration.0.certificate", "-----BEGIN CERTIFICATE-----\nMIIBkDCB+gIJALoScFD0sJq3MA0GCSqGSIb3DQEBBQUAMA0xCzAJBgNVBAYTAkRF\nMB4XDTE1MTIxOTIwMzU1MVoXDTE2MDExODIwMzU1MVowDTELMAkGA1UEBhMCREUw\ngZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKKQKbTTH/Julz16xY7ArYlzJYCP\nedTCx1bopuryCx/+d1gC94MtRdlPSpQl8mfc9iBdtXbJppp73Qh/DzLzO9Ns25xZ\n+kUQMhbIyLsaCBzuEGLgAaVdGpNvRBw++UoYtd0U7QczFAreTGLH8n8+FIzuI5Mc\n+MJ1TKbbt5gFfRSzAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEALARo96wCDmaHKCaX\nS0IGLGnZCfiIUfCmBxOXBSJxDBwter95QHR0dMGxYIujee5n4vvavpVsqZnfMC3I\nOZWPlwiUJbNIpK+04Bg2vd5m/NMMrvi75RfmyeMtSfq/NrIX2Q3+nyWI7DLq7yZI\nV/YEvOqdAiy5NEWBztHx8HvB9G4=\n-----END CERTIFICATE-----",
    66  					),
    67  					resource.TestCheckResourceAttr(
    68  						"aws_opsworks_application.tf-acc-app", "ssl_configuration.0.private_key", "-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQCikCm00x/ybpc9esWOwK2JcyWAj3nUwsdW6Kbq8gsf/ndYAveD\nLUXZT0qUJfJn3PYgXbV2yaaae90Ifw8y8zvTbNucWfpFEDIWyMi7Gggc7hBi4AGl\nXRqTb0QcPvlKGLXdFO0HMxQK3kxix/J/PhSM7iOTHPjCdUym27eYBX0UswIDAQAB\nAoGBAIYcrvuqDboguI8U4TUjCkfSAgds1pLLWk79wu8jXkA329d1IyNKT0y3WIye\nPbyoEzmidZmZROQ/+ZsPz8c12Y0DrX73WSVzKNyJeP7XMk9HSzA1D9RX0U0S+5Kh\nFAMc2NEVVFIfQtVtoVmHdKDpnRYtOCHLW9rRpvqOOjd4mYk5AkEAzeiFr1mtlnsa\n67shMxzDaOTAFMchRz6G7aSovvCztxcB63ulFI/w9OTUMdTQ7ff7pet+lVihLc2W\nefIL0HvsjQJBAMocNTKaR/TnsV5GSk2kPAdR+zFP5sQy8sfMy0lEXTylc7zN4ajX\nMeHVoxp+GZgpfDcZ3ya808H1umyXh+xA1j8CQE9x9ZKQYT98RAjL7KVR5btk9w+N\nPTPF1j1+mHUDXfO4ds8qp6jlWKzEVXLcj7ghRADiebaZuaZ4eiSW1SQdjEkCQQC4\nwDhQ3X9RfEpCp3ZcqvjEqEg6t5N3XitYQPjDLN8eBRBbUsgpEy3iBuxl10eGNMX7\niIbYXlwkPYAArDPv3wT5AkAwp4vym+YKmDqh6gseKfRDuJqRiW9yD5A8VGr/w88k\n5rkuduVGP7tK3uIp00Its3aEyKF8mLGWYszVGeeLxAMH\n-----END RSA PRIVATE KEY-----",
    69  					),
    70  					resource.TestCheckResourceAttr(
    71  						"aws_opsworks_application.tf-acc-app", "domains.0", "example.com",
    72  					),
    73  					resource.TestCheckResourceAttr(
    74  						"aws_opsworks_application.tf-acc-app", "domains.1", "sub.example.com",
    75  					),
    76  					resource.TestCheckResourceAttr(
    77  						"aws_opsworks_application.tf-acc-app", "app_source.0.password", "",
    78  					),
    79  					resource.TestCheckResourceAttr(
    80  						"aws_opsworks_application.tf-acc-app", "app_source.0.revision", "master",
    81  					),
    82  					resource.TestCheckResourceAttr(
    83  						"aws_opsworks_application.tf-acc-app", "app_source.0.ssh_key", "",
    84  					),
    85  					resource.TestCheckResourceAttr(
    86  						"aws_opsworks_application.tf-acc-app", "app_source.0.type", "git",
    87  					),
    88  					resource.TestCheckResourceAttr(
    89  						"aws_opsworks_application.tf-acc-app", "app_source.0.url", "https://github.com/aws/example.git",
    90  					),
    91  					resource.TestCheckResourceAttr(
    92  						"aws_opsworks_application.tf-acc-app", "app_source.0.username", "",
    93  					),
    94  					resource.TestCheckResourceAttr(
    95  						"aws_opsworks_application.tf-acc-app", "environment.2107898637.key", "key2",
    96  					),
    97  					resource.TestCheckResourceAttr(
    98  						"aws_opsworks_application.tf-acc-app", "environment.2107898637.value", "value2",
    99  					),
   100  					resource.TestCheckResourceAttr(
   101  						"aws_opsworks_application.tf-acc-app", "environment.2107898637.secure", "true",
   102  					),
   103  					resource.TestCheckResourceAttr(
   104  						"aws_opsworks_application.tf-acc-app", "environment.3077298702.key", "key1",
   105  					),
   106  					resource.TestCheckResourceAttr(
   107  						"aws_opsworks_application.tf-acc-app", "environment.3077298702.value", "value1",
   108  					),
   109  					resource.TestCheckResourceAttr(
   110  						"aws_opsworks_application.tf-acc-app", "environment.3077298702.secret", "",
   111  					),
   112  					resource.TestCheckResourceAttr(
   113  						"aws_opsworks_application.tf-acc-app", "document_root", "root",
   114  					),
   115  					resource.TestCheckResourceAttr(
   116  						"aws_opsworks_application.tf-acc-app", "auto_bundle_on_deploy", "true",
   117  					),
   118  					resource.TestCheckResourceAttr(
   119  						"aws_opsworks_application.tf-acc-app", "rails_env", "staging",
   120  					),
   121  				),
   122  			},
   123  		},
   124  	})
   125  }
   126  
   127  func testAccCheckAwsOpsworksApplicationDestroy(s *terraform.State) error {
   128  	client := testAccProvider.Meta().(*AWSClient).opsworksconn
   129  
   130  	for _, rs := range s.RootModule().Resources {
   131  		if rs.Type != "aws_opsworks_application" {
   132  			continue
   133  		}
   134  
   135  		req := &opsworks.DescribeAppsInput{
   136  			AppIds: []*string{
   137  				aws.String(rs.Primary.ID),
   138  			},
   139  		}
   140  
   141  		resp, err := client.DescribeApps(req)
   142  		if err == nil {
   143  			if len(resp.Apps) > 0 {
   144  				return fmt.Errorf("OpsWorks App still exist.")
   145  			}
   146  		}
   147  
   148  		if awserr, ok := err.(awserr.Error); ok {
   149  			if awserr.Code() != "ResourceNotFoundException" {
   150  				return err
   151  			}
   152  		}
   153  	}
   154  
   155  	return nil
   156  }
   157  
   158  var testAccAwsOpsworksApplicationCreate = testAccAwsOpsworksStackConfigNoVpcCreate("tf-ops-acc-application") + `
   159  resource "aws_opsworks_application" "tf-acc-app" {
   160    stack_id = "${aws_opsworks_stack.tf-acc.id}"
   161    name = "tf-ops-acc-application"
   162    type = "other"
   163    enable_ssl = false
   164    app_source ={
   165      type = "other"
   166    }
   167  	environment = { key = "key1" value = "value1" secure = false}
   168  }
   169  `
   170  
   171  var testAccAwsOpsworksApplicationUpdate = testAccAwsOpsworksStackConfigNoVpcCreate("tf-ops-acc-application") + `
   172  resource "aws_opsworks_application" "tf-acc-app" {
   173    stack_id = "${aws_opsworks_stack.tf-acc.id}"
   174    name = "tf-ops-acc-application"
   175    type = "rails"
   176    domains = ["example.com", "sub.example.com"]
   177    enable_ssl = true
   178    ssl_configuration = {
   179      private_key = <<EOS
   180  -----BEGIN RSA PRIVATE KEY-----
   181  MIICXQIBAAKBgQCikCm00x/ybpc9esWOwK2JcyWAj3nUwsdW6Kbq8gsf/ndYAveD
   182  LUXZT0qUJfJn3PYgXbV2yaaae90Ifw8y8zvTbNucWfpFEDIWyMi7Gggc7hBi4AGl
   183  XRqTb0QcPvlKGLXdFO0HMxQK3kxix/J/PhSM7iOTHPjCdUym27eYBX0UswIDAQAB
   184  AoGBAIYcrvuqDboguI8U4TUjCkfSAgds1pLLWk79wu8jXkA329d1IyNKT0y3WIye
   185  PbyoEzmidZmZROQ/+ZsPz8c12Y0DrX73WSVzKNyJeP7XMk9HSzA1D9RX0U0S+5Kh
   186  FAMc2NEVVFIfQtVtoVmHdKDpnRYtOCHLW9rRpvqOOjd4mYk5AkEAzeiFr1mtlnsa
   187  67shMxzDaOTAFMchRz6G7aSovvCztxcB63ulFI/w9OTUMdTQ7ff7pet+lVihLc2W
   188  efIL0HvsjQJBAMocNTKaR/TnsV5GSk2kPAdR+zFP5sQy8sfMy0lEXTylc7zN4ajX
   189  MeHVoxp+GZgpfDcZ3ya808H1umyXh+xA1j8CQE9x9ZKQYT98RAjL7KVR5btk9w+N
   190  PTPF1j1+mHUDXfO4ds8qp6jlWKzEVXLcj7ghRADiebaZuaZ4eiSW1SQdjEkCQQC4
   191  wDhQ3X9RfEpCp3ZcqvjEqEg6t5N3XitYQPjDLN8eBRBbUsgpEy3iBuxl10eGNMX7
   192  iIbYXlwkPYAArDPv3wT5AkAwp4vym+YKmDqh6gseKfRDuJqRiW9yD5A8VGr/w88k
   193  5rkuduVGP7tK3uIp00Its3aEyKF8mLGWYszVGeeLxAMH
   194  -----END RSA PRIVATE KEY-----
   195  EOS
   196      certificate = <<EOS
   197  -----BEGIN CERTIFICATE-----
   198  MIIBkDCB+gIJALoScFD0sJq3MA0GCSqGSIb3DQEBBQUAMA0xCzAJBgNVBAYTAkRF
   199  MB4XDTE1MTIxOTIwMzU1MVoXDTE2MDExODIwMzU1MVowDTELMAkGA1UEBhMCREUw
   200  gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKKQKbTTH/Julz16xY7ArYlzJYCP
   201  edTCx1bopuryCx/+d1gC94MtRdlPSpQl8mfc9iBdtXbJppp73Qh/DzLzO9Ns25xZ
   202  +kUQMhbIyLsaCBzuEGLgAaVdGpNvRBw++UoYtd0U7QczFAreTGLH8n8+FIzuI5Mc
   203  +MJ1TKbbt5gFfRSzAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEALARo96wCDmaHKCaX
   204  S0IGLGnZCfiIUfCmBxOXBSJxDBwter95QHR0dMGxYIujee5n4vvavpVsqZnfMC3I
   205  OZWPlwiUJbNIpK+04Bg2vd5m/NMMrvi75RfmyeMtSfq/NrIX2Q3+nyWI7DLq7yZI
   206  V/YEvOqdAiy5NEWBztHx8HvB9G4=
   207  -----END CERTIFICATE-----
   208  EOS
   209    }
   210    app_source = {
   211      type = "git"
   212      revision = "master"
   213      url = "https://github.com/aws/example.git"
   214    }
   215  	environment = { key = "key1" value = "value1" secure = false}
   216  	environment = { key = "key2" value = "value2" }
   217  	document_root = "root"
   218    auto_bundle_on_deploy = "true"
   219    rails_env = "staging"
   220  }
   221  `